@axa-fr/oidc-client 7.27.17 → 7.27.18
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 +35 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +208 -192
- package/dist/index.umd.cjs +2 -2
- package/dist/login.d.ts.map +1 -1
- package/dist/login.spec.d.ts +2 -0
- package/dist/login.spec.d.ts.map +1 -0
- package/dist/oidcStateError.d.ts +33 -0
- package/dist/oidcStateError.d.ts.map +1 -0
- package/dist/oidcStateError.spec.d.ts +2 -0
- package/dist/oidcStateError.spec.d.ts.map +1 -0
- package/dist/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/login.spec.ts +151 -0
- package/src/login.ts +23 -2
- package/src/oidcStateError.spec.ts +33 -0
- package/src/oidcStateError.ts +50 -0
- package/src/renewTokens.ts +13 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable, machine-readable codes for OIDC state / nonce failures occurring
|
|
3
|
+
* between the authorization redirect and the callback handling.
|
|
4
|
+
*
|
|
5
|
+
* These codes let consumers react to specific failure modes without having to
|
|
6
|
+
* pattern-match against error message strings.
|
|
7
|
+
*/
|
|
8
|
+
export const OidcStateErrorCode = {
|
|
9
|
+
/** No state was found in storage when handling the callback. */
|
|
10
|
+
STATE_MISSING: 'STATE_MISSING',
|
|
11
|
+
/** The state returned by the server does not match the stored one. */
|
|
12
|
+
STATE_MISMATCH: 'STATE_MISMATCH',
|
|
13
|
+
/** No nonce was found in storage when handling the callback / renewal. */
|
|
14
|
+
NONCE_MISSING: 'NONCE_MISSING',
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
// Companion type that mirrors the const above. This is the standard TS
|
|
18
|
+
// "string-enum-like" pattern; we intentionally reuse the same name so that
|
|
19
|
+
// `OidcStateErrorCode` works as both a value namespace and a type for
|
|
20
|
+
// consumers.
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
22
|
+
export type OidcStateErrorCode = (typeof OidcStateErrorCode)[keyof typeof OidcStateErrorCode];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Typed error thrown when the OIDC login state or nonce is missing,
|
|
26
|
+
* corrupted, or does not match the value returned by the authorization server.
|
|
27
|
+
*
|
|
28
|
+
* Consumers can use `instanceof OidcStateError` and inspect `code` instead of
|
|
29
|
+
* relying on the (unstable) error message text.
|
|
30
|
+
*/
|
|
31
|
+
export class OidcStateError extends Error {
|
|
32
|
+
readonly code: OidcStateErrorCode;
|
|
33
|
+
|
|
34
|
+
constructor(code: OidcStateErrorCode, message: string) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = 'OidcStateError';
|
|
37
|
+
this.code = code;
|
|
38
|
+
|
|
39
|
+
// Keep prototype chain intact when transpiled to ES5.
|
|
40
|
+
Object.setPrototypeOf(this, OidcStateError.prototype);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Type guard for {@link OidcStateError}. Useful in callers that want to react
|
|
46
|
+
* specifically to state/nonce failures.
|
|
47
|
+
*/
|
|
48
|
+
export const isOidcStateError = (value: unknown): value is OidcStateError => {
|
|
49
|
+
return value instanceof OidcStateError;
|
|
50
|
+
};
|
package/src/renewTokens.ts
CHANGED
|
@@ -446,6 +446,19 @@ const synchroniseTokensAsync =
|
|
|
446
446
|
);
|
|
447
447
|
|
|
448
448
|
if (tokenResponse.success) {
|
|
449
|
+
// Guard against a missing/corrupted nonce reaching id_token validation.
|
|
450
|
+
// Without this guard, accessing `nonce.nonce` would throw a TypeError
|
|
451
|
+
// when the underlying storage has been cleared (private mode, manual
|
|
452
|
+
// clearing, browser eviction). We prefer a defined SESSION_LOST result
|
|
453
|
+
// so silent renew stays non-throwing for consumers.
|
|
454
|
+
// See https://github.com/AxaFrance/oidc-client/issues/1678
|
|
455
|
+
if (!nonce || !nonce.nonce) {
|
|
456
|
+
updateTokens(null);
|
|
457
|
+
oidc.publishEvent(eventNames.refreshTokensAsync_error, {
|
|
458
|
+
message: 'refresh token: nonce missing from storage',
|
|
459
|
+
});
|
|
460
|
+
return { tokens: null, status: 'SESSION_LOST' };
|
|
461
|
+
}
|
|
449
462
|
const { isValid, reason } = isTokensOidcValid(
|
|
450
463
|
tokenResponse.data,
|
|
451
464
|
nonce.nonce,
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '7.27.
|
|
1
|
+
export default '7.27.18';
|