@axa-fr/oidc-client 7.22.18 → 7.22.19
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 +31 -39
- package/bin/copy-service-worker-files.mjs +24 -17
- package/dist/OidcTrustedDomains.js +14 -12
- package/dist/cache.d.ts.map +1 -1
- package/dist/checkSession.d.ts +1 -1
- package/dist/checkSession.d.ts.map +1 -1
- package/dist/checkSessionIFrame.d.ts.map +1 -1
- package/dist/crypto.d.ts.map +1 -1
- package/dist/fetch.d.ts +2 -1
- package/dist/fetch.d.ts.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +935 -601
- package/dist/index.umd.cjs +2 -2
- package/dist/initSession.d.ts +1 -1
- package/dist/initSession.d.ts.map +1 -1
- package/dist/initWorker.d.ts +2 -2
- package/dist/initWorker.d.ts.map +1 -1
- package/dist/initWorkerOption.d.ts.map +1 -1
- package/dist/jwt.d.ts +2 -2
- package/dist/jwt.d.ts.map +1 -1
- package/dist/keepSession.d.ts.map +1 -1
- package/dist/location.d.ts.map +1 -1
- package/dist/login.d.ts +1 -1
- package/dist/login.d.ts.map +1 -1
- package/dist/logout.d.ts +1 -1
- package/dist/logout.d.ts.map +1 -1
- package/dist/oidc.d.ts +1 -1
- package/dist/oidc.d.ts.map +1 -1
- package/dist/oidcClient.d.ts +2 -2
- package/dist/oidcClient.d.ts.map +1 -1
- package/dist/parseTokens.d.ts.map +1 -1
- package/dist/renewTokens.d.ts.map +1 -1
- package/dist/requests.d.ts +1 -1
- package/dist/requests.d.ts.map +1 -1
- package/dist/silentLogin.d.ts.map +1 -1
- package/dist/timer.d.ts.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/user.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/cache.ts +21 -18
- package/src/checkSession.ts +89 -54
- package/src/checkSessionIFrame.ts +70 -69
- package/src/crypto.ts +27 -25
- package/src/events.ts +28 -28
- package/src/fetch.ts +40 -21
- package/src/index.ts +6 -17
- package/src/iniWorker.spec.ts +26 -16
- package/src/initSession.ts +115 -113
- package/src/initWorker.ts +299 -212
- package/src/initWorkerOption.ts +121 -114
- package/src/jwt.ts +150 -136
- package/src/keepSession.ts +100 -81
- package/src/location.ts +24 -26
- package/src/login.ts +246 -189
- package/src/logout.spec.ts +131 -76
- package/src/logout.ts +130 -115
- package/src/oidc.ts +426 -337
- package/src/oidcClient.ts +129 -105
- package/src/parseTokens.spec.ts +198 -179
- package/src/parseTokens.ts +221 -186
- package/src/renewTokens.ts +397 -284
- package/src/requests.spec.ts +5 -7
- package/src/requests.ts +142 -114
- package/src/route-utils.spec.ts +17 -19
- package/src/route-utils.ts +29 -26
- package/src/silentLogin.ts +145 -127
- package/src/timer.ts +10 -11
- package/src/types.ts +56 -46
- package/src/user.ts +17 -12
- package/src/version.ts +1 -1
package/src/oidcClient.ts
CHANGED
|
@@ -1,122 +1,146 @@
|
|
|
1
|
+
import { fetchWithTokens } from './fetch';
|
|
2
|
+
import { ILOidcLocation, OidcLocation } from './location';
|
|
1
3
|
import { LoginCallback, Oidc } from './oidc.js';
|
|
2
4
|
import { getValidTokenAsync, Tokens, ValidToken } from './parseTokens.js';
|
|
3
5
|
import { Fetch, OidcConfiguration, StringMap } from './types.js';
|
|
4
|
-
import {ILOidcLocation, OidcLocation} from "./location";
|
|
5
|
-
import {fetchWithTokens} from "./fetch";
|
|
6
6
|
|
|
7
7
|
export interface EventSubscriber {
|
|
8
|
-
|
|
8
|
+
(name: string, data: any);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export class OidcClient {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
12
|
+
private readonly _oidc: Oidc;
|
|
13
|
+
constructor(oidc: Oidc) {
|
|
14
|
+
this._oidc = oidc;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
subscribeEvents(func: EventSubscriber): string {
|
|
18
|
+
return this._oidc.subscribeEvents(func);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
removeEventSubscription(id: string): void {
|
|
22
|
+
this._oidc.removeEventSubscription(id);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
publishEvent(eventName: string, data: any): void {
|
|
26
|
+
this._oidc.publishEvent(eventName, data);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static getOrCreate =
|
|
30
|
+
(getFetch: () => Fetch, location: ILOidcLocation = new OidcLocation()) =>
|
|
31
|
+
(configuration: OidcConfiguration, name = 'default'): OidcClient => {
|
|
32
|
+
return new OidcClient(Oidc.getOrCreate(getFetch, location)(configuration, name));
|
|
31
33
|
};
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
35
|
+
static get(name = 'default'): OidcClient {
|
|
36
|
+
return new OidcClient(Oidc.get(name));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static eventNames = Oidc.eventNames;
|
|
40
|
+
tryKeepExistingSessionAsync(): Promise<boolean> {
|
|
41
|
+
return this._oidc.tryKeepExistingSessionAsync();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
loginAsync(
|
|
45
|
+
callbackPath: string = undefined,
|
|
46
|
+
extras: StringMap = null,
|
|
47
|
+
isSilentSignin = false,
|
|
48
|
+
scope: string = undefined,
|
|
49
|
+
silentLoginOnly = false,
|
|
50
|
+
): Promise<unknown> {
|
|
51
|
+
return this._oidc.loginAsync(callbackPath, extras, isSilentSignin, scope, silentLoginOnly);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
logoutAsync(
|
|
55
|
+
callbackPathOrUrl: string | null | undefined = undefined,
|
|
56
|
+
extras: StringMap = null,
|
|
57
|
+
): Promise<void> {
|
|
58
|
+
return this._oidc.logoutAsync(callbackPathOrUrl, extras);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
silentLoginCallbackAsync(): Promise<void> {
|
|
62
|
+
return this._oidc.silentLoginCallbackAsync();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
renewTokensAsync(extras: StringMap = null): Promise<void> {
|
|
66
|
+
return this._oidc.renewTokensAsync(extras);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
loginCallbackAsync(): Promise<LoginCallback> {
|
|
70
|
+
return this._oidc.loginCallbackWithAutoTokensRenewAsync();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get tokens(): Tokens {
|
|
74
|
+
return this._oidc.tokens;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get configuration(): OidcConfiguration {
|
|
78
|
+
return this._oidc.configuration;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async generateDemonstrationOfProofOfPossessionAsync(
|
|
82
|
+
accessToken: string,
|
|
83
|
+
url: string,
|
|
84
|
+
method: string,
|
|
85
|
+
extras: StringMap = {},
|
|
86
|
+
): Promise<string> {
|
|
87
|
+
return this._oidc.generateDemonstrationOfProofOfPossessionAsync(
|
|
88
|
+
accessToken,
|
|
89
|
+
url,
|
|
90
|
+
method,
|
|
91
|
+
extras,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async getValidTokenAsync(waitMs = 200, numberWait = 50): Promise<ValidToken> {
|
|
96
|
+
return getValidTokenAsync(this._oidc, waitMs, numberWait);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fetchWithTokens(fetch: Fetch, demonstrating_proof_of_possession: boolean = false): Fetch {
|
|
100
|
+
return fetchWithTokens(fetch, this._oidc, demonstrating_proof_of_possession);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async userInfoAsync<T extends OidcUserInfo = OidcUserInfo>(
|
|
104
|
+
noCache = false,
|
|
105
|
+
demonstrating_proof_of_possession: boolean = false,
|
|
106
|
+
): Promise<T> {
|
|
107
|
+
return this._oidc.userInfoAsync(noCache, demonstrating_proof_of_possession);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
userInfo<T extends OidcUserInfo = OidcUserInfo>(): T {
|
|
111
|
+
return this._oidc.userInfo;
|
|
112
|
+
}
|
|
89
113
|
}
|
|
90
114
|
|
|
91
115
|
export interface OidcUserInfo {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
sub: string;
|
|
117
|
+
name?: string;
|
|
118
|
+
given_name?: string;
|
|
119
|
+
family_name?: string;
|
|
120
|
+
middle_name?: string;
|
|
121
|
+
nickname?: string;
|
|
122
|
+
preferred_username?: string;
|
|
123
|
+
profile?: string;
|
|
124
|
+
picture?: string;
|
|
125
|
+
website?: string;
|
|
126
|
+
email?: string;
|
|
127
|
+
email_verified?: boolean;
|
|
128
|
+
gender?: string;
|
|
129
|
+
birthdate?: string;
|
|
130
|
+
zoneinfo?: string;
|
|
131
|
+
locale?: string;
|
|
132
|
+
phone_number?: string;
|
|
133
|
+
phone_number_verified?: boolean;
|
|
134
|
+
address?: OidcAddressClaim;
|
|
135
|
+
updated_at?: number;
|
|
136
|
+
groups?: string[];
|
|
113
137
|
}
|
|
114
138
|
|
|
115
139
|
export interface OidcAddressClaim {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
140
|
+
formatted?: string;
|
|
141
|
+
street_address?: string;
|
|
142
|
+
locality?: string;
|
|
143
|
+
region?: string;
|
|
144
|
+
postal_code?: string;
|
|
145
|
+
country?: string;
|
|
122
146
|
}
|
package/src/parseTokens.spec.ts
CHANGED
|
@@ -1,193 +1,212 @@
|
|
|
1
|
-
import { describe, expect,it } from 'vitest';
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
|
+
import { sleepAsync } from './initWorker';
|
|
3
4
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from
|
|
11
|
-
import {StringMap, TokenAutomaticRenewMode} from
|
|
12
|
-
import {sleepAsync} from "./initWorker";
|
|
5
|
+
getValidTokenAsync,
|
|
6
|
+
isTokensOidcValid,
|
|
7
|
+
parseJwt,
|
|
8
|
+
parseOriginalTokens,
|
|
9
|
+
setTokens,
|
|
10
|
+
TokenRenewMode,
|
|
11
|
+
} from './parseTokens';
|
|
12
|
+
import { StringMap, TokenAutomaticRenewMode } from './types';
|
|
13
13
|
|
|
14
14
|
describe('ParseTokens test Suite', () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
const currentTimeUnixSecond = new Date().getTime() / 1000;
|
|
16
|
+
describe.each([
|
|
17
|
+
[currentTimeUnixSecond + 120, currentTimeUnixSecond - 10, true],
|
|
18
|
+
[currentTimeUnixSecond - 20, currentTimeUnixSecond - 50, false],
|
|
19
|
+
])('getValidTokenAsync', (expiresAt, issuedAt, expectIsValidToken) => {
|
|
20
|
+
it('should getValidTokenAsync wait and return value', async () => {
|
|
21
|
+
const oidc = {
|
|
22
|
+
tokens: {
|
|
23
|
+
refreshToken: 'youhou',
|
|
24
|
+
idTokenPayload: null,
|
|
25
|
+
idToken: 'youhou',
|
|
26
|
+
accessTokenPayload: null,
|
|
27
|
+
accessToken: 'youhou',
|
|
28
|
+
expiresAt,
|
|
29
|
+
issuedAt,
|
|
30
|
+
},
|
|
31
|
+
configuration: {
|
|
32
|
+
token_automatic_renew_mode: TokenAutomaticRenewMode.AutomaticBeforeTokenExpiration,
|
|
33
|
+
},
|
|
34
|
+
renewTokensAsync: async (_extras: StringMap) => {
|
|
35
|
+
await sleepAsync({ milliseconds: 10 });
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
const result = await getValidTokenAsync(oidc, 1, 1);
|
|
39
|
+
expect(result.isTokensValid).toEqual(expectIsValidToken);
|
|
39
40
|
});
|
|
41
|
+
});
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
43
|
+
describe.each([
|
|
44
|
+
[
|
|
45
|
+
'eyJzZXNzaW9uX3N0YXRlIjoiNzVjYzVlZDItZGYyZC00NTY5LWJmYzUtMThhOThlNjhiZTExIiwic2NvcGUiOiJvcGVuaWQgZW1haWwgcHJvZmlsZSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJuYW1lIjoixrTHosOBw6zDhyDlsI_lkI0t44Ob44Or44OYIiwicHJlZmVycmVkX3VzZXJuYW1lIjoidGVzdGluZ2NoYXJhY3RlcnNAaW52ZW50ZWRtYWlsLmNvbSIsImdpdmVuX25hbWUiOiLGtMeiw4HDrMOHIiwiZmFtaWx5X25hbWUiOiLlsI_lkI0t44Ob44Or44OYIn0',
|
|
46
|
+
{
|
|
47
|
+
session_state: '75cc5ed2-df2d-4569-bfc5-18a98e68be11',
|
|
48
|
+
scope: 'openid email profile',
|
|
49
|
+
email_verified: true,
|
|
50
|
+
name: 'ƴǢÁìÇ 小名-ホルヘ',
|
|
51
|
+
preferred_username: 'testingcharacters@inventedmail.com',
|
|
52
|
+
given_name: 'ƴǢÁìÇ',
|
|
53
|
+
family_name: '小名-ホルヘ',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
[
|
|
57
|
+
'eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCI_IjoiYWE_In0',
|
|
58
|
+
{
|
|
59
|
+
'?': 'aa?',
|
|
60
|
+
iat: 1516239022,
|
|
61
|
+
name: 'John Doe',
|
|
62
|
+
sub: '1234567890',
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
])('parseJwtShouldExtractData', (claimsPart, expectedResult) => {
|
|
66
|
+
it('should parseJwtShouldExtractData ', async () => {
|
|
67
|
+
const result = parseJwt(claimsPart);
|
|
68
|
+
expect(expectedResult).toStrictEqual(result);
|
|
66
69
|
});
|
|
70
|
+
});
|
|
67
71
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
describe.each([
|
|
109
|
-
[idTokenPayload, "nonce", oidcServerConfiguration, true, "success"],
|
|
110
|
-
[idTokenPayload, "other_nonce", oidcServerConfiguration, false, "bad nonce"],
|
|
111
|
-
[idTokenPayload, "nonce", {issuer:"tutu"}, false, "different issuer"],
|
|
112
|
-
[idTokenPayloadExpired, "nonce", oidcServerConfiguration, false, "id token expired issuer"],
|
|
113
|
-
[idTokenPayloadIssuedTooLongTimeAgo, "nonce", oidcServerConfiguration, false, "id token expired issuer"],
|
|
114
|
-
])('isTokensOidcValid', (idTokenPayload, nonce, oidcServerConfiguration, expectIsValidToken, status) => {
|
|
115
|
-
it('should isTokensOidcValid return ' + status, async () => {
|
|
116
|
-
const oidc = {
|
|
117
|
-
idTokenPayload,
|
|
118
|
-
};
|
|
119
|
-
const {isValid} = isTokensOidcValid(oidc, nonce, oidcServerConfiguration);
|
|
120
|
-
expect(isValid).toEqual(expectIsValidToken);
|
|
121
|
-
});
|
|
72
|
+
const id_token =
|
|
73
|
+
'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjUwNWZkODljLTM4YzktNGI2Mi04ZjQ3LWI4MGQ0ZTNhYjYxNSJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODA4MCIsInN1YiI6ImFkbWluIiwiYXVkIjoiM2FTbk5XUGxZQWQwOGVES3c1UUNpSWVMcWpIdHkxTTVzSGFzcDJDZWREcWYzbmJkZm8xUFo1cXhmbWoyaFhkUyIsImV4cCI6MTY5MDk4NzQ1NCwiYXV0aF90aW1lIjoxNjkwOTg2NTUxLCJpYXQiOjE2OTA5ODY1NTQsImFjciI6IjAiLCJhenAiOiIzYVNuTldQbFlBZDA4ZURLdzVRQ2lJZUxxakh0eTFNNXNIYXNwMkNlZERxZjNuYmRmbzFQWjVxeGZtajJoWGRTIiwicHJlZmVycmVkX3VzZXJuYW1lIjoiYWRtaW4iLCJzY29wZSI6Im9wZW5pZCBwcm9maWxlIGdyb3VwcyBvZmZsaW5lX2FjY2VzcyIsIm5iZiI6MTY5MDk4NjU1NCwianRpIjoiNjMiLCJub25jZSI6ImNpQkVVOTdaVmRWVSIsImdyb3VwcyI6WyJhZG1pbiJdLCJuYW1lIjoiQWRtaW5pc3RyYXRvciIsInVwZGF0ZWRfYXQiOjE2OTA5ODY1NDV9.2MUdtQR_QtzDY9BTMctG8C4uvg92DgMIUUoJed2cI7WTd5_VEPFW87esDQLw4snVdAJM1_Wf3wB88B2MXFDMCnMTNn0TMnzetRDiG3xlr2LL-geL5SNgwD0Y6RPK_aITjrC9uiQCTj3LPEENrBulNRZPURwaVon9WUVNuuBmMTKd7QKEuFN0zYDoRs0HnXo6WKnFy1rldLGh_JpA3PBUuXt4VMjfGQ7yYEuNn7MkFVDX6OnTffR8jTQp74hREvuRLFjYxfgfgu547X7yIcboOl81D0ZQlP-gfvBOeypZolRLScuqAA3fHBYvE0vCtOM6ObekfeeTDfms75csMLUuZtTR07x32xYC8vdoFsY0sRpMByTqlhsae9VX_rETJ7PIWEfruojzcj47WN9dG0K3pdPiJHEwZ1CKgZfU_cY0gtuAGaIcIjKL0txXCevaiIiIsrgSU_HTjNVybp4WHSAs3h6x0XLz4_91luCylsaoMQbwKOQNwAfr2L74jF6DOg-8DIPb-WClRQzaQtrkx_iv6FtqCB3ogFoZwi6xljdYUc2EHUmoAo-LXal-QAgUXGGzfFU2YOpxV3RyAbMGPm7PfkMVzDsDJwORJNhh38QQ6o88GgNnV28BT-d2G0n7okc0QC6o2IW0jpyCrI6v0hWOBUX2EqiJ5Wao-4LYZfCaRgU';
|
|
74
|
+
const refresh_token =
|
|
75
|
+
'DEsqDca7nDGSgT6tJPkCwbPy98B8VOC4AA55lOPs03G3hqhZ8WH08REBcwTZg1s0jZyVoA3iCXzm4PPJ096gjV7ZKYyN8vnFKw6P6KLV3tUI6mWFaSROoh1LipThFrkS';
|
|
76
|
+
const access_token = 'opqavdgHEYx8nhCdc3iByd1HD0jiYN30LevhJy4f5wIavINXKdh4lQ9C3kA49QF0OH0XeA02';
|
|
77
|
+
describe.each([
|
|
78
|
+
[
|
|
79
|
+
{
|
|
80
|
+
access_token: access_token,
|
|
81
|
+
token_type: 'Bearer',
|
|
82
|
+
expires_in: '900', // Here a string instead of a number
|
|
83
|
+
refresh_token: refresh_token,
|
|
84
|
+
id_token: id_token,
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
{
|
|
89
|
+
access_token: access_token,
|
|
90
|
+
token_type: 'Bearer',
|
|
91
|
+
expires_in: 900,
|
|
92
|
+
refresh_token: refresh_token,
|
|
93
|
+
id_token: id_token,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
[
|
|
97
|
+
{
|
|
98
|
+
access_token: access_token,
|
|
99
|
+
token_type: 'Bearer',
|
|
100
|
+
expires_in: 900,
|
|
101
|
+
expiresAt: 1609987454, // Here expiresAt that come from Service Worker
|
|
102
|
+
refresh_token: refresh_token,
|
|
103
|
+
id_token: id_token,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
])('getValidTokenAsync', tokens => {
|
|
107
|
+
it('should parseOriginalTokens', async () => {
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
const result = parseOriginalTokens(tokens);
|
|
110
|
+
expect(typeof result.issuedAt).toEqual('number');
|
|
122
111
|
});
|
|
112
|
+
});
|
|
123
113
|
|
|
114
|
+
const idTokenPayload = {
|
|
115
|
+
iss: 'toto',
|
|
116
|
+
exp: currentTimeUnixSecond + 900,
|
|
117
|
+
iat: currentTimeUnixSecond - 900,
|
|
118
|
+
nonce: 'nonce',
|
|
119
|
+
};
|
|
120
|
+
const oidcServerConfiguration = { issuer: 'toto' };
|
|
121
|
+
const idTokenPayloadExpired = { ...idTokenPayload, exp: currentTimeUnixSecond - 20 };
|
|
122
|
+
const idTokenPayloadIssuedTooLongTimeAgo = {
|
|
123
|
+
...idTokenPayload,
|
|
124
|
+
iat: currentTimeUnixSecond - 20000000,
|
|
125
|
+
};
|
|
124
126
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
127
|
+
describe.each([
|
|
128
|
+
[idTokenPayload, 'nonce', oidcServerConfiguration, true, 'success'],
|
|
129
|
+
[idTokenPayload, 'other_nonce', oidcServerConfiguration, false, 'bad nonce'],
|
|
130
|
+
[idTokenPayload, 'nonce', { issuer: 'tutu' }, false, 'different issuer'],
|
|
131
|
+
[idTokenPayloadExpired, 'nonce', oidcServerConfiguration, false, 'id token expired issuer'],
|
|
132
|
+
[
|
|
133
|
+
idTokenPayloadIssuedTooLongTimeAgo,
|
|
134
|
+
'nonce',
|
|
135
|
+
oidcServerConfiguration,
|
|
136
|
+
false,
|
|
137
|
+
'id token expired issuer',
|
|
138
|
+
],
|
|
139
|
+
])(
|
|
140
|
+
'isTokensOidcValid',
|
|
141
|
+
(idTokenPayload, nonce, oidcServerConfiguration, expectIsValidToken, status) => {
|
|
142
|
+
it('should isTokensOidcValid return ' + status, async () => {
|
|
143
|
+
const oidc = {
|
|
144
|
+
idTokenPayload,
|
|
145
|
+
};
|
|
146
|
+
const { isValid } = isTokensOidcValid(oidc, nonce, oidcServerConfiguration);
|
|
147
|
+
expect(isValid).toEqual(expectIsValidToken);
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const testTokens = {
|
|
153
|
+
id_token:
|
|
154
|
+
'eyJhbGciOiJSUzI1NiIsImtpZCI6IkMyNTJGOUNBQjc3Q0MxNTQwNTBFMTg1NTk5MjJCMTJGIiwidHlwIjoiSldUIn0.eyJpc3MiOiJodHRwczovL2RlbW8uZHVlbmRlc29mdHdhcmUuY29tIiwibmJmIjoxNzA2NTQwMjU4LCJpYXQiOjE3MDY1NDAyNTgsImV4cCI6MTcwNjU0MDU1OCwiYXVkIjoiaW50ZXJhY3RpdmUucHVibGljLnNob3J0IiwiYW1yIjpbInB3ZCJdLCJub25jZSI6IlA5dEo5eGxHZE05NiIsImF0X2hhc2giOiJOWnZhR0dZYlhoelRNWlVxUjlNYk5nIiwic2lkIjoiMzQ1QUJDODhFNkU1MEFGMTI3M0VENDE1QTdGRDZBMjMiLCJzdWIiOiIyIiwiYXV0aF90aW1lIjoxNzA2NTMxNjY1LCJpZHAiOiJsb2NhbCJ9.MVtXrCkshJFBplbOw7az3fdWB1Ewqixb2fuHXpx7KbGWUY6qgT9ijlldeD-ZV7JGA958AKqmGwfNjovAJE89pQsCFKkNft6fRO8eM9qKif6eRUqMMPiQrawARpuJOs1NvJ-SyeRs_jSNLwPVzI8NlZyFWHoyQ4DZnFoQLSQMy5UaHaCtWhC_FrWMFLQvbE3RuMlnJGzrsoMewFyVAZctMCTE1MOI3Akvhe1IGc1hmxzwNg3OkxwzHLinsDlDw8UVn8vX5iNI18GFuyTuJlawOq5OHHJH3LdKQD_RbwRF-9BFjKRZfWzGpdpxTD2lIPf1Irc3U_R6xCNuXYUwzrHp6Q',
|
|
155
|
+
access_token: 'ACCESS_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER_default',
|
|
156
|
+
expires_in: 75,
|
|
157
|
+
token_type: 'Bearer',
|
|
158
|
+
refresh_token: 'REFRESH_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER_default',
|
|
159
|
+
scope: 'openid profile email api offline_access',
|
|
160
|
+
issued_at: 1706540256.465,
|
|
161
|
+
accessTokenPayload: {
|
|
162
|
+
iss: 'https://demo.duendesoftware.com',
|
|
163
|
+
nbf: 1706540258,
|
|
164
|
+
iat: 1706540258,
|
|
165
|
+
exp: 1706540333,
|
|
166
|
+
aud: 'api',
|
|
167
|
+
scope: ['openid', 'profile', 'email', 'api', 'offline_access'],
|
|
168
|
+
amr: ['pwd'],
|
|
169
|
+
client_id: 'interactive.public.short',
|
|
170
|
+
sub: '2',
|
|
171
|
+
auth_time: 1706531665,
|
|
172
|
+
idp: 'local',
|
|
173
|
+
name: 'Bob Smith',
|
|
174
|
+
email: 'BobSmith@email.com',
|
|
175
|
+
sid: '345ABC88E6E50AF1273ED415A7FD6A23',
|
|
176
|
+
jti: 'E3CF3853D77AC90ABC774266CD381C43',
|
|
177
|
+
},
|
|
178
|
+
idTokenPayload: {
|
|
179
|
+
iss: 'https://demo.duendesoftware.com',
|
|
180
|
+
nbf: 1706540258,
|
|
181
|
+
iat: 1706540258,
|
|
182
|
+
exp: 1706540558,
|
|
183
|
+
aud: 'interactive.public.short',
|
|
184
|
+
amr: ['pwd'],
|
|
185
|
+
nonce: 'NONCE_SECURED_BY_OIDC_SERVICE_WORKER_default',
|
|
186
|
+
at_hash: 'NZvaGGYbXhzTMZUqR9MbNg',
|
|
187
|
+
sid: '345ABC88E6E50AF1273ED415A7FD6A23',
|
|
188
|
+
sub: '2',
|
|
189
|
+
auth_time: 1706531665,
|
|
190
|
+
idp: 'local',
|
|
191
|
+
},
|
|
192
|
+
expiresAt: 1706540333,
|
|
193
|
+
};
|
|
176
194
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
195
|
+
describe.each([
|
|
196
|
+
[testTokens, null, TokenRenewMode.access_token_invalid, () => {}],
|
|
197
|
+
[
|
|
198
|
+
testTokens,
|
|
199
|
+
{ testTokens, idTokenPayload: undefined, id_token: undefined },
|
|
200
|
+
TokenRenewMode.access_token_invalid,
|
|
201
|
+
(newTokens: any) => {
|
|
202
|
+
expect(newTokens.idTokenPayload).toBeDefined();
|
|
203
|
+
expect(newTokens.id_token).toBeDefined();
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
])('setTokens', (tokens, oldTokens, tokenRenewMode, validationFunction) => {
|
|
207
|
+
it('should setTokens return updatedTokens', async () => {
|
|
208
|
+
const newTokens = setTokens(tokens, oldTokens, tokenRenewMode);
|
|
209
|
+
validationFunction(newTokens);
|
|
191
210
|
});
|
|
192
|
-
|
|
211
|
+
});
|
|
193
212
|
});
|