@forgerock/oidc-client 0.0.0-beta-20250617173233 → 0.0.0-beta-20250825180717
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +8 -1
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/authorize.request.d.ts +16 -0
- package/dist/src/lib/authorize.request.d.ts.map +1 -0
- package/dist/src/lib/authorize.request.js +57 -0
- package/dist/src/lib/authorize.request.js.map +1 -0
- package/dist/src/lib/authorize.request.types.d.ts +11 -0
- package/dist/src/lib/authorize.request.types.d.ts.map +1 -0
- package/dist/src/lib/authorize.request.types.js +2 -0
- package/dist/src/lib/authorize.request.types.js.map +1 -0
- package/dist/src/lib/authorize.request.utils.d.ts +55 -0
- package/dist/src/lib/authorize.request.utils.d.ts.map +1 -0
- package/dist/src/lib/authorize.request.utils.js +187 -0
- package/dist/src/lib/authorize.request.utils.js.map +1 -0
- package/dist/src/lib/authorize.slice.d.ts +5 -0
- package/dist/src/lib/authorize.slice.d.ts.map +1 -0
- package/dist/src/lib/authorize.slice.js +21 -0
- package/dist/src/lib/authorize.slice.js.map +1 -0
- package/dist/src/lib/client.store.d.ts +108 -0
- package/dist/src/lib/client.store.d.ts.map +1 -0
- package/dist/src/lib/client.store.js +341 -0
- package/dist/src/lib/client.store.js.map +1 -0
- package/dist/src/lib/client.store.utils.d.ts +96 -0
- package/dist/src/lib/client.store.utils.d.ts.map +1 -0
- package/dist/src/lib/client.store.utils.js +92 -0
- package/dist/src/lib/client.store.utils.js.map +1 -0
- package/dist/src/lib/client.types.d.ts +13 -0
- package/dist/src/lib/client.types.d.ts.map +1 -0
- package/dist/src/lib/client.types.js +2 -0
- package/dist/src/lib/client.types.js.map +1 -0
- package/dist/src/lib/config.types.d.ts +22 -0
- package/dist/src/lib/config.types.d.ts.map +1 -0
- package/dist/src/lib/config.types.js +2 -0
- package/dist/src/lib/config.types.js.map +1 -0
- package/dist/src/lib/exchange.request.d.ts +18 -0
- package/dist/src/lib/exchange.request.d.ts.map +1 -0
- package/dist/src/lib/exchange.request.js +22 -0
- package/dist/src/lib/exchange.request.js.map +1 -0
- package/dist/src/lib/exchange.types.d.ts +21 -0
- package/dist/src/lib/exchange.types.d.ts.map +1 -0
- package/dist/src/lib/exchange.types.js +2 -0
- package/dist/src/lib/exchange.types.js.map +1 -0
- package/dist/src/lib/exchange.utils.d.ts +28 -0
- package/dist/src/lib/exchange.utils.d.ts.map +1 -0
- package/dist/src/lib/exchange.utils.js +55 -0
- package/dist/src/lib/exchange.utils.js.map +1 -0
- package/dist/src/lib/logout.request.d.ts +17 -0
- package/dist/src/lib/logout.request.d.ts.map +1 -0
- package/dist/src/lib/logout.request.js +33 -0
- package/dist/src/lib/logout.request.js.map +1 -0
- package/dist/src/lib/oidc.api.d.ts +25 -0
- package/dist/src/lib/oidc.api.d.ts.map +1 -0
- package/dist/src/lib/oidc.api.js +165 -0
- package/dist/src/lib/oidc.api.js.map +1 -0
- package/dist/src/lib/oidc.api.utils.d.ts +3 -0
- package/dist/src/lib/oidc.api.utils.d.ts.map +1 -0
- package/dist/src/lib/oidc.api.utils.js +9 -0
- package/dist/src/lib/oidc.api.utils.js.map +1 -0
- package/dist/src/lib/token.utils.d.ts +2 -0
- package/dist/src/lib/token.utils.d.ts.map +1 -0
- package/dist/src/lib/token.utils.js +15 -0
- package/dist/src/lib/token.utils.js.map +1 -0
- package/dist/src/lib/wellknown.api.d.ts +7 -0
- package/dist/src/lib/wellknown.api.d.ts.map +1 -0
- package/dist/src/lib/wellknown.api.js +22 -0
- package/dist/src/lib/wellknown.api.js.map +1 -0
- package/dist/src/types.d.ts +5 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +10 -0
- package/dist/src/types.js.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +34 -5
- package/CHANGELOG.md +0 -11
- package/dist/src/lib/token-store.d.ts +0 -12
- package/dist/src/lib/token-store.d.ts.map +0 -1
- package/dist/src/lib/token-store.js +0 -9
- package/dist/src/lib/token-store.test-d.d.ts +0 -2
- package/dist/src/lib/token-store.test-d.d.ts.map +0 -1
- package/dist/src/lib/token-store.test-d.js +0 -43
- package/eslint.config.mjs +0 -22
- package/src/index.ts +0 -1
- package/src/lib/token-store.test-d.ts +0 -52
- package/src/lib/token-store.test.ts +0 -38
- package/src/lib/token-store.ts +0 -10
- package/tsconfig.json +0 -22
- package/tsconfig.lib.json +0 -40
- package/tsconfig.spec.json +0 -41
- package/typedoc.json +0 -4
- package/vite.config.ts +0 -23
package/README.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
1
|
# oidc-client
|
|
2
2
|
|
|
3
3
|
A generic OpenID Connect (OIDC) client library for JavaScript and TypeScript, designed to work with any OIDC-compliant identity provider.
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
// Initialize OIDC Client
|
|
7
|
+
const oidcClient = oidc({
|
|
8
|
+
/* config */
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// Authorize API
|
|
12
|
+
const authResponse = oidcClient.authorize.background(); // Returns code and state if successful, error and Auth URL if not
|
|
13
|
+
const authUrl = oidcClient.authorize.url(); // Returns Auth URL or error
|
|
14
|
+
|
|
15
|
+
// Tokens API
|
|
16
|
+
const newTokens = oidcClient.token.exchange({
|
|
17
|
+
/* code, state */
|
|
18
|
+
}); // Returns new tokens or error
|
|
19
|
+
const existingTokens = oidcClient.token.get(); // Returns existing tokens or error
|
|
20
|
+
|
|
21
|
+
// User API
|
|
22
|
+
const user = oidcClient.user.info(); // Returns user object or error
|
|
23
|
+
const logoutResponse = oidcClient.user.logout(); // Returns null or error
|
|
24
|
+
```
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './lib/
|
|
1
|
+
export * from './lib/client.store.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAMA,cAAc,uBAAuB,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* This software may be modified and distributed under the terms
|
|
5
|
+
* of the MIT license. See the LICENSE file for details.
|
|
6
|
+
*/
|
|
7
|
+
export * from './lib/client.store.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CustomLogger } from '@forgerock/sdk-logger';
|
|
2
|
+
import { Micro } from 'effect';
|
|
3
|
+
import type { GetAuthorizationUrlOptions, WellKnownResponse } from '@forgerock/sdk-types';
|
|
4
|
+
import type { OidcConfig } from './config.types.js';
|
|
5
|
+
import type { AuthorizeErrorResponse, AuthorizeSuccessResponse } from './authorize.request.types.js';
|
|
6
|
+
/**
|
|
7
|
+
* @function authorizeµ
|
|
8
|
+
* @description Creates an authorization URL for the OIDC client.
|
|
9
|
+
* @param {WellKnownResponse} wellknown - The well-known configuration for the OIDC server.
|
|
10
|
+
* @param {OidcConfig} config - The OIDC client configuration.
|
|
11
|
+
* @param {CustomLogger} log - The logger instance for logging debug information.
|
|
12
|
+
* @param {GetAuthorizationUrlOptions} options - Optional parameters for the authorization request.
|
|
13
|
+
* @returns {Micro.Micro<AuthorizeSuccessResponse, AuthorizeErrorResponse, never>} - A micro effect that resolves to the authorization response.
|
|
14
|
+
*/
|
|
15
|
+
export declare function authorizeµ(wellknown: WellKnownResponse, config: OidcConfig, log: CustomLogger, options?: GetAuthorizationUrlOptions): Micro.Micro<AuthorizeSuccessResponse, AuthorizeErrorResponse, never>;
|
|
16
|
+
//# sourceMappingURL=authorize.request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.request.d.ts","sourceRoot":"","sources":["../../../src/lib/authorize.request.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAU/B,OAAO,KAAK,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EACV,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,8BAA8B,CAAC;AAEtC;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,YAAY,EACjB,OAAO,CAAC,EAAE,0BAA0B,wEAyDrC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Micro } from 'effect';
|
|
2
|
+
import { authorizeFetchµ, createAuthorizeUrlµ, authorizeIframeµ, buildAuthorizeOptionsµ, createAuthorizeErrorµ, } from './authorize.request.utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* @function authorizeµ
|
|
5
|
+
* @description Creates an authorization URL for the OIDC client.
|
|
6
|
+
* @param {WellKnownResponse} wellknown - The well-known configuration for the OIDC server.
|
|
7
|
+
* @param {OidcConfig} config - The OIDC client configuration.
|
|
8
|
+
* @param {CustomLogger} log - The logger instance for logging debug information.
|
|
9
|
+
* @param {GetAuthorizationUrlOptions} options - Optional parameters for the authorization request.
|
|
10
|
+
* @returns {Micro.Micro<AuthorizeSuccessResponse, AuthorizeErrorResponse, never>} - A micro effect that resolves to the authorization response.
|
|
11
|
+
*/
|
|
12
|
+
export function authorizeµ(wellknown, config, log, options) {
|
|
13
|
+
return buildAuthorizeOptionsµ(wellknown, config, options).pipe(Micro.flatMap(([url, config, options]) => createAuthorizeUrlµ(url, config, options)), Micro.tap((url) => log.debug('Authorize URL created', url)), Micro.tapError((url) => Micro.sync(() => log.error('Error creating authorize URL', url))), Micro.flatMap(([url, config, options]) => {
|
|
14
|
+
if (options.responseMode === 'pi.flow') {
|
|
15
|
+
/**
|
|
16
|
+
* If we support the pi.flow field, this means we are using a PingOne server.
|
|
17
|
+
* PingOne servers do not support redirection through iframes because they
|
|
18
|
+
* set iframe's to DENY.
|
|
19
|
+
*
|
|
20
|
+
* We do not use RTK Query for this because we don't want caching, or store
|
|
21
|
+
* updates, and want the request to be made similar to the iframe method below.
|
|
22
|
+
*
|
|
23
|
+
* This returns a Micro that resolves to the parsed response JSON.
|
|
24
|
+
*/
|
|
25
|
+
return authorizeFetchµ(url).pipe(Micro.flatMap((response) => {
|
|
26
|
+
if ('code' in response) {
|
|
27
|
+
log.debug('Received code in response', response);
|
|
28
|
+
return Micro.succeed(response);
|
|
29
|
+
}
|
|
30
|
+
log.error('Error in authorize response', response);
|
|
31
|
+
// For redirection, we need to remove `pi.flow` from the options
|
|
32
|
+
const redirectOptions = options;
|
|
33
|
+
delete redirectOptions.responseMode;
|
|
34
|
+
return createAuthorizeErrorµ(response, wellknown, config, options);
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
/**
|
|
39
|
+
* If the response mode is not pi.flow, then we are likely using a traditional
|
|
40
|
+
* redirect based server supporting iframes. An example would be PingAM.
|
|
41
|
+
*
|
|
42
|
+
* This returns a Micro that's either the success URL parameters or error URL
|
|
43
|
+
* parameters.
|
|
44
|
+
*/
|
|
45
|
+
return authorizeIframeµ(url, config).pipe(Micro.flatMap((response) => {
|
|
46
|
+
if ('code' in response && 'state' in response) {
|
|
47
|
+
log.debug('Received authorization code', response);
|
|
48
|
+
return Micro.succeed(response);
|
|
49
|
+
}
|
|
50
|
+
log.error('Error in authorize response', response);
|
|
51
|
+
const errorResponse = response;
|
|
52
|
+
return createAuthorizeErrorµ(errorResponse, wellknown, config, options);
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=authorize.request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.request.js","sourceRoot":"","sources":["../../../src/lib/authorize.request.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE/B,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,8BAA8B,CAAC;AAStC;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CACxB,SAA4B,EAC5B,MAAkB,EAClB,GAAiB,EACjB,OAAoC;IAEpC,OAAO,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAC5D,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,EACpF,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,EAAE,GAAG,CAAC,CAAC,EAC3D,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAC,CAAC,EACzF,KAAK,CAAC,OAAO,CAAC,CAAC,CAA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,CACF,CACF,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface AuthorizeSuccessResponse {
|
|
2
|
+
code: string;
|
|
3
|
+
state: string;
|
|
4
|
+
}
|
|
5
|
+
export interface AuthorizeErrorResponse {
|
|
6
|
+
error: string;
|
|
7
|
+
error_description: string;
|
|
8
|
+
redirectUrl?: string;
|
|
9
|
+
type: 'auth_error' | 'argument_error' | 'wellknown_error';
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=authorize.request.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.request.types.d.ts","sourceRoot":"","sources":["../../../src/lib/authorize.request.types.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,YAAY,GAAG,gBAAgB,GAAG,iBAAiB,CAAC;CAC3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.request.types.js","sourceRoot":"","sources":["../../../src/lib/authorize.request.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Micro } from 'effect';
|
|
2
|
+
import { ResolvedParams } from '@forgerock/iframe-manager';
|
|
3
|
+
import type { WellKnownResponse, GetAuthorizationUrlOptions } from '@forgerock/sdk-types';
|
|
4
|
+
import type { AuthorizeErrorResponse, AuthorizeSuccessResponse } from './authorize.request.types.js';
|
|
5
|
+
import type { OidcConfig } from './config.types.js';
|
|
6
|
+
/**
|
|
7
|
+
* @function authorizeFetchµ
|
|
8
|
+
* @description Fetches the authorization response from the given URL.
|
|
9
|
+
* @param {string} url - The URL to fetch the authorization response from.
|
|
10
|
+
* @returns {Micro.Micro<AuthorizeSuccessResponse, AuthorizeErrorResponse, never>} - A micro effect that resolves to the authorization response.
|
|
11
|
+
*/
|
|
12
|
+
export declare function authorizeFetchµ(url: string): Micro.Micro<AuthorizeSuccessResponse | AuthorizeErrorResponse, AuthorizeErrorResponse, never>;
|
|
13
|
+
/**
|
|
14
|
+
* @function authorizeIframeµ
|
|
15
|
+
* @description Fetches the authorization response from the given URL using an iframe.
|
|
16
|
+
* @param {string} url - The authorization URL to be used for the iframe.
|
|
17
|
+
* @param {OidcConfig} config - The OIDC client configuration.
|
|
18
|
+
* @returns {Micro.Micro<ResolvedParams, AuthorizeErrorResponse, never>}
|
|
19
|
+
*/
|
|
20
|
+
export declare function authorizeIframeµ(url: string, config: OidcConfig): Micro.Micro<ResolvedParams, AuthorizeErrorResponse, never>;
|
|
21
|
+
type BuildAuthorizationData = [string, OidcConfig, GetAuthorizationUrlOptions];
|
|
22
|
+
export type OptionalAuthorizeOptions = Partial<GetAuthorizationUrlOptions>;
|
|
23
|
+
/**
|
|
24
|
+
* @function buildAuthorizeOptionsµ
|
|
25
|
+
* @description Builds the authorization options for the OIDC client.
|
|
26
|
+
* @param {WellKnownResponse} wellknown - The well-known configuration for the OIDC server.
|
|
27
|
+
* @param {OidcConfig} config - The OIDC client configuration.
|
|
28
|
+
* @param {OptionalAuthorizeOptions} options - Optional parameters for the authorization request.
|
|
29
|
+
* @returns {Micro.Micro<BuildAuthorizationData, AuthorizeErrorResponse, never>}
|
|
30
|
+
*/
|
|
31
|
+
export declare function buildAuthorizeOptionsµ(wellknown: WellKnownResponse, config: OidcConfig, options?: OptionalAuthorizeOptions): Micro.Micro<BuildAuthorizationData, AuthorizeErrorResponse, never>;
|
|
32
|
+
/**
|
|
33
|
+
* @function createAuthorizeErrorµ
|
|
34
|
+
* @description Creates an error response with new Authorize URL for the authorization request.
|
|
35
|
+
* @param { error: string; error_description: string } res - The error response from the authorization request.
|
|
36
|
+
* @param {WellKnownResponse} wellknown- The well-known configuration for the OIDC server.
|
|
37
|
+
* @param { OidcConfig } config- The OIDC client configuration.
|
|
38
|
+
* @param { GetAuthorizationUrlOptions } options- Optional parameters for the authorization request.
|
|
39
|
+
* @returns { Micro.Micro<never, AuthorizeErrorResponse, never> }
|
|
40
|
+
*/
|
|
41
|
+
export declare function createAuthorizeErrorµ(res: {
|
|
42
|
+
error: string;
|
|
43
|
+
error_description: string;
|
|
44
|
+
}, wellknown: WellKnownResponse, config: OidcConfig, options: GetAuthorizationUrlOptions): Micro.Micro<never, AuthorizeErrorResponse, never>;
|
|
45
|
+
/**
|
|
46
|
+
* @function createAuthorizeUrlµ
|
|
47
|
+
* @description Creates an authorization URL and related options/config for the Authorize request.
|
|
48
|
+
* @param {string} path - The path to the authorization endpoint.
|
|
49
|
+
* @param { OidcConfig } config - The OIDC client configuration.
|
|
50
|
+
* @param { GetAuthorizationUrlOptions } options - Optional parameters for the authorization request.
|
|
51
|
+
* @returns { Micro.Micro<[string, OidcConfig, GetAuthorizationUrlOptions], AuthorizeErrorResponse, never> }
|
|
52
|
+
*/
|
|
53
|
+
export declare function createAuthorizeUrlµ(path: string, config: OidcConfig, options: GetAuthorizationUrlOptions): Micro.Micro<[string, OidcConfig, GetAuthorizationUrlOptions], AuthorizeErrorResponse, never>;
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=authorize.request.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.request.utils.d.ts","sourceRoot":"","sources":["../../../src/lib/authorize.request.utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE/B,OAAO,EAAiB,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAE1F,OAAO,KAAK,EACV,sBAAsB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AAC,EAAE,sBAAsB,EAAE,KAAK,CAAC,CAsB9F"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* This software may be modified and distributed under the terms
|
|
5
|
+
* of the MIT license. See the LICENSE file for details.
|
|
6
|
+
*/
|
|
7
|
+
import { createAuthorizeUrl } from '@forgerock/sdk-oidc';
|
|
8
|
+
import { Micro } from 'effect';
|
|
9
|
+
import { iFrameManager } from '@forgerock/iframe-manager';
|
|
10
|
+
/**
|
|
11
|
+
* @function authorizeFetchµ
|
|
12
|
+
* @description Fetches the authorization response from the given URL.
|
|
13
|
+
* @param {string} url - The URL to fetch the authorization response from.
|
|
14
|
+
* @returns {Micro.Micro<AuthorizeSuccessResponse, AuthorizeErrorResponse, never>} - A micro effect that resolves to the authorization response.
|
|
15
|
+
*/
|
|
16
|
+
export function authorizeFetchµ(url) {
|
|
17
|
+
return Micro.tryPromise({
|
|
18
|
+
try: async () => {
|
|
19
|
+
const response = await fetch(url, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
credentials: 'include',
|
|
22
|
+
});
|
|
23
|
+
const resJson = (await response.json());
|
|
24
|
+
if (!resJson || typeof resJson !== 'object') {
|
|
25
|
+
return {
|
|
26
|
+
error: 'Authorization Network Failure',
|
|
27
|
+
error_description: 'Failed to fetch authorization response',
|
|
28
|
+
type: 'auth_error',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if ('authorizeResponse' in resJson) {
|
|
32
|
+
// Return authorizeResponse as it contains the code and state
|
|
33
|
+
return resJson.authorizeResponse;
|
|
34
|
+
}
|
|
35
|
+
else if ('details' in resJson && resJson.details && Array.isArray(resJson.details)) {
|
|
36
|
+
const details = resJson.details[0];
|
|
37
|
+
// Return error response
|
|
38
|
+
return {
|
|
39
|
+
error: details.code || 'Unknown_Error',
|
|
40
|
+
error_description: details.message || 'An error occurred during authorization',
|
|
41
|
+
type: 'auth_error',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// Unrecognized response format
|
|
45
|
+
return {
|
|
46
|
+
error: 'Authorization Network Failure',
|
|
47
|
+
error_description: 'Unexpected response format from authorization endpoint',
|
|
48
|
+
type: 'auth_error',
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
catch: (err) => {
|
|
52
|
+
let message = 'Error fetching authorization URL';
|
|
53
|
+
if (err instanceof Error) {
|
|
54
|
+
message = err.message;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
error: 'Authorization Network Failure',
|
|
58
|
+
error_description: message,
|
|
59
|
+
type: 'auth_error',
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @function authorizeIframeµ
|
|
66
|
+
* @description Fetches the authorization response from the given URL using an iframe.
|
|
67
|
+
* @param {string} url - The authorization URL to be used for the iframe.
|
|
68
|
+
* @param {OidcConfig} config - The OIDC client configuration.
|
|
69
|
+
* @returns {Micro.Micro<ResolvedParams, AuthorizeErrorResponse, never>}
|
|
70
|
+
*/
|
|
71
|
+
export function authorizeIframeµ(url, config) {
|
|
72
|
+
return Micro.tryPromise({
|
|
73
|
+
try: () => {
|
|
74
|
+
const params = iFrameManager().getParamsByRedirect({
|
|
75
|
+
url,
|
|
76
|
+
/***
|
|
77
|
+
* https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2
|
|
78
|
+
* The client MUST ignore unrecognized response parameters.
|
|
79
|
+
*/
|
|
80
|
+
successParams: ['code', 'state'],
|
|
81
|
+
errorParams: ['error', 'error_description'],
|
|
82
|
+
timeout: config.serverConfig.timeout || 3000,
|
|
83
|
+
});
|
|
84
|
+
return params;
|
|
85
|
+
},
|
|
86
|
+
catch: (err) => {
|
|
87
|
+
let message = 'Error calling authorization URL';
|
|
88
|
+
if (err instanceof Error) {
|
|
89
|
+
message = err.message;
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
error: 'Authorization Network Failure',
|
|
93
|
+
error_description: message,
|
|
94
|
+
type: 'auth_error',
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @function buildAuthorizeOptionsµ
|
|
101
|
+
* @description Builds the authorization options for the OIDC client.
|
|
102
|
+
* @param {WellKnownResponse} wellknown - The well-known configuration for the OIDC server.
|
|
103
|
+
* @param {OidcConfig} config - The OIDC client configuration.
|
|
104
|
+
* @param {OptionalAuthorizeOptions} options - Optional parameters for the authorization request.
|
|
105
|
+
* @returns {Micro.Micro<BuildAuthorizationData, AuthorizeErrorResponse, never>}
|
|
106
|
+
*/
|
|
107
|
+
export function buildAuthorizeOptionsµ(wellknown, config, options) {
|
|
108
|
+
const isPiFlow = wellknown.response_modes_supported?.includes('pi.flow');
|
|
109
|
+
return Micro.sync(() => [
|
|
110
|
+
wellknown.authorization_endpoint,
|
|
111
|
+
config,
|
|
112
|
+
{
|
|
113
|
+
clientId: config.clientId,
|
|
114
|
+
redirectUri: config.redirectUri,
|
|
115
|
+
scope: config.scope || 'openid',
|
|
116
|
+
responseType: config.responseType || 'code',
|
|
117
|
+
...(isPiFlow && { responseMode: 'pi.flow' }),
|
|
118
|
+
...options,
|
|
119
|
+
},
|
|
120
|
+
]);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @function createAuthorizeErrorµ
|
|
124
|
+
* @description Creates an error response with new Authorize URL for the authorization request.
|
|
125
|
+
* @param { error: string; error_description: string } res - The error response from the authorization request.
|
|
126
|
+
* @param {WellKnownResponse} wellknown- The well-known configuration for the OIDC server.
|
|
127
|
+
* @param { OidcConfig } config- The OIDC client configuration.
|
|
128
|
+
* @param { GetAuthorizationUrlOptions } options- Optional parameters for the authorization request.
|
|
129
|
+
* @returns { Micro.Micro<never, AuthorizeErrorResponse, never> }
|
|
130
|
+
*/
|
|
131
|
+
export function createAuthorizeErrorµ(res, wellknown, config, options) {
|
|
132
|
+
return Micro.tryPromise({
|
|
133
|
+
try: () => createAuthorizeUrl(wellknown.authorization_endpoint, {
|
|
134
|
+
...options,
|
|
135
|
+
}),
|
|
136
|
+
catch: (error) => {
|
|
137
|
+
let message = 'Error creating authorization URL';
|
|
138
|
+
if (error instanceof Error) {
|
|
139
|
+
message = error.message;
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
error: 'AuthorizationUrlError',
|
|
143
|
+
error_description: message,
|
|
144
|
+
type: 'auth_error',
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
}).pipe(Micro.flatMap((url) => {
|
|
148
|
+
return Micro.fail({
|
|
149
|
+
error: res.error,
|
|
150
|
+
error_description: res.error_description,
|
|
151
|
+
type: 'auth_error',
|
|
152
|
+
redirectUrl: url,
|
|
153
|
+
});
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* @function createAuthorizeUrlµ
|
|
158
|
+
* @description Creates an authorization URL and related options/config for the Authorize request.
|
|
159
|
+
* @param {string} path - The path to the authorization endpoint.
|
|
160
|
+
* @param { OidcConfig } config - The OIDC client configuration.
|
|
161
|
+
* @param { GetAuthorizationUrlOptions } options - Optional parameters for the authorization request.
|
|
162
|
+
* @returns { Micro.Micro<[string, OidcConfig, GetAuthorizationUrlOptions], AuthorizeErrorResponse, never> }
|
|
163
|
+
*/
|
|
164
|
+
export function createAuthorizeUrlµ(path, config, options) {
|
|
165
|
+
return Micro.tryPromise({
|
|
166
|
+
try: async () => [
|
|
167
|
+
await createAuthorizeUrl(path, {
|
|
168
|
+
...options,
|
|
169
|
+
prompt: 'none',
|
|
170
|
+
}),
|
|
171
|
+
config,
|
|
172
|
+
options,
|
|
173
|
+
],
|
|
174
|
+
catch: (error) => {
|
|
175
|
+
let message = 'Error creating authorization URL';
|
|
176
|
+
if (error instanceof Error) {
|
|
177
|
+
message = error.message;
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
error: 'AuthorizationUrlError',
|
|
181
|
+
error_description: message,
|
|
182
|
+
type: 'auth_error',
|
|
183
|
+
};
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=authorize.request.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.request.utils.js","sourceRoot":"","sources":["../../../src/lib/authorize.request.utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAkB,MAAM,2BAA2B,CAAC;AAU1E;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,GAAW;IAEX,OAAO,KAAK,CAAC,UAAU,CAAC;QACtB,GAAG,EAAE,KAAK,IAAI,EAAE;YACd,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAChC,MAAM,EAAE,MAAM;gBACd,WAAW,EAAE,SAAS;aACvB,CAAC,CAAC;YACH,MAAM,OAAO,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAE3B,CAAC;YAEZ,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;gBAC5C,OAAO;oBACL,KAAK,EAAE,+BAA+B;oBACtC,iBAAiB,EAAE,wCAAwC;oBAC3D,IAAI,EAAE,YAAY;iBACnB,CAAC;YACJ,CAAC;YAED,IAAI,mBAAmB,IAAI,OAAO,EAAE,CAAC;gBACnC,6DAA6D;gBAC7D,OAAO,OAAO,CAAC,iBAA6C,CAAC;YAC/D,CAAC;iBAAM,IAAI,SAAS,IAAI,OAAO,IAAI,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;gBACrF,MAAM,OAAO,GAAG,OAAO,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E,OAAO;gBAC1B,IAAI,EAAE,YAAY;aACO,CAAC;QAC9B,CAAC;KACF,CAAC,CAAC,IAAI,CACL,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACpB,OAAO,KAAK,CAAC,IAAI,CAAC;YAChB,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;YACxC,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,GAAG;SACS,CAAC,CAAC;IAC/B,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAY,EACZ,MAAkB,EAClB,OAAmC;IAEnC,OAAO,KAAK,CAAC,UAAU,CAAC;QACtB,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC;YACf,MAAM,kBAAkB,CAAC,IAAI,EAAE;gBAC7B,GAAG,OAAO;gBACV,MAAM,EAAE,MAAM;aACf,CAAC;YACF,MAAM;YACN,OAAO;SACR;QACD,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;YACf,IAAI,OAAO,GAAG,kCAAkC,CAAC;YACjD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;gBAC3B,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;YAC1B,CAAC;YACD,OAAO;gBACL,KAAK,EAAE,uBAAuB;gBAC9B,iBAAiB,EAAE,OAAO;gBAC1B,IAAI,EAAE,YAAY;aACO,CAAC;QAC9B,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare const authorizeSlice: import("@reduxjs/toolkit/query").Api<import("@reduxjs/toolkit/query").BaseQueryFn<string | import("@reduxjs/toolkit/query").FetchArgs, unknown, import("@reduxjs/toolkit/query").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query").FetchBaseQueryMeta>, {
|
|
2
|
+
handleAuthorize: import("@reduxjs/toolkit/query").QueryDefinition<string, import("@reduxjs/toolkit/query").BaseQueryFn<string | import("@reduxjs/toolkit/query").FetchArgs, unknown, import("@reduxjs/toolkit/query").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query").FetchBaseQueryMeta>, never, string, "authorizeSlice", unknown>;
|
|
3
|
+
}, "authorizeSlice", never, typeof import("@reduxjs/toolkit/query").coreModuleName>;
|
|
4
|
+
export { authorizeSlice };
|
|
5
|
+
//# sourceMappingURL=authorize.slice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.slice.d.ts","sourceRoot":"","sources":["../../../src/lib/authorize.slice.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,cAAc;;mFAkBlB,CAAC;AAEH,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query';
|
|
2
|
+
const authorizeSlice = createApi({
|
|
3
|
+
reducerPath: 'authorizeSlice',
|
|
4
|
+
baseQuery: fetchBaseQuery({
|
|
5
|
+
credentials: 'include',
|
|
6
|
+
prepareHeaders: (headers) => {
|
|
7
|
+
headers.set('Content-Type', 'application/json');
|
|
8
|
+
headers.set('Accept', 'application/json');
|
|
9
|
+
headers.set('x-requested-with', 'ping-sdk');
|
|
10
|
+
headers.set('x-requested-platform', 'javascript');
|
|
11
|
+
return headers;
|
|
12
|
+
},
|
|
13
|
+
}),
|
|
14
|
+
endpoints: (builder) => ({
|
|
15
|
+
handleAuthorize: builder.query({
|
|
16
|
+
query: (authorizeUrl) => authorizeUrl,
|
|
17
|
+
}),
|
|
18
|
+
}),
|
|
19
|
+
});
|
|
20
|
+
export { authorizeSlice };
|
|
21
|
+
//# sourceMappingURL=authorize.slice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.slice.js","sourceRoot":"","sources":["../../../src/lib/authorize.slice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAEnE,MAAM,cAAc,GAAG,SAAS,CAAC;IAC/B,WAAW,EAAE,gBAAgB;IAC7B,SAAS,EAAE,cAAc,CAAC;QACxB,WAAW,EAAE,SAAS;QACtB,cAAc,EAAE,CAAC,OAAO,EAAE,EAAE;YAC1B,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;YAChD,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;YAC1C,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC;YAC5C,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE,YAAY,CAAC,CAAC;YAElD,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;IACF,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACvB,eAAe,EAAE,OAAO,CAAC,KAAK,CAAiB;YAC7C,KAAK,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY;SACtC,CAAC;KACH,CAAC;CACH,CAAC,CAAC;AAEH,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { CustomLogger, LogLevel } from '@forgerock/sdk-logger';
|
|
2
|
+
import { StorageConfig } from '@forgerock/storage';
|
|
3
|
+
import type { ActionTypes, RequestMiddleware } from '@forgerock/sdk-request-middleware';
|
|
4
|
+
import type { GenericError, GetAuthorizationUrlOptions } from '@forgerock/sdk-types';
|
|
5
|
+
import type { GetTokensOptions, LogoutResult } from './client.types.js';
|
|
6
|
+
import type { OauthTokens, OidcConfig } from './config.types.js';
|
|
7
|
+
import type { AuthorizeErrorResponse, AuthorizeSuccessResponse } from './authorize.request.types.js';
|
|
8
|
+
import type { TokenExchangeErrorResponse, TokenExchangeResponse } from './exchange.types.js';
|
|
9
|
+
/**
|
|
10
|
+
* @function oidc
|
|
11
|
+
* @description Factory function to create an OIDC client with methods for authorization, token exchange,
|
|
12
|
+
* user info retrieval, and logout. It initializes the client with the provided configuration,
|
|
13
|
+
* request middleware, logger, and storage options.
|
|
14
|
+
* @param param - configuration object containing the OIDC client configuration, request middleware, logger,
|
|
15
|
+
* @param {OidcConfig} param.config - OIDC configuration including server details, client ID, redirect URI,
|
|
16
|
+
* storage options, scope, and response type.
|
|
17
|
+
* @param {RequestMiddleware} param.requestMiddleware - optional array of request middleware functions to process requests.
|
|
18
|
+
* @param {{ level: LogLevel, custom: CustomLogger }} param.logger - optional logger configuration with log level and custom logger.
|
|
19
|
+
* @param {Partial<StorageConfig>} param.storage - optional storage configuration for persisting OIDC tokens.
|
|
20
|
+
* @returns {ReturnType<typeof oidc>} - Returns an object with methods for authorization, token exchange, user info retrieval, and logout.
|
|
21
|
+
*/
|
|
22
|
+
export declare function oidc<ActionType extends ActionTypes = ActionTypes>({ config, requestMiddleware, logger, storage, }: {
|
|
23
|
+
config: OidcConfig;
|
|
24
|
+
requestMiddleware?: RequestMiddleware<ActionType>[];
|
|
25
|
+
logger?: {
|
|
26
|
+
level: LogLevel;
|
|
27
|
+
custom?: CustomLogger;
|
|
28
|
+
};
|
|
29
|
+
storage?: Partial<StorageConfig>;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
error: string;
|
|
32
|
+
type: string;
|
|
33
|
+
/**
|
|
34
|
+
* An object containing methods for the creation, and background use, of the authorization URL
|
|
35
|
+
*/
|
|
36
|
+
authorize?: undefined;
|
|
37
|
+
/**
|
|
38
|
+
* An object containing methods for token exchange
|
|
39
|
+
*/
|
|
40
|
+
token?: undefined;
|
|
41
|
+
/**
|
|
42
|
+
* An object containing methods for user info retrieval and logout
|
|
43
|
+
*/
|
|
44
|
+
user?: undefined;
|
|
45
|
+
} | {
|
|
46
|
+
/**
|
|
47
|
+
* An object containing methods for the creation, and background use, of the authorization URL
|
|
48
|
+
*/
|
|
49
|
+
authorize: {
|
|
50
|
+
/**
|
|
51
|
+
* @method url
|
|
52
|
+
* @description Creates an authorization URL with the provided options or defaults from the configuration.
|
|
53
|
+
* @param {GetAuthorizationUrlOptions} options - Optional parameters to customize the authorization URL.
|
|
54
|
+
* @returns {Promise<string | GenericError>} - Returns a promise that resolves to the authorization URL or an error.
|
|
55
|
+
*/
|
|
56
|
+
url: (options?: GetAuthorizationUrlOptions) => Promise<string | GenericError>;
|
|
57
|
+
/**
|
|
58
|
+
* @function background - Initiates the authorization process in the background, returning an authorization URL or an error.
|
|
59
|
+
* @param {GetAuthorizationUrlOptions} options - Optional parameters to customize the authorization URL.
|
|
60
|
+
* @returns {Promise<AuthorizeErrorResponse | AuthorizeSuccessResponse>} - Returns a promise that resolves to the authorization URL or an error response.
|
|
61
|
+
*/
|
|
62
|
+
background: (options?: GetAuthorizationUrlOptions) => Promise<AuthorizeErrorResponse | AuthorizeSuccessResponse>;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* An object containing methods for token exchange
|
|
66
|
+
*/
|
|
67
|
+
token: {
|
|
68
|
+
/**
|
|
69
|
+
* @method exchange
|
|
70
|
+
* @description Exchanges an authorization code for tokens using the token endpoint from the wellknown
|
|
71
|
+
* configuration and stores them in the configured storage.
|
|
72
|
+
* @param {string} code - The authorization code received from the authorization server.
|
|
73
|
+
* @param {string} state - The state parameter from the authorization URL creation.
|
|
74
|
+
* @param {Partial<StorageConfig>} options - Optional storage configuration for persisting tokens.
|
|
75
|
+
* @returns {Promise<OauthTokens | GenericError | TokenExchangeErrorResponse>}
|
|
76
|
+
*/
|
|
77
|
+
exchange: (code: string, state: string, options?: Partial<StorageConfig>) => Promise<OauthTokens | TokenExchangeErrorResponse | GenericError>;
|
|
78
|
+
/**
|
|
79
|
+
* @method get
|
|
80
|
+
* @description Retrieves the current OAuth tokens from storage, or auto-renew if backgroundRenew is true.
|
|
81
|
+
* @param {GetTokensOptions} param - An object containing options for the token retrieval.
|
|
82
|
+
* @returns {Promise<OauthTokens | TokenExchangeErrorResponse | AuthorizeErrorResponse | GenericError>}
|
|
83
|
+
*/
|
|
84
|
+
get: (options?: GetTokensOptions) => Promise<OauthTokens | TokenExchangeErrorResponse | AuthorizeErrorResponse | GenericError>;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* An object containing methods for user info retrieval and logout
|
|
88
|
+
*/
|
|
89
|
+
user: {
|
|
90
|
+
/**
|
|
91
|
+
* @method info
|
|
92
|
+
* @description Retrieves user information using the userinfo endpoint from the wellknown configuration.
|
|
93
|
+
* It requires an access token stored in the configured storage.
|
|
94
|
+
* @returns {Promise<GenericError | TokenExchangeResponse>} - Returns a promise that resolves to user information or an error response.
|
|
95
|
+
*/
|
|
96
|
+
info: () => Promise<GenericError | TokenExchangeResponse>;
|
|
97
|
+
/**
|
|
98
|
+
* @method logout
|
|
99
|
+
* @description Logs out the user by revoking tokens and clearing the storage.
|
|
100
|
+
* It uses the end session endpoint from the wellknown configuration.
|
|
101
|
+
* @returns {Promise<GenericError | LogoutResult>} - Returns a promise that resolves to the logout response or an error.
|
|
102
|
+
*/
|
|
103
|
+
logout: () => Promise<GenericError | LogoutResult>;
|
|
104
|
+
};
|
|
105
|
+
error?: undefined;
|
|
106
|
+
type?: undefined;
|
|
107
|
+
}>;
|
|
108
|
+
//# sourceMappingURL=client.store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.store.d.ts","sourceRoot":"","sources":["../../../src/lib/client.store.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAsB,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEnF,OAAO,EAAiB,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAUlE,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACxF,OAAO,KAAK,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAErF,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC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