File tree Expand file tree Collapse file tree 10 files changed +5032
-3504
lines changed Expand file tree Collapse file tree 10 files changed +5032
-3504
lines changed Original file line number Diff line number Diff line change 11import { BrowserSessionManager } from '../../session-managers/index.js' ;
22import { AuthCodeWithPKCE } from '../../oauth2-flows/index.js' ;
33import * as utilities from '../../utilities/index.js' ;
4+ import type { GeneratePortalUrlParams } from '@kinde/js-utils' ;
45
56import type {
67 UserType ,
@@ -63,6 +64,18 @@ const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => {
6364 } ) ;
6465 } ;
6566
67+ /**
68+ * Method makes use of the `createPortalUrl` method of the AuthCodeWithPKCE
69+ * client above to return portal url.
70+ * @param {GeneratePortalUrlParams } options
71+ * @returns {Promise<{url: URL}> } portal URL
72+ */
73+ const portal = async ( options : GeneratePortalUrlParams ) : Promise < { url : URL } > => {
74+ return await client . createPortalUrl ( sessionManager , {
75+ ...options ,
76+ } ) ;
77+ } ;
78+
6679 /**
6780 * Method makes use of the `handleRedirectFromAuthDomain` method of the
6881 * `AuthCodeWithPKCE` client above to handle the redirection back to the app.
@@ -379,6 +392,7 @@ const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => {
379392 getFlag,
380393 logout,
381394 login,
395+ portal,
382396 } ;
383397} ;
384398
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import type {
1212} from '../types.js' ;
1313
1414import type { OAuth2CodeExchangeResponse } from '../../oauth2-flows/types.js' ;
15+ import type { GeneratePortalUrlParams } from '@kinde/js-utils' ;
1516
1617const createAuthorizationCodeClient = (
1718 options : ACClientOptions ,
@@ -73,6 +74,22 @@ const createAuthorizationCodeClient = (
7374 } ) ;
7475 } ;
7576
77+ /**
78+ * Method makes use of the `createPortalUrl` method of the AuthCodeAbstract
79+ * client above to return login url.
80+ * @param {SessionManager } sessionManager
81+ * @param {GeneratePortalUrlParams } options
82+ * @returns {Promise<{ url: URL }> } required authorization URL
83+ */
84+ const portal = async (
85+ sessionManager : SessionManager ,
86+ options : GeneratePortalUrlParams
87+ ) : Promise < { url : URL } > => {
88+ return await client . createPortalUrl ( sessionManager , {
89+ ...options ,
90+ } ) ;
91+ } ;
92+
7693 /**
7794 * Method makes use of the `handleRedirectFromAuthDomain` method of the
7895 * `AuthCodeAbstract` client above to handle the redirection back to the app.
@@ -175,6 +192,7 @@ const createAuthorizationCodeClient = (
175192 getUser,
176193 logout,
177194 login,
195+ portal,
178196 } ;
179197} ;
180198
Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ export interface BrowserPKCEClientOptions extends AuthorizationCodeOptions {
1212 sessionManager ?: SessionManager ;
1313}
1414
15+ export { PortalPage } from '@kinde/js-utils' ;
16+ export type { GeneratePortalUrlParams } from '@kinde/js-utils' ;
17+
1518export interface PKCEClientOptions extends AuthorizationCodeOptions { }
1619export interface CCClientOptions extends ClientCredentialsOptions { }
1720export interface ACClientOptions extends AuthorizationCodeOptions {
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import type {
1313} from './types.js' ;
1414import { createLocalJWKSet } from 'jose' ;
1515import { getRemoteJwks } from '../utilities/remote-jwks-cache.js' ;
16+ import type { GeneratePortalUrlParams } from '@kinde/js-utils' ;
1617
1718/**
1819 * Abstract class provides contract (methods) for classes implementing OAuth2.0 flows
@@ -71,6 +72,17 @@ export abstract class AuthCodeAbstract {
7172 options : AuthURLOptions
7273 ) : Promise < URL > ;
7374
75+ /**
76+ * Abstract method mandates implementation of logic required for creating portal URL
77+ * for accessing Kinde's portal interface, utilizing session data for authentication.
78+ * @param {GeneratePortalUrlParams } options
79+ * @returns {Promise<{url: URL}> } object containing the portal URL
80+ */
81+ public abstract createPortalUrl (
82+ sessionManager : SessionManager ,
83+ options : GeneratePortalUrlParams
84+ ) : Promise < { url : URL } > ;
85+
7486 /**
7587 * Abstract method will implement logic required for exchanging received auth code
7688 * post user-authentication with authorization server to receive access, refresh
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ import type {
1212 AuthURLOptions ,
1313 AuthorizationCodeOptions ,
1414} from './types.js' ;
15+ import type { GeneratePortalUrlParams } from '@kinde/js-utils' ;
16+ import { createPortalUrl } from '../utilities/createPortalUrl.js' ;
1517
1618/**
1719 * Class provides implementation for the authorization code with PKCE extension
@@ -67,6 +69,24 @@ export class AuthCodeWithPKCE extends AuthCodeAbstract {
6769 return authURL ;
6870 }
6971
72+ /**
73+ * Method provides implementation for `createPortalUrl` method mandated by
74+ * `AuthCodeAbstract` parent class, see corresponding comment in parent class for
75+ * further explanation.
76+ * @param {SessionManager } sessionManager
77+ * @param {Omit<GeneratePortalUrlParams, 'domain'> } options
78+ * @returns {Promise<{url: URL}> } required authorization URL
79+ */
80+ async createPortalUrl (
81+ sessionManager : SessionManager ,
82+ options : Omit < GeneratePortalUrlParams , 'domain' >
83+ ) : Promise < { url : URL } > {
84+ return await createPortalUrl ( sessionManager , {
85+ domain : this . config . authDomain ,
86+ ...options ,
87+ } ) ;
88+ }
89+
7090 /**
7191 * Method provides implementation for `refreshTokens` method mandated by
7292 * `AuthCodeAbstract` parent class, see corresponding comment in parent class for
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ import type {
77 AuthorizationCodeOptions ,
88 AuthURLOptions ,
99} from './types.js' ;
10+ import type { GeneratePortalUrlParams } from '@kinde/js-utils' ;
11+ import { createPortalUrl } from '../utilities/createPortalUrl.js' ;
1012
1113/**
1214 * Class provides implementation for the authorization code OAuth2.0 flow.
@@ -52,6 +54,24 @@ export class AuthorizationCode extends AuthCodeAbstract {
5254 return authURL ;
5355 }
5456
57+ /**
58+ * Method provides implementation for `createPortalUrl` method mandated by
59+ * `AuthCodeAbstract` parent class, see corresponding comment in parent class for
60+ * further explanation.
61+ * @param {SessionManager } sessionManager
62+ * @param {Omit<GeneratePortalUrlParams, 'domain'> } options
63+ * @returns {Promise<{url: URL}> } required authorization URL
64+ */
65+ async createPortalUrl (
66+ sessionManager : SessionManager ,
67+ options : Omit < GeneratePortalUrlParams , 'domain' >
68+ ) : Promise < { url : URL } > {
69+ return await createPortalUrl ( sessionManager , {
70+ domain : this . config . authDomain ,
71+ ...options ,
72+ } ) ;
73+ }
74+
5575 /**
5676 * Method provides implementation for `refreshTokens` method mandated by
5777 * `AuthCodeAbstract` parent class, see corresponding comment in parent class for
Original file line number Diff line number Diff line change 1+ import {
2+ generatePortalUrl ,
3+ MemoryStorage ,
4+ setActiveStorage ,
5+ StorageKeys ,
6+ } from '@kinde/js-utils' ;
7+ import type { GeneratePortalUrlParams } from '@kinde/js-utils' ;
8+ import { type SessionManager } from '../session-managers/index.js' ;
9+
10+ export const createPortalUrl = async (
11+ sessionManager : SessionManager ,
12+ options : GeneratePortalUrlParams
13+ ) : Promise < { url : URL } > => {
14+ const token = await sessionManager . getSessionItem ( 'access_token' ) ; // Ensure session is initialized
15+
16+ if ( ! token ) {
17+ throw new Error ( 'No active session found.' ) ;
18+ }
19+
20+ const storage = new MemoryStorage ( ) ;
21+ await storage . setSessionItem ( StorageKeys . accessToken , token ) ;
22+ setActiveStorage ( storage ) ;
23+
24+ return await generatePortalUrl ( {
25+ domain : options . domain ,
26+ returnUrl : options . returnUrl ,
27+ subNav : options . subNav ,
28+ } ) ;
29+ } ;
Original file line number Diff line number Diff line change 6969 "typescript" : " ^5.0.4"
7070 },
7171 "dependencies" : {
72+ "@kinde/js-utils" : " ^0.18.1" ,
7273 "jose" : " ^5.2.2" ,
7374 "uncrypto" : " ^0.1.3"
7475 },
You can’t perform that action at this time.
0 commit comments