@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/parseTokens.ts
CHANGED
|
@@ -1,233 +1,268 @@
|
|
|
1
|
-
import {sleepAsync} from './initWorker.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const b64DecodeUnicode =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
} catch (e) {
|
|
19
|
-
console.warn(e);
|
|
1
|
+
import { sleepAsync } from './initWorker.js';
|
|
2
|
+
import { StringMap, TokenAutomaticRenewMode } from './types';
|
|
3
|
+
|
|
4
|
+
const b64DecodeUnicode = str =>
|
|
5
|
+
decodeURIComponent(
|
|
6
|
+
Array.prototype.map
|
|
7
|
+
.call(atob(str), c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
|
|
8
|
+
.join(''),
|
|
9
|
+
);
|
|
10
|
+
export const parseJwt = (payload: string) =>
|
|
11
|
+
JSON.parse(b64DecodeUnicode(payload.replaceAll(/-/g, '+').replaceAll(/_/g, '/')));
|
|
12
|
+
|
|
13
|
+
const extractTokenPayload = (token: string) => {
|
|
14
|
+
try {
|
|
15
|
+
if (!token) {
|
|
16
|
+
return null;
|
|
20
17
|
}
|
|
21
|
-
|
|
18
|
+
if (countLetter(token, '.') === 2) {
|
|
19
|
+
return parseJwt(token.split('.')[1]);
|
|
20
|
+
} else {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
} catch (e) {
|
|
24
|
+
console.warn(e);
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
22
27
|
};
|
|
23
28
|
|
|
24
|
-
const countLetter = (str
|
|
25
|
-
|
|
29
|
+
const countLetter = (str: string, find) => {
|
|
30
|
+
return str.split(find).length - 1;
|
|
26
31
|
};
|
|
27
32
|
|
|
28
33
|
export type Tokens = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
refreshToken: string;
|
|
35
|
+
idTokenPayload: any;
|
|
36
|
+
idToken: string;
|
|
37
|
+
accessTokenPayload: any;
|
|
38
|
+
accessToken: string;
|
|
39
|
+
expiresAt: number;
|
|
40
|
+
issuedAt: number;
|
|
36
41
|
};
|
|
37
42
|
|
|
38
43
|
export type TokenRenewModeType = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
44
|
+
access_token_or_id_token_invalid: string;
|
|
45
|
+
access_token_invalid: string;
|
|
46
|
+
id_token_invalid: string;
|
|
47
|
+
};
|
|
43
48
|
|
|
44
49
|
export const TokenRenewMode = {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
access_token_or_id_token_invalid: 'access_token_or_id_token_invalid',
|
|
51
|
+
access_token_invalid: 'access_token_invalid',
|
|
52
|
+
id_token_invalid: 'id_token_invalid',
|
|
48
53
|
};
|
|
49
54
|
|
|
50
55
|
function extractedIssueAt(tokens, accessTokenPayload, _idTokenPayload) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
} else if (typeof tokens.issuedAt == "string") {
|
|
61
|
-
return parseInt(tokens.issuedAt, 10);
|
|
56
|
+
if (!tokens.issuedAt) {
|
|
57
|
+
if (accessTokenPayload && accessTokenPayload.iat) {
|
|
58
|
+
return accessTokenPayload.iat;
|
|
59
|
+
} else if (_idTokenPayload && _idTokenPayload.iat) {
|
|
60
|
+
return _idTokenPayload.iat;
|
|
61
|
+
} else {
|
|
62
|
+
const currentTimeUnixSecond = new Date().getTime() / 1000;
|
|
63
|
+
return currentTimeUnixSecond;
|
|
62
64
|
}
|
|
63
|
-
|
|
65
|
+
} else if (typeof tokens.issuedAt == 'string') {
|
|
66
|
+
return parseInt(tokens.issuedAt, 10);
|
|
67
|
+
}
|
|
68
|
+
return tokens.issuedAt;
|
|
64
69
|
}
|
|
65
70
|
|
|
66
|
-
export const setTokens = (tokens, oldTokens = null, tokenRenewMode: string):Tokens => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
export const setTokens = (tokens, oldTokens = null, tokenRenewMode: string): Tokens => {
|
|
72
|
+
if (!tokens) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
let accessTokenPayload;
|
|
76
|
+
const expireIn =
|
|
77
|
+
typeof tokens.expiresIn == 'string' ? parseInt(tokens.expiresIn, 10) : tokens.expiresIn;
|
|
78
|
+
|
|
79
|
+
if (tokens.accessTokenPayload !== undefined) {
|
|
80
|
+
accessTokenPayload = tokens.accessTokenPayload;
|
|
81
|
+
} else {
|
|
82
|
+
accessTokenPayload = extractTokenPayload(tokens.accessToken);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// When id_token is not rotated we reuse old id_token
|
|
86
|
+
let idToken: string;
|
|
87
|
+
if (oldTokens != null && 'idToken' in oldTokens && !('idToken' in tokens)) {
|
|
88
|
+
idToken = oldTokens.idToken;
|
|
89
|
+
} else {
|
|
90
|
+
idToken = tokens.idToken;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const _idTokenPayload = tokens.idTokenPayload
|
|
94
|
+
? tokens.idTokenPayload
|
|
95
|
+
: extractTokenPayload(idToken);
|
|
96
|
+
|
|
97
|
+
const idTokenExpireAt =
|
|
98
|
+
_idTokenPayload && _idTokenPayload.exp ? _idTokenPayload.exp : Number.MAX_VALUE;
|
|
99
|
+
const accessTokenExpiresAt =
|
|
100
|
+
accessTokenPayload && accessTokenPayload.exp
|
|
101
|
+
? accessTokenPayload.exp
|
|
102
|
+
: tokens.issuedAt + expireIn;
|
|
103
|
+
|
|
104
|
+
tokens.issuedAt = extractedIssueAt(tokens, accessTokenPayload, _idTokenPayload);
|
|
78
105
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
106
|
+
let expiresAt;
|
|
107
|
+
if (tokens.expiresAt) {
|
|
108
|
+
expiresAt = tokens.expiresAt;
|
|
109
|
+
} else {
|
|
110
|
+
if (tokenRenewMode === TokenRenewMode.access_token_invalid) {
|
|
111
|
+
expiresAt = accessTokenExpiresAt;
|
|
112
|
+
} else if (tokenRenewMode === TokenRenewMode.id_token_invalid) {
|
|
113
|
+
expiresAt = idTokenExpireAt;
|
|
83
114
|
} else {
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const _idTokenPayload = tokens.idTokenPayload ? tokens.idTokenPayload : extractTokenPayload(idToken);
|
|
88
|
-
|
|
89
|
-
const idTokenExpireAt = (_idTokenPayload && _idTokenPayload.exp) ? _idTokenPayload.exp : Number.MAX_VALUE;
|
|
90
|
-
const accessTokenExpiresAt = (accessTokenPayload && accessTokenPayload.exp) ? accessTokenPayload.exp : tokens.issuedAt + expireIn;
|
|
91
|
-
|
|
92
|
-
tokens.issuedAt = extractedIssueAt(tokens, accessTokenPayload, _idTokenPayload);
|
|
93
|
-
|
|
94
|
-
let expiresAt;
|
|
95
|
-
if(tokens.expiresAt)
|
|
96
|
-
{
|
|
97
|
-
expiresAt = tokens.expiresAt;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
if (tokenRenewMode === TokenRenewMode.access_token_invalid) {
|
|
101
|
-
expiresAt = accessTokenExpiresAt;
|
|
102
|
-
} else if (tokenRenewMode === TokenRenewMode.id_token_invalid) {
|
|
103
|
-
expiresAt = idTokenExpireAt;
|
|
104
|
-
} else {
|
|
105
|
-
expiresAt = idTokenExpireAt < accessTokenExpiresAt ? idTokenExpireAt : accessTokenExpiresAt;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const newTokens = { ...tokens, idTokenPayload: _idTokenPayload, accessTokenPayload, expiresAt, idToken };
|
|
110
|
-
// When refresh_token is not rotated we reuse old refresh_token
|
|
111
|
-
if (oldTokens != null && 'refreshToken' in oldTokens && !('refreshToken' in tokens)) {
|
|
112
|
-
const refreshToken = oldTokens.refreshToken;
|
|
113
|
-
return { ...newTokens, refreshToken };
|
|
115
|
+
expiresAt = idTokenExpireAt < accessTokenExpiresAt ? idTokenExpireAt : accessTokenExpiresAt;
|
|
114
116
|
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const newTokens = {
|
|
120
|
+
...tokens,
|
|
121
|
+
idTokenPayload: _idTokenPayload,
|
|
122
|
+
accessTokenPayload,
|
|
123
|
+
expiresAt,
|
|
124
|
+
idToken,
|
|
125
|
+
};
|
|
126
|
+
// When refresh_token is not rotated we reuse old refresh_token
|
|
127
|
+
if (oldTokens != null && 'refreshToken' in oldTokens && !('refreshToken' in tokens)) {
|
|
128
|
+
const refreshToken = oldTokens.refreshToken;
|
|
129
|
+
return { ...newTokens, refreshToken };
|
|
130
|
+
}
|
|
115
131
|
|
|
116
|
-
|
|
132
|
+
return newTokens;
|
|
117
133
|
};
|
|
118
134
|
|
|
119
135
|
export const parseOriginalTokens = (tokens, oldTokens, tokenRenewMode: string) => {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
if (!tokens) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
if (!tokens.issued_at) {
|
|
140
|
+
const currentTimeUnixSecond = new Date().getTime() / 1000;
|
|
141
|
+
tokens.issued_at = currentTimeUnixSecond;
|
|
142
|
+
}
|
|
127
143
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if ('refresh_token' in tokens) {
|
|
138
|
-
// @ts-ignore
|
|
139
|
-
data.refreshToken = tokens.refresh_token;
|
|
140
|
-
}
|
|
144
|
+
const data = {
|
|
145
|
+
accessToken: tokens.access_token,
|
|
146
|
+
expiresIn: tokens.expires_in,
|
|
147
|
+
idToken: tokens.id_token,
|
|
148
|
+
scope: tokens.scope,
|
|
149
|
+
tokenType: tokens.token_type,
|
|
150
|
+
issuedAt: tokens.issued_at,
|
|
151
|
+
};
|
|
141
152
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
153
|
+
if ('refresh_token' in tokens) {
|
|
154
|
+
// @ts-ignore
|
|
155
|
+
data.refreshToken = tokens.refresh_token;
|
|
156
|
+
}
|
|
146
157
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
158
|
+
if (tokens.accessTokenPayload !== undefined) {
|
|
159
|
+
// @ts-ignore
|
|
160
|
+
data.accessTokenPayload = tokens.accessTokenPayload;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (tokens.idTokenPayload !== undefined) {
|
|
164
|
+
// @ts-ignore
|
|
165
|
+
data.idTokenPayload = tokens.idTokenPayload;
|
|
166
|
+
}
|
|
151
167
|
|
|
152
|
-
|
|
168
|
+
return setTokens(data, oldTokens, tokenRenewMode);
|
|
153
169
|
};
|
|
154
170
|
|
|
155
171
|
export const computeTimeLeft = (refreshTimeBeforeTokensExpirationInSecond, expiresAt) => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
172
|
+
const currentTimeUnixSecond = new Date().getTime() / 1000;
|
|
173
|
+
|
|
174
|
+
const timeLeftSecond = expiresAt - currentTimeUnixSecond;
|
|
175
|
+
|
|
176
|
+
return Math.round(timeLeftSecond - refreshTimeBeforeTokensExpirationInSecond);
|
|
161
177
|
};
|
|
162
178
|
|
|
163
|
-
export const isTokensValid =
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
179
|
+
export const isTokensValid = tokens => {
|
|
180
|
+
if (!tokens) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
return computeTimeLeft(0, tokens.expiresAt) > 0;
|
|
168
184
|
};
|
|
169
185
|
|
|
170
186
|
export type ValidToken = {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
187
|
+
isTokensValid: boolean;
|
|
188
|
+
tokens: Tokens;
|
|
189
|
+
numberWaited: number;
|
|
190
|
+
};
|
|
175
191
|
|
|
176
|
-
export interface OidcToken{
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
192
|
+
export interface OidcToken {
|
|
193
|
+
tokens?: Tokens;
|
|
194
|
+
configuration: { token_automatic_renew_mode?: TokenAutomaticRenewMode };
|
|
195
|
+
renewTokensAsync: (extras: StringMap) => Promise<void>;
|
|
180
196
|
}
|
|
181
197
|
|
|
182
|
-
export const getValidTokenAsync = async (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
198
|
+
export const getValidTokenAsync = async (
|
|
199
|
+
oidc: OidcToken,
|
|
200
|
+
waitMs = 200,
|
|
201
|
+
numberWait = 50,
|
|
202
|
+
): Promise<ValidToken> => {
|
|
203
|
+
let numberWaitTemp = numberWait;
|
|
204
|
+
if (!oidc.tokens) {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
while (!isTokensValid(oidc.tokens) && numberWaitTemp > 0) {
|
|
208
|
+
if (
|
|
209
|
+
oidc.configuration.token_automatic_renew_mode ==
|
|
210
|
+
TokenAutomaticRenewMode.AutomaticOnlyWhenFetchExecuted
|
|
211
|
+
) {
|
|
212
|
+
await oidc.renewTokensAsync({});
|
|
213
|
+
break;
|
|
214
|
+
} else {
|
|
215
|
+
await sleepAsync({ milliseconds: waitMs });
|
|
195
216
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
217
|
+
numberWaitTemp = numberWaitTemp - 1;
|
|
218
|
+
}
|
|
219
|
+
const isValid = isTokensValid(oidc.tokens);
|
|
220
|
+
return {
|
|
221
|
+
isTokensValid: isValid,
|
|
222
|
+
tokens: oidc.tokens,
|
|
223
|
+
numberWaited: numberWaitTemp - numberWait,
|
|
224
|
+
};
|
|
202
225
|
};
|
|
203
226
|
|
|
204
227
|
// https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation (excluding rules #1, #4, #5, #7, #8, #12, and #13 which did not apply).
|
|
205
228
|
// https://github.com/openid/AppAuth-JS/issues/65
|
|
206
229
|
export const isTokensOidcValid = (tokens, nonce, oidcServerConfiguration) => {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
230
|
+
if (tokens.idTokenPayload) {
|
|
231
|
+
const idTokenPayload = tokens.idTokenPayload;
|
|
232
|
+
// 2: The Issuer Identifier for the OpenID Provider (which is typically obtained during Discovery) MUST exactly match the value of the iss (issuer) Claim.
|
|
233
|
+
if (oidcServerConfiguration.issuer !== idTokenPayload.iss) {
|
|
234
|
+
return {
|
|
235
|
+
isValid: false,
|
|
236
|
+
reason: `Issuer does not match (oidcServerConfiguration issuer) ${oidcServerConfiguration.issuer} !== (idTokenPayload issuer) ${idTokenPayload.iss}`,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
// 3: The Client MUST validate that the aud (audience) Claim contains its client_id value registered at the Issuer identified by the iss (issuer) Claim as an audience. The aud (audience) Claim MAY contain an array with more than one element. The ID Token MUST be rejected if the ID Token does not list the Client as a valid audience, or if it contains additional audiences not trusted by the Client.
|
|
240
|
+
|
|
241
|
+
// 6: If the ID Token is received via direct communication between the Client and the Token Endpoint (which it is in this flow), the TLS server validation MAY be used to validate the issuer in place of checking the token signature. The Client MUST validate the signature of all other ID Tokens according to JWS [JWS] using the algorithm specified in the JWT alg Header Parameter. The Client MUST use the keys provided by the Issuer.
|
|
242
|
+
|
|
243
|
+
// 9: The current time MUST be before the time represented by the exp Claim.
|
|
244
|
+
const currentTimeUnixSecond = new Date().getTime() / 1000;
|
|
245
|
+
if (idTokenPayload.exp && idTokenPayload.exp < currentTimeUnixSecond) {
|
|
246
|
+
return {
|
|
247
|
+
isValid: false,
|
|
248
|
+
reason: `Token expired (idTokenPayload exp) ${idTokenPayload.exp} < (currentTimeUnixSecond) ${currentTimeUnixSecond}`,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
// 10: The iat Claim can be used to reject tokens that were issued too far away from the current time, limiting the amount of time that nonces need to be stored to prevent attacks. The acceptable range is Client specific.
|
|
252
|
+
const timeInSevenDays = 60 * 60 * 24 * 7;
|
|
253
|
+
if (idTokenPayload.iat && idTokenPayload.iat + timeInSevenDays < currentTimeUnixSecond) {
|
|
254
|
+
return {
|
|
255
|
+
isValid: false,
|
|
256
|
+
reason: `Token is used from too long time (idTokenPayload iat + timeInSevenDays) ${idTokenPayload.iat + timeInSevenDays} < (currentTimeUnixSecond) ${currentTimeUnixSecond}`,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
// 11: If a nonce value was sent in the Authentication Request, a nonce Claim MUST be present and its value checked to verify that it is the same value as the one that was sent in the Authentication Request. The Client SHOULD check the nonce value for replay attacks. The precise method for detecting replay attacks is Client specific.
|
|
260
|
+
if (idTokenPayload.nonce && idTokenPayload.nonce !== nonce) {
|
|
261
|
+
return {
|
|
262
|
+
isValid: false,
|
|
263
|
+
reason: `Nonce does not match (idTokenPayload nonce) ${idTokenPayload.nonce} !== (nonce) ${nonce}`,
|
|
264
|
+
};
|
|
231
265
|
}
|
|
232
|
-
|
|
266
|
+
}
|
|
267
|
+
return { isValid: true, reason: '' };
|
|
233
268
|
};
|