@forgerock/oidc-client 1.2.0 → 2.0.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.
Files changed (92) hide show
  1. package/README.md +294 -2
  2. package/dist/src/index.d.ts +1 -1
  3. package/dist/src/index.d.ts.map +1 -1
  4. package/dist/src/index.js +8 -1
  5. package/dist/src/index.js.map +1 -0
  6. package/dist/src/lib/authorize.request.d.ts +18 -0
  7. package/dist/src/lib/authorize.request.d.ts.map +1 -0
  8. package/dist/src/lib/authorize.request.js +125 -0
  9. package/dist/src/lib/authorize.request.js.map +1 -0
  10. package/dist/src/lib/authorize.request.types.d.ts +50 -0
  11. package/dist/src/lib/authorize.request.types.d.ts.map +1 -0
  12. package/dist/src/lib/authorize.request.types.js +2 -0
  13. package/dist/src/lib/authorize.request.types.js.map +1 -0
  14. package/dist/src/lib/authorize.request.utils.d.ts +35 -0
  15. package/dist/src/lib/authorize.request.utils.d.ts.map +1 -0
  16. package/dist/src/lib/authorize.request.utils.js +101 -0
  17. package/dist/src/lib/authorize.request.utils.js.map +1 -0
  18. package/dist/src/lib/authorize.slice.d.ts +5 -0
  19. package/dist/src/lib/authorize.slice.d.ts.map +1 -0
  20. package/dist/src/lib/authorize.slice.js +27 -0
  21. package/dist/src/lib/authorize.slice.js.map +1 -0
  22. package/dist/src/lib/client.store.d.ts +115 -0
  23. package/dist/src/lib/client.store.d.ts.map +1 -0
  24. package/dist/src/lib/client.store.js +435 -0
  25. package/dist/src/lib/client.store.js.map +1 -0
  26. package/dist/src/lib/client.store.utils.d.ts +104 -0
  27. package/dist/src/lib/client.store.utils.d.ts.map +1 -0
  28. package/dist/src/lib/client.store.utils.js +92 -0
  29. package/dist/src/lib/client.store.utils.js.map +1 -0
  30. package/dist/src/lib/client.types.d.ts +37 -0
  31. package/dist/src/lib/client.types.d.ts.map +1 -0
  32. package/dist/src/lib/client.types.js +2 -0
  33. package/dist/src/lib/client.types.js.map +1 -0
  34. package/dist/src/lib/config.types.d.ts +19 -0
  35. package/dist/src/lib/config.types.d.ts.map +1 -0
  36. package/dist/src/lib/config.types.js +2 -0
  37. package/dist/src/lib/config.types.js.map +1 -0
  38. package/dist/src/lib/exchange.request.d.ts +18 -0
  39. package/dist/src/lib/exchange.request.d.ts.map +1 -0
  40. package/dist/src/lib/exchange.request.js +22 -0
  41. package/dist/src/lib/exchange.request.js.map +1 -0
  42. package/dist/src/lib/exchange.types.d.ts +21 -0
  43. package/dist/src/lib/exchange.types.d.ts.map +1 -0
  44. package/dist/src/lib/exchange.types.js +2 -0
  45. package/dist/src/lib/exchange.types.js.map +1 -0
  46. package/dist/src/lib/exchange.utils.d.ts +28 -0
  47. package/dist/src/lib/exchange.utils.d.ts.map +1 -0
  48. package/dist/src/lib/exchange.utils.js +55 -0
  49. package/dist/src/lib/exchange.utils.js.map +1 -0
  50. package/dist/src/lib/logout.request.d.ts +13 -0
  51. package/dist/src/lib/logout.request.d.ts.map +1 -0
  52. package/dist/src/lib/logout.request.js +47 -0
  53. package/dist/src/lib/logout.request.js.map +1 -0
  54. package/dist/src/lib/oidc.api.d.ts +33 -0
  55. package/dist/src/lib/oidc.api.d.ts.map +1 -0
  56. package/dist/src/lib/oidc.api.js +295 -0
  57. package/dist/src/lib/oidc.api.js.map +1 -0
  58. package/dist/src/lib/oidc.api.utils.d.ts +3 -0
  59. package/dist/src/lib/oidc.api.utils.d.ts.map +1 -0
  60. package/dist/src/lib/oidc.api.utils.js +9 -0
  61. package/dist/src/lib/oidc.api.utils.js.map +1 -0
  62. package/dist/src/lib/token.utils.d.ts +2 -0
  63. package/dist/src/lib/token.utils.d.ts.map +1 -0
  64. package/dist/src/lib/token.utils.js +15 -0
  65. package/dist/src/lib/token.utils.js.map +1 -0
  66. package/dist/src/lib/wellknown.api.d.ts +236 -0
  67. package/dist/src/lib/wellknown.api.d.ts.map +1 -0
  68. package/dist/src/lib/wellknown.api.js +55 -0
  69. package/dist/src/lib/wellknown.api.js.map +1 -0
  70. package/dist/src/types.d.ts +9 -0
  71. package/dist/src/types.d.ts.map +1 -0
  72. package/dist/src/types.js +10 -0
  73. package/dist/src/types.js.map +1 -0
  74. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  75. package/package.json +35 -10
  76. package/CHANGELOG.md +0 -11
  77. package/dist/src/lib/token-store.d.ts +0 -12
  78. package/dist/src/lib/token-store.d.ts.map +0 -1
  79. package/dist/src/lib/token-store.js +0 -9
  80. package/dist/src/lib/token-store.test-d.d.ts +0 -2
  81. package/dist/src/lib/token-store.test-d.d.ts.map +0 -1
  82. package/dist/src/lib/token-store.test-d.js +0 -43
  83. package/eslint.config.mjs +0 -22
  84. package/src/index.ts +0 -1
  85. package/src/lib/token-store.test-d.ts +0 -52
  86. package/src/lib/token-store.test.ts +0 -38
  87. package/src/lib/token-store.ts +0 -10
  88. package/tsconfig.json +0 -22
  89. package/tsconfig.lib.json +0 -40
  90. package/tsconfig.spec.json +0 -41
  91. package/typedoc.json +0 -4
  92. package/vite.config.ts +0 -23
package/README.md CHANGED
@@ -1,3 +1,295 @@
1
- # oidc-client
1
+ # OIDC Client
2
2
 
3
- A generic OpenID Connect (OIDC) client library for JavaScript and TypeScript, designed to work with any OIDC-compliant identity provider.
3
+ A generic OpenID Connect (OIDC) client library for JavaScript and TypeScript, designed to work with PingOne platforms.
4
+
5
+ The oidc module follows the [OIDC](https://openid.net/specs/openid-connect-core-1_0.html) specification and provides a simple and easy-to-use API to interact with the OIDC server. It allows you to authenticate, retrieve the access token, revoke the token, and sign out from the OIDC server.
6
+
7
+ ## Table of Contents
8
+
9
+ - [Installation](#installation)
10
+ - [Initialization](#initialization)
11
+ - [Configuration Options](#configuration-options)
12
+ - [Quick Start](#quick-start)
13
+ - [API Reference](#api-reference)
14
+ - [authorize](#authorize)
15
+ - [token](#token)
16
+ - [user](#user)
17
+ - [Usage Examples](#usage-examples)
18
+ - [Redirect-Based Login](#redirect-based-login-authorizeurl)
19
+ - [Background Authorization](#background-authorization-authorizebackground)
20
+ - [Automatic Token Renewal](#automatic-token-renewal)
21
+ - [Error Handling](#error-handling)
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pnpm add @forgerock/oidc-client
27
+ # or
28
+ npm install @forgerock/oidc-client
29
+ # or
30
+ yarn add @forgerock/oidc-client
31
+ ```
32
+
33
+ ## Initialization
34
+
35
+ ```typescript
36
+ import { oidc } from '@forgerock/oidc-client';
37
+ import { OidcConfig, OidcClient } from '@forgerock/oidc-client/types';
38
+
39
+ const config: OidcConfig = {
40
+ serverConfig: { wellknown: 'https://example.com/.well-known/openid-configuration' },
41
+ clientId: 'example-client-id',
42
+ redirectUri: 'https://example-app/redirect-uri',
43
+ scope: 'openid profile email',
44
+ };
45
+
46
+ const oidcClient: OidcClient = await oidc({ config });
47
+ ```
48
+
49
+ ### Configuration Options
50
+
51
+ The `oidc()` initialization function accepts the following configuration:
52
+
53
+ - **serverConfig** (required)
54
+ - **wellknown** (required) - URL to the OIDC provider's well-known configuration endpoint
55
+ - **clientId** (required) - Your application's client ID registered with the OIDC provider
56
+ - **redirectUri** (required) - The URI where the OIDC provider will redirect after authentication
57
+ - **scope** (required) - Space-separated list of requested scopes (e.g., `'openid profile email'`)
58
+ - **storage** (optional) - Storage configuration for tokens (defaults to localStorage)
59
+ - **timeout** (optional) - Request timeout in milliseconds
60
+ - **additionalParameters** (optional) - Additional parameters to include in authorization requests
61
+
62
+ ## Quick Start
63
+
64
+ Here's a minimal example to get started:
65
+
66
+ ```js
67
+ import { oidc } from '@forgerock/oidc-client';
68
+
69
+ // Initialize the client
70
+ const oidcClient = await oidc({ config });
71
+
72
+ // Start authorization in the background
73
+ const authResponse = await oidcClient.authorize.background();
74
+
75
+ // Get tokens
76
+ const tokens = await oidcClient.token.exchange(authResponse.code, authResponse.state);
77
+
78
+ // Get user information
79
+ const user = await oidcClient.user.info();
80
+
81
+ // Clean up: logout and revoke tokens
82
+ await oidcClient.user.logout();
83
+ ```
84
+
85
+ ## API Reference
86
+
87
+ ### authorize
88
+
89
+ Methods for creating and handling authorization flows.
90
+
91
+ #### `authorize.url(options?)`
92
+
93
+ Creates an authorization URL with the provided options or defaults from the configuration.
94
+
95
+ - **Parameters**: `GetAuthorizationUrlOptions` (optional)
96
+ - **Returns**: `Promise<string | GenericError>` - The authorization URL or an error
97
+
98
+ ```js
99
+ const authUrl = await oidcClient.authorize.url();
100
+ ```
101
+
102
+ #### `authorize.background(options?)`
103
+
104
+ Initiates the authorization process in the background, returning the authorization code and state or an error. This method handles the authorization flow without requiring user interaction.
105
+
106
+ - **Parameters**: `GetAuthorizationUrlOptions` (optional)
107
+ - **Returns**: `Promise<AuthorizationSuccess | AuthorizationError>` - An object containing `code` and `state` on success, or error details on failure
108
+
109
+ ```js
110
+ const authResponse = await oidcClient.authorize.background();
111
+ ```
112
+
113
+ ### token
114
+
115
+ Methods for managing OAuth tokens.
116
+
117
+ #### `token.exchange(code, state, options?)`
118
+
119
+ Exchanges an authorization code for tokens using the token endpoint from the wellknown configuration. The tokens are automatically stored in the configured storage.
120
+
121
+ - **Parameters**:
122
+ - `code` (string) - The authorization code received from the authorization server
123
+ - `state` (string) - The state parameter from the authorization URL creation
124
+ - `options` (`Partial<StorageConfig>`, optional) - Storage configuration for persisting tokens
125
+ - **Returns**: `Promise<OauthTokens | TokenExchangeErrorResponse | GenericError>` - The new tokens or an error
126
+
127
+ ```js
128
+ const tokens = await oidcClient.token.exchange(authCode, authState);
129
+ ```
130
+
131
+ #### `token.get(options?)`
132
+
133
+ Retrieves the current OAuth tokens from storage. Optionally auto-renews tokens if they are expired or if `backgroundRenew` is enabled.
134
+
135
+ - **Parameters**: `GetTokensOptions` (optional)
136
+ - `forceRenew` - Force token renewal even if not expired
137
+ - `backgroundRenew` - Automatically renew expired tokens
138
+ - `authorizeOptions` - Options for authorization during renewal
139
+ - `storageOptions` - Storage configuration options
140
+ - **Returns**: `Promise<OauthTokens | TokenExchangeErrorResponse | AuthorizationError | GenericError>` - The tokens or an error
141
+
142
+ ```js
143
+ const tokens = await oidcClient.token.get();
144
+ ```
145
+
146
+ #### `token.revoke()`
147
+
148
+ Revokes the access token using the revocation endpoint from the wellknown configuration. Requires an access token stored in the configured storage.
149
+
150
+ - **Parameters**: None
151
+ - **Returns**: `Promise<GenericError | RevokeSuccessResult | RevokeErrorResult>` - Confirmation of revocation or an error
152
+
153
+ ```js
154
+ const response = await oidcClient.token.revoke();
155
+ ```
156
+
157
+ ### user
158
+
159
+ Methods for user information and session management.
160
+
161
+ #### `user.info()`
162
+
163
+ Retrieves user information using the userinfo endpoint from the wellknown configuration. Requires an access token stored in the configured storage.
164
+
165
+ - **Parameters**: None
166
+ - **Returns**: `Promise<GenericError | UserInfoResponse>` - User information object or an error
167
+
168
+ ```js
169
+ const user = await oidcClient.user.info();
170
+ ```
171
+
172
+ #### `user.logout()`
173
+
174
+ Logs out the user by revoking tokens and clearing the storage. Uses the end session endpoint from the wellknown configuration.
175
+
176
+ - **Parameters**: None
177
+ - **Returns**: `Promise<GenericError | LogoutSuccessResult | LogoutErrorResult>` - Confirmation of logout or an error
178
+
179
+ ```js
180
+ const logoutResponse = await oidcClient.user.logout();
181
+ ```
182
+
183
+ ## Usage Examples
184
+
185
+ ### Redirect-Based Login (`authorize.url()`)
186
+
187
+ Here's a practical example of implementing a redirect-based authentication flow. The user is redirected to the OIDC provider's login page:
188
+
189
+ ```js
190
+ import { oidc } from '@forgerock/oidc-client';
191
+
192
+ // 1. Initialize the client
193
+ const oidcClient = await oidc({ config });
194
+
195
+ // 2. Generate authorization URL and redirect user to OIDC provider
196
+ const authUrl = await oidcClient.authorize.url();
197
+ if (typeof authUrl !== 'string' && 'error' in authUrl) {
198
+ console.error('Failed to generate authorization URL:', authUrl.error);
199
+ } else {
200
+ // Redirect to OIDC provider's login page
201
+ window.location.assign(authUrl);
202
+ }
203
+
204
+ // After user logs in and is redirected back to your app with authorization code
205
+ // 3. Exchange authorization code for tokens
206
+ const urlParams = new URLSearchParams(window.location.search);
207
+ const code = urlParams.get('code');
208
+ const state = urlParams.get('state');
209
+
210
+ const tokens = await oidcClient.token.exchange(code, state);
211
+ if ('error' in tokens) {
212
+ console.error('Failed to exchange code for tokens:', tokens.error);
213
+ }
214
+
215
+ // 4. Retrieve user information
216
+ const userInfo = await oidcClient.user.info();
217
+ if ('error' in userInfo) {
218
+ console.error('Failed to fetch user info:', userInfo.error);
219
+ }
220
+
221
+ // 5. Later, when user wants to logout
222
+ const logoutResult = await oidcClient.user.logout();
223
+ if ('error' in logoutResult) {
224
+ console.error('Logout failed:', logoutResult.error);
225
+ }
226
+ ```
227
+
228
+ ### Background Authorization (`authorize.background()`)
229
+
230
+ Here's an example of initiating the authorization process in the background without user interaction. This method returns the authorization code and state directly:
231
+
232
+ ```js
233
+ import { oidc } from '@forgerock/oidc-client';
234
+
235
+ // 1. Initialize the client
236
+ const oidcClient = await oidc({ config });
237
+
238
+ // 2. Start authorization in the background
239
+ const authResponse = await oidcClient.authorize.background();
240
+ if ('error' in authResponse) {
241
+ console.error('Background authorization failed:', authResponse.error);
242
+ } else {
243
+ // 3. Exchange the authorization code for tokens
244
+ const tokens = await oidcClient.token.exchange(authResponse.code, authResponse.state);
245
+ if ('error' in tokens) {
246
+ console.error('Failed to exchange code for tokens:', tokens.error);
247
+ }
248
+
249
+ // 4. Retrieve user information
250
+ const userInfo = await oidcClient.user.info();
251
+ if ('error' in userInfo) {
252
+ console.error('Failed to fetch user info:', userInfo.error);
253
+ }
254
+
255
+ // 5. Later, when user wants to logout
256
+ const logoutResult = await oidcClient.user.logout();
257
+ if ('error' in logoutResult) {
258
+ console.error('Logout failed:', logoutResult.error);
259
+ }
260
+ }
261
+ ```
262
+
263
+ ### Automatic Token Renewal
264
+
265
+ Use automatic token renewal to keep the user's session valid. With the `backgroundRenew` option, this will either return valid tokens from storage if they exist or fetch new tokens if they are expired.
266
+
267
+ ```js
268
+ // Get tokens with automatic renewal if expired
269
+ const tokens = await oidcClient.token.get({
270
+ backgroundRenew: true,
271
+ });
272
+
273
+ if ('error' in tokens) {
274
+ console.error('Failed to retrieve tokens:', tokens.error);
275
+ } else {
276
+ console.log('Access token:', tokens.access_token);
277
+ }
278
+ ```
279
+
280
+ ### Error Handling
281
+
282
+ The library uses a consistent error handling pattern. All methods return either a success response or an error object. Check if the response contains an `error` property:
283
+
284
+ ```js
285
+ // Pattern for handling responses
286
+ const result = await oidcClient.user.info();
287
+ if ('error' in result) {
288
+ // Handle error case
289
+ console.error('Error:', result.error);
290
+ console.error('Error description:', result.error_description);
291
+ } else {
292
+ // Handle success case
293
+ console.log('User:', result);
294
+ }
295
+ ```
@@ -1,2 +1,2 @@
1
- export * from './lib/token-store.js';
1
+ export * from './lib/client.store.js';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
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
- export * from './lib/token-store.js';
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,CAAC;AAE/B,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAOxC;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CACxB,SAA4B,EAC5B,MAAkB,EAClB,GAAiB,EACjB,KAAkB,EAClB,OAAoC;IAEpC,OAAO,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAC5D,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,EACpE,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,CACX,CAAC,CAAC,G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AC,IAAI,CAAC;4BAChB,KAAK,EAAE,eAAe;4BACtB,iBAAiB,EAAE,gDAAgD;4BACnE,IAAI,EAAE,eAAe;yBACtB,CAAC,CAAC;oBACL,CAAC;oBAED,MAAM,YAAY,GAAG,KAAK,CAAC,IAA0B,CAAC;oBAEtD,yDAAyD;oBACzD,IAAI,YAAY,IAAI,KAAK,IAAI,KAAK,CAAC,UAAU,KAAK,qBAAqB,EAAE,CAAC;wBACxE,OAAO,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;oBAClC,CAAC;oBAED,uEAAuE;oBACvE,OAAO,qBAAqB,CAAC,YAAY,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;gBACjE,CAAC;gBAED,GAAG,CAAC,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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=authorize.request.types.js.map
@@ -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":["../../../src/lib/authorize.request.utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAC1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