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 1
1
import { BrowserSessionManager } from '../../session-managers/index.js' ;
2
2
import { AuthCodeWithPKCE } from '../../oauth2-flows/index.js' ;
3
3
import * as utilities from '../../utilities/index.js' ;
4
+ import type { GeneratePortalUrlParams } from '@kinde/js-utils' ;
4
5
5
6
import type {
6
7
UserType ,
@@ -63,6 +64,18 @@ const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => {
63
64
} ) ;
64
65
} ;
65
66
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
+
66
79
/**
67
80
* Method makes use of the `handleRedirectFromAuthDomain` method of the
68
81
* `AuthCodeWithPKCE` client above to handle the redirection back to the app.
@@ -379,6 +392,7 @@ const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => {
379
392
getFlag,
380
393
logout,
381
394
login,
395
+ portal,
382
396
} ;
383
397
} ;
384
398
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import type {
12
12
} from '../types.js' ;
13
13
14
14
import type { OAuth2CodeExchangeResponse } from '../../oauth2-flows/types.js' ;
15
+ import type { GeneratePortalUrlParams } from '@kinde/js-utils' ;
15
16
16
17
const createAuthorizationCodeClient = (
17
18
options : ACClientOptions ,
@@ -73,6 +74,22 @@ const createAuthorizationCodeClient = (
73
74
} ) ;
74
75
} ;
75
76
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
+
76
93
/**
77
94
* Method makes use of the `handleRedirectFromAuthDomain` method of the
78
95
* `AuthCodeAbstract` client above to handle the redirection back to the app.
@@ -175,6 +192,7 @@ const createAuthorizationCodeClient = (
175
192
getUser,
176
193
logout,
177
194
login,
195
+ portal,
178
196
} ;
179
197
} ;
180
198
Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ export interface BrowserPKCEClientOptions extends AuthorizationCodeOptions {
12
12
sessionManager ?: SessionManager ;
13
13
}
14
14
15
+ export { PortalPage } from '@kinde/js-utils' ;
16
+ export type { GeneratePortalUrlParams } from '@kinde/js-utils' ;
17
+
15
18
export interface PKCEClientOptions extends AuthorizationCodeOptions { }
16
19
export interface CCClientOptions extends ClientCredentialsOptions { }
17
20
export interface ACClientOptions extends AuthorizationCodeOptions {
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import type {
13
13
} from './types.js' ;
14
14
import { createLocalJWKSet } from 'jose' ;
15
15
import { getRemoteJwks } from '../utilities/remote-jwks-cache.js' ;
16
+ import type { GeneratePortalUrlParams } from '@kinde/js-utils' ;
16
17
17
18
/**
18
19
* Abstract class provides contract (methods) for classes implementing OAuth2.0 flows
@@ -71,6 +72,17 @@ export abstract class AuthCodeAbstract {
71
72
options : AuthURLOptions
72
73
) : Promise < URL > ;
73
74
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
+
74
86
/**
75
87
* Abstract method will implement logic required for exchanging received auth code
76
88
* 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 {
12
12
AuthURLOptions ,
13
13
AuthorizationCodeOptions ,
14
14
} from './types.js' ;
15
+ import type { GeneratePortalUrlParams } from '@kinde/js-utils' ;
16
+ import { createPortalUrl } from '../utilities/createPortalUrl.js' ;
15
17
16
18
/**
17
19
* Class provides implementation for the authorization code with PKCE extension
@@ -67,6 +69,24 @@ export class AuthCodeWithPKCE extends AuthCodeAbstract {
67
69
return authURL ;
68
70
}
69
71
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
+
70
90
/**
71
91
* Method provides implementation for `refreshTokens` method mandated by
72
92
* `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 {
7
7
AuthorizationCodeOptions ,
8
8
AuthURLOptions ,
9
9
} from './types.js' ;
10
+ import type { GeneratePortalUrlParams } from '@kinde/js-utils' ;
11
+ import { createPortalUrl } from '../utilities/createPortalUrl.js' ;
10
12
11
13
/**
12
14
* Class provides implementation for the authorization code OAuth2.0 flow.
@@ -52,6 +54,24 @@ export class AuthorizationCode extends AuthCodeAbstract {
52
54
return authURL ;
53
55
}
54
56
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
+
55
75
/**
56
76
* Method provides implementation for `refreshTokens` method mandated by
57
77
* `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 69
69
"typescript" : " ^5.0.4"
70
70
},
71
71
"dependencies" : {
72
+ "@kinde/js-utils" : " ^0.18.1" ,
72
73
"jose" : " ^5.2.2" ,
73
74
"uncrypto" : " ^0.1.3"
74
75
},
You can’t perform that action at this time.
0 commit comments