@axa-fr/oidc-client 7.29.7 → 7.30.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 +226 -0
- package/dist/events.d.ts +3 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/fetch.d.ts +2 -2
- package/dist/fetch.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1353 -873
- package/dist/index.umd.cjs +2 -2
- package/dist/initSession.d.ts +2 -0
- package/dist/initSession.d.ts.map +1 -1
- package/dist/initWorker.d.ts +1 -25
- package/dist/initWorker.d.ts.map +1 -1
- package/dist/jwt.d.ts.map +1 -1
- package/dist/legacyCompatibility.spec.d.ts +2 -0
- package/dist/legacyCompatibility.spec.d.ts.map +1 -0
- package/dist/login.d.ts +2 -1
- package/dist/login.d.ts.map +1 -1
- package/dist/logout.d.ts.map +1 -1
- package/dist/node_modules/@axa-fr/oidc-client-service-worker/dist/OidcServiceWorker.js +1049 -0
- package/dist/node_modules/@axa-fr/oidc-client-service-worker/dist/OidcTrustedDomains.js +31 -0
- package/dist/oidc.d.ts +6 -1
- package/dist/oidc.d.ts.map +1 -1
- package/dist/oidcClient.d.ts +13 -2
- package/dist/oidcClient.d.ts.map +1 -1
- package/dist/oidcError.d.ts +5 -0
- package/dist/oidcError.d.ts.map +1 -1
- package/dist/parseTokens.d.ts +10 -0
- package/dist/parseTokens.d.ts.map +1 -1
- package/dist/protocol.d.ts +7 -1
- package/dist/protocol.d.ts.map +1 -1
- package/dist/renewTokens.d.ts +0 -6
- package/dist/renewTokens.d.ts.map +1 -1
- package/dist/requests.d.ts +3 -3
- package/dist/requests.d.ts.map +1 -1
- package/dist/resourceParameters.d.ts +9 -0
- package/dist/resourceParameters.d.ts.map +1 -0
- package/dist/resourceTokens.d.ts +34 -0
- package/dist/resourceTokens.d.ts.map +1 -0
- package/dist/resourceTokens.spec.d.ts +2 -0
- package/dist/resourceTokens.spec.d.ts.map +1 -0
- package/dist/silentLogin.d.ts +2 -1
- package/dist/silentLogin.d.ts.map +1 -1
- package/dist/types.d.ts +28 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +3 -3
- package/src/events.ts +3 -0
- package/src/fetch.ts +115 -15
- package/src/index.ts +4 -0
- package/src/initSession.ts +9 -0
- package/src/initWorker.ts +65 -13
- package/src/jwt.spec.ts +17 -0
- package/src/jwt.ts +4 -1
- package/src/legacyCompatibility.spec.ts +142 -0
- package/src/login.ts +91 -29
- package/src/logout.ts +36 -0
- package/src/oidc.ts +71 -20
- package/src/oidcClient.ts +48 -3
- package/src/oidcError.ts +7 -0
- package/src/parseTokens.ts +14 -1
- package/src/protocol.ts +16 -1
- package/src/renewTokens.ts +32 -16
- package/src/renewTokensError.spec.ts +111 -0
- package/src/requests.ts +13 -11
- package/src/resourceParameters.ts +85 -0
- package/src/resourceTokens.spec.ts +1271 -0
- package/src/resourceTokens.ts +708 -0
- package/src/silentLogin.spec.ts +87 -1
- package/src/silentLogin.ts +24 -22
- package/src/types.ts +34 -0
- package/src/version.ts +1 -1
package/src/silentLogin.spec.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
2
2
|
|
|
3
3
|
import { OidcError, OidcErrorCode, serializeOidcError } from './oidcError';
|
|
4
4
|
import { isOidcStateError, OidcStateError, OidcStateErrorCode } from './oidcStateError';
|
|
5
|
-
import {
|
|
5
|
+
import { type Tokens } from './parseTokens';
|
|
6
|
+
import * as renewal from './renewTokens';
|
|
7
|
+
import { _silentLoginAsync, defaultSilentLoginAsync } from './silentLogin';
|
|
8
|
+
import timer from './timer';
|
|
6
9
|
|
|
7
10
|
const installDom = () => {
|
|
8
11
|
const contentWindow = {};
|
|
@@ -30,10 +33,93 @@ const installDom = () => {
|
|
|
30
33
|
};
|
|
31
34
|
|
|
32
35
|
afterEach(() => {
|
|
36
|
+
vi.restoreAllMocks();
|
|
33
37
|
vi.useRealTimers();
|
|
34
38
|
vi.unstubAllGlobals();
|
|
35
39
|
});
|
|
36
40
|
|
|
41
|
+
describe('explicit silent login', () => {
|
|
42
|
+
const configuration = {
|
|
43
|
+
authority: 'https://issuer.example.com',
|
|
44
|
+
client_id: 'client',
|
|
45
|
+
redirect_uri: 'https://client.example.com/callback',
|
|
46
|
+
scope: 'openid',
|
|
47
|
+
silent_login_uri: 'https://client.example.com/silent-login',
|
|
48
|
+
silent_redirect_uri: 'https://client.example.com/silent-callback',
|
|
49
|
+
silent_login_timeout: 25,
|
|
50
|
+
};
|
|
51
|
+
const tokens: Tokens = {
|
|
52
|
+
accessToken: 'access',
|
|
53
|
+
refreshToken: 'refresh',
|
|
54
|
+
idToken: 'id',
|
|
55
|
+
accessTokenPayload: null,
|
|
56
|
+
idTokenPayload: null,
|
|
57
|
+
expiresAt: 100,
|
|
58
|
+
issuedAt: 0,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
it('returns provider errors without overwriting an existing session or stopping renewal', async () => {
|
|
62
|
+
const { contentWindow, getListener } = installDom();
|
|
63
|
+
const publishEvent = vi.fn();
|
|
64
|
+
const oidc = { tokens, timeoutId: 123 };
|
|
65
|
+
const clearTimeout = vi.spyOn(timer, 'clearTimeout').mockImplementation(() => undefined);
|
|
66
|
+
const renew = vi
|
|
67
|
+
.spyOn(renewal, 'autoRenewTokens')
|
|
68
|
+
.mockReturnValue(setTimeout(() => undefined, 0));
|
|
69
|
+
const promise = defaultSilentLoginAsync(window, 'custom', configuration, publishEvent, oidc)();
|
|
70
|
+
getListener()({
|
|
71
|
+
origin: 'https://client.example.com',
|
|
72
|
+
source: contentWindow,
|
|
73
|
+
data: 'custom_oidc_error:{"error":"login_required","error_description":"Sign in first."}',
|
|
74
|
+
} as unknown as MessageEvent);
|
|
75
|
+
|
|
76
|
+
await expect(promise).resolves.toMatchObject({
|
|
77
|
+
code: OidcErrorCode.LOGIN_REQUIRED,
|
|
78
|
+
oauthError: 'login_required',
|
|
79
|
+
});
|
|
80
|
+
expect(oidc.tokens).toBe(tokens);
|
|
81
|
+
expect(clearTimeout).not.toHaveBeenCalled();
|
|
82
|
+
expect(renew).not.toHaveBeenCalled();
|
|
83
|
+
expect(publishEvent).not.toHaveBeenCalledWith('token_acquired', expect.anything());
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('preserves fulfilled error values on timeout', async () => {
|
|
87
|
+
vi.useFakeTimers();
|
|
88
|
+
installDom();
|
|
89
|
+
const promise = defaultSilentLoginAsync(window, 'custom', configuration, vi.fn(), {
|
|
90
|
+
tokens: null,
|
|
91
|
+
timeoutId: null,
|
|
92
|
+
})();
|
|
93
|
+
const result = expect(promise).resolves.toMatchObject({
|
|
94
|
+
code: OidcErrorCode.SILENT_LOGIN_TIMEOUT,
|
|
95
|
+
});
|
|
96
|
+
await vi.advanceTimersByTimeAsync(25);
|
|
97
|
+
await result;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('adopts successful iframe tokens and restarts automatic renewal', async () => {
|
|
101
|
+
const { contentWindow, getListener } = installDom();
|
|
102
|
+
const publishEvent = vi.fn();
|
|
103
|
+
const oidc = { tokens: null, timeoutId: 123 };
|
|
104
|
+
const clearTimeout = vi.spyOn(timer, 'clearTimeout').mockImplementation(() => undefined);
|
|
105
|
+
const renew = vi
|
|
106
|
+
.spyOn(renewal, 'autoRenewTokens')
|
|
107
|
+
.mockReturnValue(setTimeout(() => undefined, 0));
|
|
108
|
+
const promise = defaultSilentLoginAsync(window, 'custom', configuration, publishEvent, oidc)();
|
|
109
|
+
getListener()({
|
|
110
|
+
origin: 'https://client.example.com',
|
|
111
|
+
source: contentWindow,
|
|
112
|
+
data: `custom_oidc_tokens:${JSON.stringify({ tokens, sessionState: null })}`,
|
|
113
|
+
} as unknown as MessageEvent);
|
|
114
|
+
|
|
115
|
+
await expect(promise).resolves.toEqual({});
|
|
116
|
+
expect(oidc.tokens).toEqual(tokens);
|
|
117
|
+
expect(clearTimeout).toHaveBeenCalledWith(123);
|
|
118
|
+
expect(renew).toHaveBeenCalledWith(oidc, tokens.expiresAt, {}, undefined);
|
|
119
|
+
expect(publishEvent).toHaveBeenCalledWith('token_acquired', {});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
37
123
|
describe('_silentLoginAsync typed errors', () => {
|
|
38
124
|
it('rejects with SILENT_LOGIN_TIMEOUT and publishes the same error', async () => {
|
|
39
125
|
vi.useFakeTimers();
|
package/src/silentLogin.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { autoRenewTokens } from './renewTokens.js';
|
|
|
11
11
|
import timer from './timer.js';
|
|
12
12
|
import { OidcConfiguration, StringMap } from './types.js';
|
|
13
13
|
export type SilentLoginResponse = {
|
|
14
|
+
resource?: string;
|
|
14
15
|
tokens: Tokens | null;
|
|
15
16
|
sessionState: string | null;
|
|
16
17
|
error?: string;
|
|
@@ -175,39 +176,40 @@ export const defaultSilentLoginAsync =
|
|
|
175
176
|
};
|
|
176
177
|
|
|
177
178
|
const loginLocalAsync = async () => {
|
|
178
|
-
if (oidc.timeoutId) {
|
|
179
|
-
timer.clearTimeout(oidc.timeoutId);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
179
|
let state;
|
|
183
180
|
if (extras && 'state' in extras) {
|
|
184
181
|
state = extras.state;
|
|
185
182
|
delete extras.state;
|
|
186
183
|
}
|
|
187
184
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
185
|
+
const extraFinal = !configuration.extras ? extras : { ...configuration.extras, ...extras };
|
|
186
|
+
const silentResult = await silentLoginAsync(
|
|
187
|
+
{
|
|
188
|
+
...extraFinal,
|
|
189
|
+
prompt: 'none',
|
|
190
|
+
},
|
|
191
|
+
state,
|
|
192
|
+
scope,
|
|
193
|
+
);
|
|
194
|
+
if (!silentResult) return;
|
|
195
|
+
if (silentResult.oidcError) throw silentResult.oidcError;
|
|
196
|
+
if (!silentResult.tokens) {
|
|
197
|
+
throw new OidcError(
|
|
198
|
+
OidcErrorCode.TOKEN_REQUEST_FAILED,
|
|
199
|
+
'Silent login returned no tokens.',
|
|
191
200
|
{
|
|
192
|
-
|
|
193
|
-
|
|
201
|
+
phase: 'login',
|
|
202
|
+
retryable: false,
|
|
194
203
|
},
|
|
195
|
-
state,
|
|
196
|
-
scope,
|
|
197
204
|
);
|
|
198
|
-
|
|
199
|
-
if (silentResult) {
|
|
200
|
-
oidc.tokens = silentResult.tokens;
|
|
201
|
-
publishEvent(eventNames.token_acquired, {});
|
|
202
|
-
// @ts-ignore
|
|
203
|
-
oidc.timeoutId = autoRenewTokens(oidc, oidc.tokens.expiresAt, extras, scope);
|
|
204
|
-
return {};
|
|
205
|
-
}
|
|
206
|
-
} catch (e) {
|
|
207
|
-
return e;
|
|
208
205
|
}
|
|
206
|
+
if (oidc.timeoutId) timer.clearTimeout(oidc.timeoutId);
|
|
207
|
+
oidc.tokens = silentResult.tokens;
|
|
208
|
+
publishEvent(eventNames.token_acquired, {});
|
|
209
|
+
oidc.timeoutId = autoRenewTokens(oidc, oidc.tokens.expiresAt, extras, scope);
|
|
210
|
+
return {};
|
|
209
211
|
};
|
|
210
|
-
return loginLocalAsync();
|
|
212
|
+
return loginLocalAsync().catch(error => error);
|
|
211
213
|
};
|
|
212
214
|
|
|
213
215
|
export default defaultSilentLoginAsync;
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
|
+
import type { OidcResourceConfiguration } from './protocol';
|
|
2
|
+
|
|
3
|
+
export type { OidcResourceConfiguration } from './protocol';
|
|
4
|
+
|
|
1
5
|
export type Fetch = typeof window.fetch;
|
|
2
6
|
|
|
7
|
+
/** Access-token metadata; accessToken is a placeholder when the worker hides it. */
|
|
8
|
+
export interface ResourceAccessToken {
|
|
9
|
+
resource: string;
|
|
10
|
+
issuer: string;
|
|
11
|
+
clientId: string;
|
|
12
|
+
configurationName: string;
|
|
13
|
+
accessToken: string;
|
|
14
|
+
expiresAt: number;
|
|
15
|
+
scope?: string;
|
|
16
|
+
tokenType?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Options for acquiring a resource-specific token. */
|
|
20
|
+
export interface ResourceTokenOptions {
|
|
21
|
+
forceRenew?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Options for explicitly selecting a resource in authenticated fetch. */
|
|
25
|
+
export interface ResourceFetchOptions {
|
|
26
|
+
resource?: string;
|
|
27
|
+
demonstratingProofOfPossession?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** OAuth parameters with RFC 8707 repeated resource values. */
|
|
31
|
+
export interface OAuthParameters {
|
|
32
|
+
[key: string]: string | readonly string[];
|
|
33
|
+
}
|
|
34
|
+
|
|
3
35
|
export type LogoutToken = 'access_token' | 'refresh_token';
|
|
4
36
|
|
|
5
37
|
export type PushedAuthorizationRequestMode = 'disabled' | 'auto' | 'required';
|
|
@@ -25,6 +57,8 @@ export type OidcConfiguration = {
|
|
|
25
57
|
silent_login_uri?: string;
|
|
26
58
|
silent_login_timeout?: number;
|
|
27
59
|
scope: string;
|
|
60
|
+
resource?: string | readonly string[];
|
|
61
|
+
resources?: readonly OidcResourceConfiguration[];
|
|
28
62
|
authority: string;
|
|
29
63
|
authority_time_cache_wellknowurl_in_second?: number;
|
|
30
64
|
authority_timeout_wellknowurl_in_millisecond?: number;
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '7.
|
|
1
|
+
export default '7.30.0';
|