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