@forgerock/oidc-client 1.2.0 → 1.3.0
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 +22 -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 +18 -0
- package/dist/src/lib/authorize.request.d.ts.map +1 -0
- package/dist/src/lib/authorize.request.js +125 -0
- package/dist/src/lib/authorize.request.js.map +1 -0
- package/dist/src/lib/authorize.request.types.d.ts +50 -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 +35 -0
- package/dist/src/lib/authorize.request.utils.d.ts.map +1 -0
- package/dist/src/lib/authorize.request.utils.js +101 -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 +27 -0
- package/dist/src/lib/authorize.slice.js.map +1 -0
- package/dist/src/lib/client.store.d.ts +115 -0
- package/dist/src/lib/client.store.d.ts.map +1 -0
- package/dist/src/lib/client.store.js +433 -0
- package/dist/src/lib/client.store.js.map +1 -0
- package/dist/src/lib/client.store.utils.d.ts +104 -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 +35 -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 +13 -0
- package/dist/src/lib/logout.request.d.ts.map +1 -0
- package/dist/src/lib/logout.request.js +47 -0
- package/dist/src/lib/logout.request.js.map +1 -0
- package/dist/src/lib/oidc.api.d.ts +33 -0
- package/dist/src/lib/oidc.api.d.ts.map +1 -0
- package/dist/src/lib/oidc.api.js +295 -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 +9 -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 +35 -10
- 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,25 @@
|
|
|
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 = await oidc({
|
|
8
|
+
/* config */
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// Authorize API
|
|
12
|
+
const authResponse = await oidcClient.authorize.background(); // Returns code and state if successful, error if not
|
|
13
|
+
const authUrl = await oidcClient.authorize.url(); // Returns Auth URL or error
|
|
14
|
+
|
|
15
|
+
// Tokens API
|
|
16
|
+
const newTokens = await oidcClient.token.exchange({
|
|
17
|
+
/* code, state */
|
|
18
|
+
}); // Returns new tokens or error
|
|
19
|
+
const existingTokens = await oidcClient.token.get(); // Returns existing tokens or error
|
|
20
|
+
const response = await oidcClient.token.revoke(); // Revokes an access token and returns the response or an error
|
|
21
|
+
|
|
22
|
+
// User API
|
|
23
|
+
const user = await oidcClient.user.info(); // Returns user object or error
|
|
24
|
+
const logoutResponse = await oidcClient.user.logout(); // Logs the user out and returns the response or an error
|
|
25
|
+
```
|
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,18 @@
|
|
|
1
|
+
import { CustomLogger } from '@forgerock/sdk-logger';
|
|
2
|
+
import { Micro } from 'effect';
|
|
3
|
+
import type { ClientStore } from './client.types.js';
|
|
4
|
+
import type { GetAuthorizationUrlOptions, WellKnownResponse } from '@forgerock/sdk-types';
|
|
5
|
+
import type { AuthorizationError, AuthorizationSuccess } from './authorize.request.types.js';
|
|
6
|
+
import type { OidcConfig } from './config.types.js';
|
|
7
|
+
/**
|
|
8
|
+
* @function authorizeµ
|
|
9
|
+
* @description Creates an authorization URL for the OIDC client.
|
|
10
|
+
* @param {WellKnownResponse} wellknown - The well-known configuration for the OIDC server.
|
|
11
|
+
* @param {OidcConfig} config - The OIDC client configuration.
|
|
12
|
+
* @param {CustomLogger} log - The logger instance for logging debug information.
|
|
13
|
+
* @param {ClientStore} store - The Redux store instance for managing OIDC state.
|
|
14
|
+
* @param {GetAuthorizationUrlOptions} options - Optional parameters for the authorization request.
|
|
15
|
+
* @returns {Micro.Micro<AuthorizationSuccess, AuthorizationError, never>} - A micro effect that resolves to the authorization response.
|
|
16
|
+
*/
|
|
17
|
+
export declare function authorizeµ(wellknown: WellKnownResponse, config: OidcConfig, log: CustomLogger, store: ClientStore, options?: GetAuthorizationUrlOptions): Micro.Micro<AuthorizationSuccess, AuthorizationError, never>;
|
|
18
|
+
//# 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;AAS/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAC7F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,WAAW,EAClB,OAAO,CAAC,EAAE,0BAA0B,gEA8IrC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Micro } from 'effect';
|
|
2
|
+
import { createAuthorizeUrlµ, buildAuthorizeOptionsµ, createAuthorizeErrorµ, } from './authorize.request.utils.js';
|
|
3
|
+
import { oidcApi } from './oidc.api.js';
|
|
4
|
+
/**
|
|
5
|
+
* @function authorizeµ
|
|
6
|
+
* @description Creates an authorization URL for the OIDC client.
|
|
7
|
+
* @param {WellKnownResponse} wellknown - The well-known configuration for the OIDC server.
|
|
8
|
+
* @param {OidcConfig} config - The OIDC client configuration.
|
|
9
|
+
* @param {CustomLogger} log - The logger instance for logging debug information.
|
|
10
|
+
* @param {ClientStore} store - The Redux store instance for managing OIDC state.
|
|
11
|
+
* @param {GetAuthorizationUrlOptions} options - Optional parameters for the authorization request.
|
|
12
|
+
* @returns {Micro.Micro<AuthorizationSuccess, AuthorizationError, never>} - A micro effect that resolves to the authorization response.
|
|
13
|
+
*/
|
|
14
|
+
export function authorizeµ(wellknown, config, log, store, options) {
|
|
15
|
+
return buildAuthorizeOptionsµ(wellknown, config, options).pipe(Micro.flatMap(([url, options]) => createAuthorizeUrlµ(url, 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, options]) => {
|
|
16
|
+
if (options.responseMode === 'pi.flow') {
|
|
17
|
+
/**
|
|
18
|
+
* If we support the pi.flow field, this means we are using a PingOne server.
|
|
19
|
+
* PingOne servers do not support redirection through iframes because they
|
|
20
|
+
* set iframe's to DENY.
|
|
21
|
+
*
|
|
22
|
+
* We do not use RTK Query for this because we don't want caching, or store
|
|
23
|
+
* updates, and want the request to be made similar to the iframe method below.
|
|
24
|
+
*
|
|
25
|
+
* This returns a Micro that resolves to the parsed response JSON.
|
|
26
|
+
*/
|
|
27
|
+
return Micro.promise(() => store.dispatch(oidcApi.endpoints.authorizeFetch.initiate({ url }))).pipe(Micro.flatMap(({ error, data }) => {
|
|
28
|
+
if (error) {
|
|
29
|
+
// Check for serialized error
|
|
30
|
+
if (!('status' in error)) {
|
|
31
|
+
// This is a network or fetch error, so return it as-is
|
|
32
|
+
return Micro.fail({
|
|
33
|
+
error: error.code || 'Unknown_Error',
|
|
34
|
+
error_description: error.message || 'An unknown error occurred during authorization',
|
|
35
|
+
type: 'unknown_error',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
// If there is no data, this is an unknown error
|
|
39
|
+
if (!('data' in error)) {
|
|
40
|
+
return Micro.fail({
|
|
41
|
+
error: 'Unknown_Error',
|
|
42
|
+
error_description: 'An unknown error occurred during authorization',
|
|
43
|
+
type: 'unknown_error',
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const errorDetails = error.data;
|
|
47
|
+
// If the error is a configuration issue, return it as-is
|
|
48
|
+
if ('statusText' in error && error.statusText === 'CONFIGURATION_ERROR') {
|
|
49
|
+
return Micro.fail(errorDetails);
|
|
50
|
+
}
|
|
51
|
+
// If the error is not a configuration issue, we build a new Authorize URL
|
|
52
|
+
// For redirection, we need to remove `pi.flow` from the options
|
|
53
|
+
const redirectOptions = options;
|
|
54
|
+
delete redirectOptions.responseMode;
|
|
55
|
+
// Create an error with a new Authorize URL
|
|
56
|
+
return createAuthorizeErrorµ(errorDetails, wellknown, options);
|
|
57
|
+
}
|
|
58
|
+
log.debug('Received success response', data);
|
|
59
|
+
if (data.authorizeResponse) {
|
|
60
|
+
// Authorization was successful
|
|
61
|
+
return Micro.succeed(data.authorizeResponse);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// This should never be reached, but just in case
|
|
65
|
+
return Micro.fail({
|
|
66
|
+
error: 'Unknown_Error',
|
|
67
|
+
error_description: 'Response schema was not recognized',
|
|
68
|
+
type: 'unknown_error',
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
/**
|
|
75
|
+
* If the response mode is not pi.flow, then we are likely using a traditional
|
|
76
|
+
* redirect based server supporting iframes. An example would be PingAM.
|
|
77
|
+
*
|
|
78
|
+
* This returns a Micro that's either the success URL parameters or error URL
|
|
79
|
+
* parameters.
|
|
80
|
+
*/
|
|
81
|
+
return Micro.promise(() => store.dispatch(oidcApi.endpoints.authorizeIframe.initiate({ url }))).pipe(Micro.flatMap(({ error, data }) => {
|
|
82
|
+
if (error) {
|
|
83
|
+
// Check for serialized error
|
|
84
|
+
if (!('status' in error)) {
|
|
85
|
+
// This is a network or fetch error, so return it as-is
|
|
86
|
+
return Micro.fail({
|
|
87
|
+
error: error.code || 'Unknown_Error',
|
|
88
|
+
error_description: error.message || 'An unknown error occurred during authorization',
|
|
89
|
+
type: 'unknown_error',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
// If there is no data, this is an unknown error
|
|
93
|
+
if (!('data' in error)) {
|
|
94
|
+
return Micro.fail({
|
|
95
|
+
error: 'Unknown_Error',
|
|
96
|
+
error_description: 'An unknown error occurred during authorization',
|
|
97
|
+
type: 'unknown_error',
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const errorDetails = error.data;
|
|
101
|
+
// If the error is a configuration issue, return it as-is
|
|
102
|
+
if ('statusText' in error && error.statusText === 'CONFIGURATION_ERROR') {
|
|
103
|
+
return Micro.fail(errorDetails);
|
|
104
|
+
}
|
|
105
|
+
// This is an expected error, so combine error with a new Authorize URL
|
|
106
|
+
return createAuthorizeErrorµ(errorDetails, wellknown, options);
|
|
107
|
+
}
|
|
108
|
+
log.debug('Received success response', data);
|
|
109
|
+
if (data) {
|
|
110
|
+
// Authorization was successful
|
|
111
|
+
return Micro.succeed(data);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
// This should never be reached, but just in case
|
|
115
|
+
return Micro.fail({
|
|
116
|
+
error: 'Unknown_Error',
|
|
117
|
+
error_description: 'Redirect parameters was not recognized',
|
|
118
|
+
type: 'unknown_error',
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
//# 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,CA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AAC,KAAK,CAAC,2BAA2B,EAAE,IAAI,CAAC,CAAC;gBAE7C,IAAI,IAAI,EAAE,CAAC;oBACT,+BAA+B;oBAC/B,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBAC7B,CAAC;qBAAM,CAAC;oBACN,iDAAiD;oBACjD,OAAO,KAAK,CAAC,IAAI,CAAC;wBAChB,KAAK,EAAE,eAAe;wBACtB,iBAAiB,EAAE,wCAAwC;wBAC3D,IAAI,EAAE,eAAe;qBACtB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CACF,CACF,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { GetAuthorizationUrlOptions } from '@forgerock/sdk-types';
|
|
2
|
+
export type BuildAuthorizationData = [string, GetAuthorizationUrlOptions];
|
|
3
|
+
export type OptionalAuthorizeOptions = Partial<GetAuthorizationUrlOptions>;
|
|
4
|
+
export interface AuthorizeErrorResponse {
|
|
5
|
+
id?: string;
|
|
6
|
+
code?: string;
|
|
7
|
+
message?: string;
|
|
8
|
+
details?: [
|
|
9
|
+
{
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
];
|
|
14
|
+
}
|
|
15
|
+
export interface AuthorizeSuccessResponse {
|
|
16
|
+
_links?: {
|
|
17
|
+
[key: string]: {
|
|
18
|
+
href: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
_embedded?: {
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
id?: string;
|
|
25
|
+
environment?: {
|
|
26
|
+
id: string;
|
|
27
|
+
};
|
|
28
|
+
session?: {
|
|
29
|
+
id: string;
|
|
30
|
+
};
|
|
31
|
+
resumeUrl?: string;
|
|
32
|
+
status?: string;
|
|
33
|
+
createdAt?: string;
|
|
34
|
+
expiresAt?: string;
|
|
35
|
+
authorizeResponse?: {
|
|
36
|
+
code: string;
|
|
37
|
+
state: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface AuthorizationSuccess {
|
|
41
|
+
code: string;
|
|
42
|
+
state: string;
|
|
43
|
+
}
|
|
44
|
+
export interface AuthorizationError {
|
|
45
|
+
error: string;
|
|
46
|
+
error_description: string;
|
|
47
|
+
redirectUrl?: string;
|
|
48
|
+
type: 'auth_error' | 'argument_error' | 'network_error' | 'unknown_error' | 'wellknown_error';
|
|
49
|
+
}
|
|
50
|
+
//# 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,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAEvE,MAAM,MAAM,sBAAsB,GAAG,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;AAC1E,MAAM,MAAM,wBAAwB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAC3E,MAAM,WAAW,sBAAsB;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE;QACR;YACE,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;SACjB;KACF,CAAC;CACH;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,CAAC,EAAE;QACP,CAAC,GAAG,EAAE,MAAM,GAAG;YACb,IAAI,EAAE,MAAM,CAAC;SACd,CAAC;KACH,CAAC;IACF,SAAS,CAAC,EAAE;QACV,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;IACF,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE;QACZ,EAAE,EAAE,MAAM,CAAC;KACZ,CAAC;IACF,OAAO,CAAC,EAAE;QACR,EAAE,EAAE,MAAM,CAAC;KACZ,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,YAAY,GAAG,gBAAgB,GAAG,eAAe,GAAG,eAAe,GAAG,iBAAiB,CAAC;CAC/F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.request.types.js","sourceRoot":"","sources":["../../../src/lib/authorize.request.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Micro } from 'effect';
|
|
2
|
+
import type { WellKnownResponse, GetAuthorizationUrlOptions } from '@forgerock/sdk-types';
|
|
3
|
+
import type { AuthorizationError, AuthorizationSuccess, BuildAuthorizationData, OptionalAuthorizeOptions } from './authorize.request.types.js';
|
|
4
|
+
import type { OidcConfig } from './config.types.js';
|
|
5
|
+
/**
|
|
6
|
+
* @function buildAuthorizeOptionsµ
|
|
7
|
+
* @description Builds the authorization options for the OIDC client.
|
|
8
|
+
* @param {WellKnownResponse} wellknown - The well-known configuration for the OIDC server.
|
|
9
|
+
* @param {OptionalAuthorizeOptions} options - Optional parameters for the authorization request.
|
|
10
|
+
* @returns {Micro.Micro<BuildAuthorizationData, AuthorizationError, never>}
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildAuthorizeOptionsµ(wellknown: WellKnownResponse, config: OidcConfig, options?: OptionalAuthorizeOptions): Micro.Micro<BuildAuthorizationData, AuthorizationError, never>;
|
|
13
|
+
/**
|
|
14
|
+
* @function createAuthorizeErrorµ
|
|
15
|
+
* @description Creates an error response with new Authorize URL for the authorization request.
|
|
16
|
+
* @param { error: string; error_description: string } res - The error response from the authorization request.
|
|
17
|
+
* @param {WellKnownResponse} wellknown- The well-known configuration for the OIDC server.
|
|
18
|
+
* @param { OidcConfig } config- The OIDC client configuration.
|
|
19
|
+
* @param { GetAuthorizationUrlOptions } options- Optional parameters for the authorization request.
|
|
20
|
+
* @returns { Micro.Micro<never, AuthorizationError, never> }
|
|
21
|
+
*/
|
|
22
|
+
export declare function createAuthorizeErrorµ(res: {
|
|
23
|
+
error: string;
|
|
24
|
+
error_description: string;
|
|
25
|
+
}, wellknown: WellKnownResponse, options: GetAuthorizationUrlOptions): Micro.Micro<never, AuthorizationError, never>;
|
|
26
|
+
/**
|
|
27
|
+
* @function createAuthorizeUrlµ
|
|
28
|
+
* @description Creates an authorization URL and related options/config for the Authorize request.
|
|
29
|
+
* @param {string} path - The path to the authorization endpoint.
|
|
30
|
+
* @param { GetAuthorizationUrlOptions } options - Optional parameters for the authorization request.
|
|
31
|
+
* @returns { Micro.Micro<[string, GetAuthorizationUrlOptions], AuthorizationError, never> }
|
|
32
|
+
*/
|
|
33
|
+
export declare function createAuthorizeUrlµ(path: string, options: GetAuthorizationUrlOptions): Micro.Micro<[string, GetAuthorizationUrlOptions], AuthorizationError, never>;
|
|
34
|
+
export declare function handleResponseµ(response: AuthorizationSuccess | AuthorizationError, wellknown: WellKnownResponse, options: GetAuthorizationUrlOptions): Micro.Micro<AuthorizationSuccess, AuthorizationError, never>;
|
|
35
|
+
//# sourceMappingURL=authorize.request.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize.request.utils.d.ts","sourceRoot":"","sources":["../../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) 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
|
+
/**
|
|
10
|
+
* @function buildAuthorizeOptionsµ
|
|
11
|
+
* @description Builds the authorization options for the OIDC client.
|
|
12
|
+
* @param {WellKnownResponse} wellknown - The well-known configuration for the OIDC server.
|
|
13
|
+
* @param {OptionalAuthorizeOptions} options - Optional parameters for the authorization request.
|
|
14
|
+
* @returns {Micro.Micro<BuildAuthorizationData, AuthorizationError, never>}
|
|
15
|
+
*/
|
|
16
|
+
export function buildAuthorizeOptionsµ(wellknown, config, options) {
|
|
17
|
+
const isPiFlow = wellknown.response_modes_supported?.includes('pi.flow');
|
|
18
|
+
return Micro.sync(() => [
|
|
19
|
+
wellknown.authorization_endpoint,
|
|
20
|
+
{
|
|
21
|
+
clientId: config.clientId,
|
|
22
|
+
redirectUri: config.redirectUri,
|
|
23
|
+
scope: config.scope || 'openid',
|
|
24
|
+
responseType: config.responseType || 'code',
|
|
25
|
+
...(isPiFlow && { responseMode: 'pi.flow' }),
|
|
26
|
+
...options,
|
|
27
|
+
},
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @function createAuthorizeErrorµ
|
|
32
|
+
* @description Creates an error response with new Authorize URL for the authorization request.
|
|
33
|
+
* @param { error: string; error_description: string } res - The error response from the authorization request.
|
|
34
|
+
* @param {WellKnownResponse} wellknown- The well-known configuration for the OIDC server.
|
|
35
|
+
* @param { OidcConfig } config- The OIDC client configuration.
|
|
36
|
+
* @param { GetAuthorizationUrlOptions } options- Optional parameters for the authorization request.
|
|
37
|
+
* @returns { Micro.Micro<never, AuthorizationError, never> }
|
|
38
|
+
*/
|
|
39
|
+
export function createAuthorizeErrorµ(res, wellknown, options) {
|
|
40
|
+
return Micro.tryPromise({
|
|
41
|
+
try: () => createAuthorizeUrl(wellknown.authorization_endpoint, {
|
|
42
|
+
...options,
|
|
43
|
+
}),
|
|
44
|
+
catch: (error) => {
|
|
45
|
+
let message = 'Error creating authorization URL';
|
|
46
|
+
if (error instanceof Error) {
|
|
47
|
+
message = error.message;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
error: 'AuthorizationUrlError',
|
|
51
|
+
error_description: message,
|
|
52
|
+
type: 'auth_error',
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
}).pipe(Micro.flatMap((url) => {
|
|
56
|
+
return Micro.fail({
|
|
57
|
+
error: res.error,
|
|
58
|
+
error_description: res.error_description,
|
|
59
|
+
type: 'auth_error',
|
|
60
|
+
redirectUrl: url,
|
|
61
|
+
});
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @function createAuthorizeUrlµ
|
|
66
|
+
* @description Creates an authorization URL and related options/config for the Authorize request.
|
|
67
|
+
* @param {string} path - The path to the authorization endpoint.
|
|
68
|
+
* @param { GetAuthorizationUrlOptions } options - Optional parameters for the authorization request.
|
|
69
|
+
* @returns { Micro.Micro<[string, GetAuthorizationUrlOptions], AuthorizationError, never> }
|
|
70
|
+
*/
|
|
71
|
+
export function createAuthorizeUrlµ(path, options) {
|
|
72
|
+
return Micro.tryPromise({
|
|
73
|
+
try: async () => [
|
|
74
|
+
await createAuthorizeUrl(path, {
|
|
75
|
+
...options,
|
|
76
|
+
prompt: 'none',
|
|
77
|
+
}),
|
|
78
|
+
options,
|
|
79
|
+
],
|
|
80
|
+
catch: (error) => {
|
|
81
|
+
let message = 'Error creating authorization URL';
|
|
82
|
+
if (error instanceof Error) {
|
|
83
|
+
message = error.message;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
error: 'AuthorizationUrlError',
|
|
87
|
+
error_description: message,
|
|
88
|
+
type: 'auth_error',
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
export function handleResponseµ(response, wellknown, options) {
|
|
94
|
+
if ('code' in response) {
|
|
95
|
+
return Micro.sync(() => response);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
return createAuthorizeErrorµ(response, wellknown, options);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# 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;AAW/B;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CACpC,SAA4B,EAC5B,MAAkB,EAClB,OAAkC;IAElC,MAAM,QAAQ,GAAG,SAAS,CAAC,wBAAwB,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IACzE,OAAO,KAAK,CAAC,IAAI,CACf,GAA2B,EAAE,CAAC;QAC5B,SAAS,CAAC,sBAAsB;QAChC;YACE,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,QAAQ;YAC/B,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,MAAM;YAC3C,GAAG,CAAC,QAAQ,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;YAC5C,GAAG,OAAO;SACX;KACF,CACF,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CACnC,GAAiD,EACjD,SAA4B,EAC5B,OAAmC;IAEnC,OAAO,KAAK,CAAC,UAAU,CAAC;QACtB,GAAG,EAAE,GAAG,EAAE,CACR,kBAAkB,CAAC,SAAS,C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,CAC7B,QAAmD,EACnD,SAA4B,EAC5B,OAAmC;IAEnC,IAAI,MAAM,IAAI,QAAQ,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;SAAM,CAAC;QACN,OAAO,qBAAqB,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;AACH,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":"AAQA,QAAA,MAAM,cAAc;;mFAkBlB,CAAC;AAEH,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query';
|
|
8
|
+
const authorizeSlice = createApi({
|
|
9
|
+
reducerPath: 'authorizeSlice',
|
|
10
|
+
baseQuery: fetchBaseQuery({
|
|
11
|
+
credentials: 'include',
|
|
12
|
+
prepareHeaders: (headers) => {
|
|
13
|
+
headers.set('Content-Type', 'application/json');
|
|
14
|
+
headers.set('Accept', 'application/json');
|
|
15
|
+
headers.set('x-requested-with', 'ping-sdk');
|
|
16
|
+
headers.set('x-requested-platform', 'javascript');
|
|
17
|
+
return headers;
|
|
18
|
+
},
|
|
19
|
+
}),
|
|
20
|
+
endpoints: (builder) => ({
|
|
21
|
+
handleAuthorize: builder.query({
|
|
22
|
+
query: (authorizeUrl) => authorizeUrl,
|
|
23
|
+
}),
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
export { authorizeSlice };
|
|
27
|
+
//# 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;;;;;GAKG;AACH,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,115 @@
|
|
|
1
|
+
import type { ActionTypes, RequestMiddleware } from '@forgerock/sdk-request-middleware';
|
|
2
|
+
import type { GenericError, GetAuthorizationUrlOptions } from '@forgerock/sdk-types';
|
|
3
|
+
import type { CustomLogger, LogLevel } from '@forgerock/sdk-logger';
|
|
4
|
+
import type { StorageConfig } from '@forgerock/storage';
|
|
5
|
+
import type { GetTokensOptions, LogoutErrorResult, LogoutSuccessResult, RevokeErrorResult, RevokeSuccessResult, UserInfoResponse } from './client.types.js';
|
|
6
|
+
import type { OauthTokens, OidcConfig } from './config.types.js';
|
|
7
|
+
import type { AuthorizationError, AuthorizationSuccess } from './authorize.request.types.js';
|
|
8
|
+
import type { TokenExchangeErrorResponse } 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 management
|
|
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<AuthorizationSuccess | AuthorizationError>;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* An object containing methods for token management
|
|
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 | AuthorizationError | GenericError>}
|
|
83
|
+
*/
|
|
84
|
+
get: (options?: GetTokensOptions) => Promise<OauthTokens | TokenExchangeErrorResponse | AuthorizationError | GenericError>;
|
|
85
|
+
/**
|
|
86
|
+
* @method revoke
|
|
87
|
+
* @description Revokes an access token using the revocation endpoint from the wellknown configuration.
|
|
88
|
+
* It requires an access token stored in the configured storage.
|
|
89
|
+
* @returns {Promise<GenericError | RevokeSuccessResult | RevokeErrorResult>} - Returns a promise that resolves to the revoke response or an error response.
|
|
90
|
+
*/
|
|
91
|
+
revoke: () => Promise<GenericError | RevokeSuccessResult | RevokeErrorResult>;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* An object containing methods for user info retrieval and logout
|
|
95
|
+
*/
|
|
96
|
+
user: {
|
|
97
|
+
/**
|
|
98
|
+
* @method info
|
|
99
|
+
* @description Retrieves user information using the userinfo endpoint from the wellknown configuration.
|
|
100
|
+
* It requires an access token stored in the configured storage.
|
|
101
|
+
* @returns {Promise<GenericError | UserInfoResponse>} - Returns a promise that resolves to user information or an error response.
|
|
102
|
+
*/
|
|
103
|
+
info: () => Promise<GenericError | UserInfoResponse>;
|
|
104
|
+
/**
|
|
105
|
+
* @method logout
|
|
106
|
+
* @description Logs out the user by revoking tokens and clearing the storage.
|
|
107
|
+
* It uses the end session endpoint from the wellknown configuration.
|
|
108
|
+
* @returns {Promise<GenericError | LogoutSuccessResult | LogoutErrorResult>} - Returns a promise that resolves to the logout response or an error.
|
|
109
|
+
*/
|
|
110
|
+
logout: () => Promise<GenericError | LogoutSuccessResult | LogoutErrorResult>;
|
|
111
|
+
};
|
|
112
|
+
error?: undefined;
|
|
113
|
+
type?: undefined;
|
|
114
|
+
}>;
|
|
115
|
+
//# 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":"AAkBA,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACxF,OAAO,KAAK,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,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