@axa-fr/oidc-client 7.27.18 → 7.29.1
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 +122 -4
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.spec.d.ts +2 -0
- package/dist/crypto.spec.d.ts.map +1 -0
- package/dist/events.d.ts +3 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/fetch.d.ts +2 -1
- package/dist/fetch.d.ts.map +1 -1
- package/dist/fetch.spec.d.ts +2 -0
- package/dist/fetch.spec.d.ts.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +918 -545
- package/dist/index.umd.cjs +2 -2
- package/dist/initWorker.d.ts +1 -0
- package/dist/initWorker.d.ts.map +1 -1
- package/dist/initWorkerAbortError.spec.d.ts +2 -0
- package/dist/initWorkerAbortError.spec.d.ts.map +1 -0
- package/dist/jwt.spec.d.ts +2 -0
- package/dist/jwt.spec.d.ts.map +1 -0
- package/dist/login.d.ts +3 -3
- package/dist/login.d.ts.map +1 -1
- package/dist/logout.d.ts.map +1 -1
- package/dist/oidc.d.ts +12 -2
- package/dist/oidc.d.ts.map +1 -1
- package/dist/oidcClient.d.ts +5 -1
- package/dist/oidcClient.d.ts.map +1 -1
- package/dist/oidcError.d.ts +57 -0
- package/dist/oidcError.d.ts.map +1 -0
- package/dist/oidcError.spec.d.ts +2 -0
- package/dist/oidcError.spec.d.ts.map +1 -0
- package/dist/oidcStateError.d.ts +7 -4
- package/dist/oidcStateError.d.ts.map +1 -1
- package/dist/par.spec.d.ts +2 -0
- package/dist/par.spec.d.ts.map +1 -0
- package/dist/parseTokens.d.ts +1 -1
- package/dist/parseTokens.d.ts.map +1 -1
- package/dist/pushedAuthorizationRequestError.d.ts +20 -0
- package/dist/pushedAuthorizationRequestError.d.ts.map +1 -0
- package/dist/pushedAuthorizationRequestError.spec.d.ts +2 -0
- package/dist/pushedAuthorizationRequestError.spec.d.ts.map +1 -0
- package/dist/renewTokens.d.ts +11 -0
- package/dist/renewTokens.d.ts.map +1 -1
- package/dist/renewTokensError.spec.d.ts +2 -0
- package/dist/renewTokensError.spec.d.ts.map +1 -0
- package/dist/requests.d.ts +21 -14
- package/dist/requests.d.ts.map +1 -1
- package/dist/silentLogin.d.ts +6 -4
- package/dist/silentLogin.d.ts.map +1 -1
- package/dist/silentLogin.spec.d.ts +2 -0
- package/dist/silentLogin.spec.d.ts.map +1 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/user.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/crypto.spec.ts +40 -0
- package/src/crypto.ts +9 -10
- package/src/events.ts +3 -0
- package/src/fetch.spec.ts +105 -0
- package/src/fetch.ts +39 -3
- package/src/index.ts +14 -1
- package/src/initWorker.ts +37 -17
- package/src/initWorkerAbortError.spec.ts +147 -0
- package/src/jwt.spec.ts +33 -0
- package/src/jwt.ts +1 -47
- package/src/login.spec.ts +34 -0
- package/src/login.ts +119 -14
- package/src/logout.spec.ts +58 -0
- package/src/logout.ts +46 -7
- package/src/oidc.ts +78 -16
- package/src/oidcClient.ts +8 -1
- package/src/oidcError.spec.ts +105 -0
- package/src/oidcError.ts +197 -0
- package/src/oidcStateError.spec.ts +18 -0
- package/src/oidcStateError.ts +29 -8
- package/src/par.spec.ts +232 -0
- package/src/parseTokens.spec.ts +2 -1
- package/src/parseTokens.ts +1 -1
- package/src/pushedAuthorizationRequestError.spec.ts +43 -0
- package/src/pushedAuthorizationRequestError.ts +50 -0
- package/src/renewTokens.ts +167 -29
- package/src/renewTokensError.spec.ts +116 -0
- package/src/requests.spec.ts +293 -4
- package/src/requests.ts +174 -8
- package/src/silentLogin.spec.ts +158 -0
- package/src/silentLogin.ts +36 -9
- package/src/types.ts +6 -0
- package/src/user.ts +71 -31
- package/src/version.ts +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"par.spec.d.ts","sourceRoot":"","sources":["../src/par.spec.ts"],"names":[],"mappings":""}
|
package/dist/parseTokens.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export interface OidcToken {
|
|
|
35
35
|
token_automatic_renew_mode?: TokenAutomaticRenewMode;
|
|
36
36
|
refresh_time_before_tokens_expiration_in_second?: number;
|
|
37
37
|
};
|
|
38
|
-
renewTokensAsync: (extras: StringMap) => Promise<
|
|
38
|
+
renewTokensAsync: (extras: StringMap) => Promise<Tokens | null | undefined>;
|
|
39
39
|
}
|
|
40
40
|
export declare const getValidTokenAsync: (oidc: OidcToken, waitMs?: number, numberWait?: number) => Promise<ValidToken>;
|
|
41
41
|
export declare const isTokensOidcValid: (tokens: any, nonce: any, oidcServerConfiguration: any) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseTokens.d.ts","sourceRoot":"","sources":["../src/parseTokens.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAQ7D,eAAO,MAAM,QAAQ,GAAI,SAAS,MAAM,QAC2C,CAAC;AAsBpF,MAAM,MAAM,MAAM,GAAG;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,GAAG,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB,EAAE,GAAG,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gCAAgC,EAAE,MAAM,CAAC;IACzC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,cAAc;;;;CAI1B,CAAC;AAkBF,eAAO,MAAM,SAAS,GAAI,WAAM,EAAE,cAAgB,EAAE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
|
|
3
|
+
readonly ENDPOINT_UNAVAILABLE: "ENDPOINT_UNAVAILABLE";
|
|
4
|
+
readonly REQUEST_FAILED: "REQUEST_FAILED";
|
|
5
|
+
readonly INVALID_RESPONSE: "INVALID_RESPONSE";
|
|
6
|
+
};
|
|
7
|
+
export type PushedAuthorizationRequestErrorCode = (typeof PushedAuthorizationRequestErrorCode)[keyof typeof PushedAuthorizationRequestErrorCode];
|
|
8
|
+
type PushedAuthorizationRequestErrorOptions = {
|
|
9
|
+
status?: number;
|
|
10
|
+
oauthError?: string;
|
|
11
|
+
oauthErrorDescription?: string;
|
|
12
|
+
cause?: unknown;
|
|
13
|
+
};
|
|
14
|
+
export declare class PushedAuthorizationRequestError extends OidcError {
|
|
15
|
+
readonly code: PushedAuthorizationRequestErrorCode;
|
|
16
|
+
constructor(code: PushedAuthorizationRequestErrorCode, message: string, options?: PushedAuthorizationRequestErrorOptions);
|
|
17
|
+
}
|
|
18
|
+
export declare const isPushedAuthorizationRequestError: (value: unknown) => value is PushedAuthorizationRequestError;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=pushedAuthorizationRequestError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pushedAuthorizationRequestError.d.ts","sourceRoot":"","sources":["../src/pushedAuthorizationRequestError.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EAEV,MAAM,gBAAgB,CAAC;AAExB,eAAO,MAAM,mCAAmC;;;;CAItC,CAAC;AAGX,MAAM,MAAM,mCAAmC,GAC7C,CAAC,OAAO,mCAAmC,CAAC,CAAC,MAAM,OAAO,mCAAmC,CAAC,CAAC;AAEjG,KAAK,sCAAsC,GAAG;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,qBAAa,+BAAgC,SAAQ,SAAS;IAC5D,SAAiB,IAAI,EAAE,mCAAmC,CAAC;gBAGzD,IAAI,EAAE,mCAAmC,EACzC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,sCAA2C;CAcvD;AAED,eAAO,MAAM,iCAAiC,GAC5C,OAAO,OAAO,KACb,KAAK,IAAI,+BAEX,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pushedAuthorizationRequestError.spec.d.ts","sourceRoot":"","sources":["../src/pushedAuthorizationRequestError.spec.ts"],"names":[],"mappings":""}
|
package/dist/renewTokens.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { default as Oidc } from './oidc.js';
|
|
2
|
+
import { OidcError } from './oidcError.js';
|
|
2
3
|
import { Tokens } from './parseTokens.js';
|
|
3
4
|
import { OidcConfiguration, StringMap } from './types.js';
|
|
5
|
+
export type RenewTokensResult = {
|
|
6
|
+
tokens: Tokens | null;
|
|
7
|
+
status: string | null;
|
|
8
|
+
error?: OidcError;
|
|
9
|
+
};
|
|
10
|
+
export declare function renewTokensAndStartTimerResultAsync(oidc: any, forceRefresh?: boolean, extras?: StringMap, scope?: string): Promise<{
|
|
11
|
+
tokens: any;
|
|
12
|
+
status: string | null;
|
|
13
|
+
error?: OidcError;
|
|
14
|
+
}>;
|
|
4
15
|
export declare function renewTokensAndStartTimerAsync(oidc: any, forceRefresh?: boolean, extras?: StringMap, scope?: string): Promise<any>;
|
|
5
16
|
export declare const autoRenewTokens: (oidc: Oidc, expiresAt: any, extras?: StringMap, scope?: string) => NodeJS.Timeout;
|
|
6
17
|
export declare const synchroniseTokensStatus: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renewTokens.d.ts","sourceRoot":"","sources":["../src/renewTokens.ts"],"names":[],"mappings":"AAGA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAiD,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAIzF,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAA2B,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"renewTokens.d.ts","sourceRoot":"","sources":["../src/renewTokens.ts"],"names":[],"mappings":"AAGA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAKL,SAAS,EAEV,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAiD,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAIzF,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAA2B,MAAM,YAAY,CAAC;AAEnF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AA4DF,wBAAsB,mCAAmC,CACvD,IAAI,KAAA,EACJ,YAAY,UAAQ,EACpB,MAAM,GAAE,SAAgB,EACxB,KAAK,GAAE,MAAa;;YAlEZ,MAAM,GAAG,IAAI;YACb,SAAS;GAwGlB;AAED,wBAAsB,6BAA6B,CACjD,IAAI,KAAA,EACJ,YAAY,UAAQ,EACpB,MAAM,GAAE,SAAgB,EACxB,KAAK,GAAE,MAAa,gBAIrB;AAED,eAAO,MAAM,eAAe,GAC1B,MAAM,IAAI,EACV,cAAS,EACT,SAAQ,SAAgB,EACxB,QAAO,MAAa,mBAarB,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;;;;;;;CAUnC,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC7B,MAAM,IAAI,MAET,eAAe,iBAAiB,EAChC,mBAAmB,MAAM,EACzB,eAAe,MAAM,EACrB,sBAAoB;;;;;;;;;;EA2FrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renewTokensError.spec.d.ts","sourceRoot":"","sources":["../src/renewTokensError.spec.ts"],"names":[],"mappings":""}
|
package/dist/requests.d.ts
CHANGED
|
@@ -8,27 +8,34 @@ export declare const TOKEN_TYPE: {
|
|
|
8
8
|
};
|
|
9
9
|
export declare const performRevocationRequestAsync: (fetch: any) => (url: any, token: any, token_type: string, client_id: any, extras?: StringMap, timeoutMs?: number) => Promise<{
|
|
10
10
|
success: boolean;
|
|
11
|
+
status: number;
|
|
12
|
+
oauthError: any;
|
|
13
|
+
oauthErrorDescription: any;
|
|
14
|
+
} | {
|
|
15
|
+
success: boolean;
|
|
16
|
+
status: number;
|
|
17
|
+
oauthError?: undefined;
|
|
18
|
+
oauthErrorDescription?: undefined;
|
|
11
19
|
}>;
|
|
12
20
|
type PerformTokenRequestResponse = {
|
|
13
21
|
success: boolean;
|
|
14
22
|
status?: number;
|
|
15
23
|
data?: any;
|
|
16
24
|
demonstratingProofOfPossessionNonce?: string;
|
|
25
|
+
oauthError?: string;
|
|
26
|
+
oauthErrorDescription?: string;
|
|
27
|
+
};
|
|
28
|
+
export type PushedAuthorizationRequestResponse = {
|
|
29
|
+
request_uri: string;
|
|
30
|
+
expires_in: number;
|
|
17
31
|
};
|
|
32
|
+
export declare const performPushedAuthorizationRequestAsync: (fetch: Fetch) => (url: string, details: StringMap, timeoutMs?: number) => Promise<PushedAuthorizationRequestResponse>;
|
|
18
33
|
export declare const performTokenRequestAsync: (fetch: Fetch) => (url: string, details: any, extras: any, oldTokens: any, headersExtras: {}, tokenRenewMode: string, timeoutMs?: number) => Promise<PerformTokenRequestResponse>;
|
|
19
|
-
export declare const performAuthorizationRequestAsync: (storage: any, oidcLocation: ILOidcLocation) => (url: any, extras: StringMap
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
success: boolean;
|
|
26
|
-
data: {
|
|
27
|
-
state: any;
|
|
28
|
-
tokens: import('./parseTokens.js').Tokens;
|
|
29
|
-
demonstratingProofOfPossessionNonce: string;
|
|
30
|
-
};
|
|
31
|
-
status?: undefined;
|
|
32
|
-
}>;
|
|
34
|
+
export declare const performAuthorizationRequestAsync: (storage: any, oidcLocation: ILOidcLocation) => (url: any, extras: StringMap, pushedAuthorizationRequest?: {
|
|
35
|
+
endpoint: string;
|
|
36
|
+
fetch: Fetch;
|
|
37
|
+
timeoutMs?: number;
|
|
38
|
+
}) => Promise<void>;
|
|
39
|
+
export declare const performFirstTokenRequestAsync: (storage: any) => (url: any, formBodyExtras: any, headersExtras: any, tokenRenewMode: string, timeoutMs?: number, shouldPreserveLoginStateForDpopRetry?: boolean) => Promise<PerformTokenRequestResponse>;
|
|
33
40
|
export {};
|
|
34
41
|
//# sourceMappingURL=requests.d.ts.map
|
package/dist/requests.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../src/requests.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,qCAAqC,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../src/requests.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,qCAAqC,EAAE,MAAM,WAAW,CAAC;AAMlE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG9C,eAAO,MAAM,eAAe,GAC1B,UAAK,MAEH,iBAAiB,MAAM,EACvB,wBAA+B,EAC/B,iBAA+B,EAC/B,kBAAiB,KAChB,OAAO,CAAC,qCAAqC,CAkB/C,CAAC;AA6BJ,eAAO,MAAM,UAAU;;;CAGtB,CAAC;AAEF,eAAO,MAAM,6BAA6B,GACxC,UAAK,MAEH,QAAG,EACH,UAAK,EACL,kBAAqC,EACrC,cAAS,EACT,SAAQ,SAAc,EACtB,kBAAiB;;;;;;;;;;EA8ClB,CAAC;AAEJ,KAAK,2BAA2B,GAAG;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,mCAAmC,CAAC,EAAE,MAAM,CAAC;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAUF,eAAO,MAAM,sCAAsC,GAChD,OAAO,KAAK,MAEX,KAAK,MAAM,EACX,SAAS,SAAS,EAClB,kBAAiB,KAChB,OAAO,CAAC,kCAAkC,CAwE5C,CAAC;AAEJ,eAAO,MAAM,wBAAwB,GAClC,OAAO,KAAK,MAEX,KAAK,MAAM,EACX,YAAO,EACP,WAAM,EACN,cAAS,EACT,iBAAkB,EAClB,gBAAgB,MAAM,EACtB,kBAAiB,KAChB,OAAO,CAAC,2BAA2B,CAyDrC,CAAC;AAEJ,eAAO,MAAM,gCAAgC,GAC1C,SAAS,GAAG,EAAE,cAAc,cAAc,MAEzC,QAAG,EACH,QAAQ,SAAS,EACjB,6BAA6B;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,kBAkCF,CAAC;AAGJ,eAAO,MAAM,6BAA6B,GACvC,SAAS,GAAG,MAEX,QAAG,EACH,mBAAc,EACd,kBAAa,EACb,gBAAgB,MAAM,EACtB,kBAAiB,EACjB,8CAA4C,KAC3C,OAAO,CAAC,2BAA2B,CA0DrC,CAAC"}
|
package/dist/silentLogin.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { OidcError, OidcErrorPhase } from './oidcError.js';
|
|
1
2
|
import { Tokens } from './parseTokens.js';
|
|
2
3
|
import { OidcConfiguration, StringMap } from './types.js';
|
|
3
4
|
export type SilentLoginResponse = {
|
|
4
|
-
tokens: Tokens;
|
|
5
|
-
sessionState: string;
|
|
6
|
-
error
|
|
5
|
+
tokens: Tokens | null;
|
|
6
|
+
sessionState: string | null;
|
|
7
|
+
error?: string;
|
|
8
|
+
oidcError?: OidcError;
|
|
7
9
|
};
|
|
8
10
|
export type PublishEventFunction = (eventName: string, eventData: any) => void;
|
|
9
|
-
export declare const _silentLoginAsync: (configurationName: string, configuration: OidcConfiguration, publishEvent: PublishEventFunction) => (extras?: StringMap, state?: string, scope?: string) => Promise<SilentLoginResponse>;
|
|
11
|
+
export declare const _silentLoginAsync: (configurationName: string, configuration: OidcConfiguration, publishEvent: PublishEventFunction, phase?: OidcErrorPhase) => (extras?: StringMap, state?: string, scope?: string) => Promise<SilentLoginResponse>;
|
|
10
12
|
export declare const defaultSilentLoginAsync: (window: any, configurationName: any, configuration: OidcConfiguration, publishEvent: (string: any, any: any) => void, oidc: any) => (extras?: StringMap, scope?: string) => Promise<unknown>;
|
|
11
13
|
export default defaultSilentLoginAsync;
|
|
12
14
|
//# sourceMappingURL=silentLogin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"silentLogin.d.ts","sourceRoot":"","sources":["../src/silentLogin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC1D,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"silentLogin.d.ts","sourceRoot":"","sources":["../src/silentLogin.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,SAAS,EAET,cAAc,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC1D,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,IAAI,CAAC;AAE/E,eAAO,MAAM,iBAAiB,GAE1B,mBAAmB,MAAM,EACzB,eAAe,iBAAiB,EAChC,cAAc,oBAAoB,EAClC,QAAO,cAAwB,MAG/B,SAAQ,SAAgB,EACxB,QAAO,MAAa,EACpB,QAAO,MAAa,KACnB,OAAO,CAAC,mBAAmB,CA2H7B,CAAC;AAEJ,eAAO,MAAM,uBAAuB,GAEhC,WAAM,EACN,sBAAiB,EACjB,eAAe,iBAAiB,EAChC,cAAc,CAAC,MAAM,KAAA,EAAE,GAAG,KAAA,KAAK,IAAI,EACnC,MAAM,GAAG,MAEV,SAAQ,SAAgB,EAAE,QAAO,MAAkB,qBA6CnD,CAAC;AAEJ,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"silentLogin.spec.d.ts","sourceRoot":"","sources":["../src/silentLogin.spec.ts"],"names":[],"mappings":""}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type Fetch = typeof window.fetch;
|
|
2
2
|
export type LogoutToken = 'access_token' | 'refresh_token';
|
|
3
|
+
export type PushedAuthorizationRequestMode = 'disabled' | 'auto' | 'required';
|
|
3
4
|
export type ServiceWorkerUpdateRequireCallback = (registration: any, stopKeepAlive: () => void) => Promise<void>;
|
|
4
5
|
export type ServiceWorkerRegister = (serviceWorkerRelativeUrl: string) => Promise<ServiceWorkerRegistration>;
|
|
5
6
|
export type ServiceWorkerActivate = () => boolean;
|
|
@@ -21,6 +22,8 @@ export type OidcConfiguration = {
|
|
|
21
22
|
refresh_time_before_tokens_expiration_in_second?: number;
|
|
22
23
|
token_automatic_renew_mode?: TokenAutomaticRenewMode;
|
|
23
24
|
token_request_timeout?: number;
|
|
25
|
+
par?: PushedAuthorizationRequestMode;
|
|
26
|
+
par_request_timeout?: number;
|
|
24
27
|
service_worker_relative_url?: string;
|
|
25
28
|
service_worker_register?: ServiceWorkerRegister;
|
|
26
29
|
service_worker_keep_alive_path?: string;
|
|
@@ -53,6 +56,8 @@ export interface AuthorityConfiguration {
|
|
|
53
56
|
authorization_endpoint: string;
|
|
54
57
|
token_endpoint: string;
|
|
55
58
|
revocation_endpoint: string;
|
|
59
|
+
pushed_authorization_request_endpoint?: string;
|
|
60
|
+
require_pushed_authorization_requests?: boolean;
|
|
56
61
|
end_session_endpoint?: string;
|
|
57
62
|
userinfo_endpoint?: string;
|
|
58
63
|
check_session_iframe?: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG,OAAO,MAAM,CAAC,KAAK,CAAC;AAExC,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG,eAAe,CAAC;AAE3D,MAAM,MAAM,kCAAkC,GAAG,CAC/C,YAAY,EAAE,GAAG,EACjB,aAAa,EAAE,MAAM,IAAI,KACtB,OAAO,CAAC,IAAI,CAAC,CAAC;AACnB,MAAM,MAAM,qBAAqB,GAAG,CAClC,wBAAwB,EAAE,MAAM,KAC7B,OAAO,CAAC,yBAAyB,CAAC,CAAC;AACxC,MAAM,MAAM,qBAAqB,GAAG,MAAM,OAAO,CAAC;AAElD,oBAAY,uBAAuB;IACjC,8BAA8B,oCAAoC;IAClE,8BAA8B,mCAAmC;CAClE;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,CAAC,E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;IAC7D,eAAe,EAAE,mBAAmB,CAAC;IACrC,kBAAkB,EACd,mBAAmB,GACnB,qBAAqB,GACrB,iBAAiB,GACjB,gBAAgB,GAChB,eAAe,CAAC;IACpB,aAAa,EAAE,mBAAmB,GAAG,YAAY,GAAG,WAAW,CAAC;IAChE,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,sBAAsB;IACrC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,qCAAqC,CAAC,EAAE,MAAM,CAAC;IAC/C,qCAAqC,CAAC,EAAE,OAAO,CAAC;IAChD,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
package/dist/user.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../src/user.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../src/user.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,QAAQ,CAAC;AAU1B,eAAO,MAAM,aAAa,GACvB,MAAM,IAAI,MACJ,iBAAe,EAAE,2CAAyC,iBAkEhE,CAAC"}
|
package/dist/version.d.ts
CHANGED
package/dist/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"wBAAe,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"wBAAe,QAAQ;AAAvB,wBAAwB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axa-fr/oidc-client",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.29.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.umd.cjs",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"url": "https://github.com/AxaFrance/oidc-client.git"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@axa-fr/oidc-client-service-worker": "7.
|
|
23
|
+
"@axa-fr/oidc-client-service-worker": "7.29.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@testing-library/dom": "10.4.1",
|
|
@@ -50,7 +50,6 @@
|
|
|
50
50
|
"copy-service-worker": "cpy ./node_modules/@axa-fr/oidc-client-service-worker/dist/OidcTrustedDomains.js ./node_modules/@axa-fr/oidc-client-service-worker/dist/OidcServiceWorker.js ./dist",
|
|
51
51
|
"build": "tsc && vite build",
|
|
52
52
|
"test": "vitest --root . --coverage",
|
|
53
|
-
"prepare": "pnpm run clean && pnpm run copy-service-worker && pnpm run build",
|
|
54
53
|
"postinstall": "echo 'WARNING keep sink OidcServiceWorker.js version file'"
|
|
55
54
|
},
|
|
56
55
|
"license": "MIT",
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { generateRandom } from './crypto';
|
|
4
|
+
|
|
5
|
+
describe('generateRandom', () => {
|
|
6
|
+
const originalCrypto = Object.getOwnPropertyDescriptor(globalThis, 'crypto');
|
|
7
|
+
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
if (originalCrypto) {
|
|
10
|
+
Object.defineProperty(globalThis, 'crypto', originalCrypto);
|
|
11
|
+
} else {
|
|
12
|
+
delete (globalThis as { crypto?: Crypto }).crypto;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('uses Web Crypto to generate authentication-related random values', () => {
|
|
17
|
+
const getRandomValues = vi.fn((buffer: Uint8Array) => {
|
|
18
|
+
buffer.fill(1);
|
|
19
|
+
return buffer;
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(globalThis, 'crypto', {
|
|
22
|
+
configurable: true,
|
|
23
|
+
value: { getRandomValues },
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
expect(generateRandom(4)).toBe('BBBB');
|
|
27
|
+
expect(getRandomValues).toHaveBeenCalledOnce();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('does not fall back to a non-cryptographic random source', () => {
|
|
31
|
+
Object.defineProperty(globalThis, 'crypto', {
|
|
32
|
+
configurable: true,
|
|
33
|
+
value: undefined,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
expect(() => generateRandom(16)).toThrow(
|
|
37
|
+
'Web Crypto API is unavailable; secure random values cannot be generated.',
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
});
|
package/src/crypto.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { uint8ToUrlBase64 } from './jwt';
|
|
2
2
|
|
|
3
|
+
const getWebCrypto = () => (typeof globalThis !== 'undefined' ? globalThis.crypto : undefined);
|
|
4
|
+
|
|
3
5
|
const cryptoInfo = () => {
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
+
const webCrypto = getWebCrypto();
|
|
7
|
+
const hasCrypto = !!webCrypto;
|
|
8
|
+
const hasSubtleCrypto = !!webCrypto?.subtle;
|
|
6
9
|
return { hasCrypto, hasSubtleCrypto };
|
|
7
10
|
};
|
|
8
11
|
const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
@@ -18,15 +21,11 @@ const bufferToString = (buffer: Uint8Array) => {
|
|
|
18
21
|
|
|
19
22
|
export const generateRandom = (size: number) => {
|
|
20
23
|
const buffer = new Uint8Array(size);
|
|
21
|
-
const
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
} else {
|
|
25
|
-
// fall back to Math.random() if nothing else is available
|
|
26
|
-
for (let i = 0; i < size; i += 1) {
|
|
27
|
-
buffer[i] = (Math.random() * charset.length) | 0;
|
|
28
|
-
}
|
|
24
|
+
const webCrypto = getWebCrypto();
|
|
25
|
+
if (!webCrypto?.getRandomValues) {
|
|
26
|
+
throw new Error('Web Crypto API is unavailable; secure random values cannot be generated.');
|
|
29
27
|
}
|
|
28
|
+
webCrypto.getRandomValues(buffer);
|
|
30
29
|
return bufferToString(buffer);
|
|
31
30
|
};
|
|
32
31
|
|
package/src/events.ts
CHANGED
|
@@ -12,6 +12,7 @@ export const eventNames = {
|
|
|
12
12
|
loginCallbackAsync_error: 'loginCallbackAsync_error',
|
|
13
13
|
loginCallbackAsync_navigated: 'loginCallbackAsync_navigated',
|
|
14
14
|
loginCallbackAsync_navigation_error: 'loginCallbackAsync_navigation_error',
|
|
15
|
+
logoutAsync_error: 'logoutAsync_error',
|
|
15
16
|
refreshTokensAsync_begin: 'refreshTokensAsync_begin',
|
|
16
17
|
refreshTokensAsync: 'refreshTokensAsync',
|
|
17
18
|
refreshTokensAsync_end: 'refreshTokensAsync_end',
|
|
@@ -24,6 +25,8 @@ export const eventNames = {
|
|
|
24
25
|
silentLoginAsync: 'silentLoginAsync',
|
|
25
26
|
silentLoginAsync_end: 'silentLoginAsync_end',
|
|
26
27
|
silentLoginAsync_error: 'silentLoginAsync_error',
|
|
28
|
+
userInfoAsync_error: 'userInfoAsync_error',
|
|
29
|
+
apiRequest_error: 'apiRequest_error',
|
|
27
30
|
syncTokensAsync_begin: 'syncTokensAsync_begin',
|
|
28
31
|
syncTokensAsync_lock_not_available: 'syncTokensAsync_lock_not_available',
|
|
29
32
|
syncTokensAsync_end: 'syncTokensAsync_end',
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { fetchWithTokens } from './fetch';
|
|
4
|
+
import { OidcError, OidcErrorCode } from './oidcError';
|
|
5
|
+
import { Tokens } from './parseTokens';
|
|
6
|
+
import { userInfoAsync } from './user';
|
|
7
|
+
|
|
8
|
+
const buildOidc = () => {
|
|
9
|
+
const tokens = {
|
|
10
|
+
accessToken: 'access-token',
|
|
11
|
+
expiresAt: Date.now() / 1000 + 3600,
|
|
12
|
+
issuedAt: Date.now() / 1000,
|
|
13
|
+
} as Tokens;
|
|
14
|
+
const storage = {
|
|
15
|
+
'oidc.default': JSON.stringify({ tokens }),
|
|
16
|
+
} as unknown as Storage;
|
|
17
|
+
const events: Array<{ name: string; data: unknown }> = [];
|
|
18
|
+
const oidc: any = {
|
|
19
|
+
configuration: {
|
|
20
|
+
authority: 'https://issuer.example.com',
|
|
21
|
+
client_id: 'client',
|
|
22
|
+
redirect_uri: 'https://client.example.com/callback',
|
|
23
|
+
scope: 'openid',
|
|
24
|
+
storage,
|
|
25
|
+
token_automatic_renew_mode: 'AutomaticBeforeTokenExpiration',
|
|
26
|
+
refresh_time_before_tokens_expiration_in_second: 30,
|
|
27
|
+
},
|
|
28
|
+
configurationName: 'default',
|
|
29
|
+
initAsync: vi.fn(async () => ({
|
|
30
|
+
userInfoEndpoint: 'https://issuer.example.com/userinfo',
|
|
31
|
+
})),
|
|
32
|
+
publishEvent: (name: string, data: unknown) => events.push({ name, data }),
|
|
33
|
+
renewTokensAsync: vi.fn(),
|
|
34
|
+
tokens,
|
|
35
|
+
userInfo: null,
|
|
36
|
+
};
|
|
37
|
+
return { events, oidc };
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
vi.unstubAllGlobals();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('fetchWithTokens typed errors', () => {
|
|
45
|
+
it('returns a DPoP challenge response unchanged and publishes an api_request error', async () => {
|
|
46
|
+
const { events, oidc } = buildOidc();
|
|
47
|
+
const response = new Response('', {
|
|
48
|
+
status: 401,
|
|
49
|
+
headers: {
|
|
50
|
+
'DPoP-Nonce': 'nonce',
|
|
51
|
+
'WWW-Authenticate': 'DPoP error="use_dpop_nonce"',
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
const fetchMock = vi.fn(async () => response);
|
|
55
|
+
|
|
56
|
+
const result = await fetchWithTokens(
|
|
57
|
+
fetchMock as any,
|
|
58
|
+
oidc,
|
|
59
|
+
)('https://api.example.com/resource');
|
|
60
|
+
|
|
61
|
+
expect(result).toBe(response);
|
|
62
|
+
expect(events.find(event => event.name === 'apiRequest_error')?.data).toMatchObject({
|
|
63
|
+
code: OidcErrorCode.DPOP_NONCE_REQUIRED,
|
|
64
|
+
phase: 'api_request',
|
|
65
|
+
retryable: true,
|
|
66
|
+
status: 401,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('wraps a rejected fetch as NETWORK_ERROR', async () => {
|
|
71
|
+
const { events, oidc } = buildOidc();
|
|
72
|
+
const cause = new TypeError('Failed to fetch');
|
|
73
|
+
const fetchMock = vi.fn(async () => {
|
|
74
|
+
throw cause;
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
await expect(
|
|
78
|
+
fetchWithTokens(fetchMock as any, oidc)('https://api.example.com/resource'),
|
|
79
|
+
).rejects.toMatchObject({
|
|
80
|
+
code: OidcErrorCode.NETWORK_ERROR,
|
|
81
|
+
phase: 'api_request',
|
|
82
|
+
retryable: true,
|
|
83
|
+
cause,
|
|
84
|
+
});
|
|
85
|
+
expect(events.find(event => event.name === 'apiRequest_error')?.data).toBeInstanceOf(OidcError);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('userInfoAsync typed errors', () => {
|
|
90
|
+
it('keeps returning null on HTTP failure and publishes a userinfo error', async () => {
|
|
91
|
+
const { events, oidc } = buildOidc();
|
|
92
|
+
vi.stubGlobal(
|
|
93
|
+
'fetch',
|
|
94
|
+
vi.fn(async () => new Response('', { status: 503 })),
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
await expect(userInfoAsync(oidc)(true)).resolves.toBeNull();
|
|
98
|
+
expect(events.find(event => event.name === 'userInfoAsync_error')?.data).toMatchObject({
|
|
99
|
+
code: OidcErrorCode.REQUEST_FAILED,
|
|
100
|
+
phase: 'userinfo',
|
|
101
|
+
retryable: true,
|
|
102
|
+
status: 503,
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
package/src/fetch.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { eventNames } from './events';
|
|
2
|
+
import Oidc from './oidc';
|
|
3
|
+
import { createNetworkError, OidcError, OidcErrorCode, OidcErrorPhase } from './oidcError';
|
|
2
4
|
import { getValidTokenAsync, OidcToken } from './parseTokens';
|
|
3
5
|
import { syncTokensInfoAsync } from './renewTokens';
|
|
4
6
|
import { Fetch } from './types';
|
|
5
7
|
|
|
6
8
|
// @ts-ignore
|
|
7
9
|
export const fetchWithTokens =
|
|
8
|
-
(
|
|
10
|
+
(
|
|
11
|
+
fetch: Fetch,
|
|
12
|
+
oidc: Oidc,
|
|
13
|
+
demonstrating_proof_of_possession: boolean = false,
|
|
14
|
+
phase: OidcErrorPhase = 'api_request',
|
|
15
|
+
): Fetch =>
|
|
9
16
|
async (...params: Parameters<Fetch>): Promise<Response> => {
|
|
10
17
|
const [url, options, ...rest] = params;
|
|
11
18
|
const optionTmp = options ? { ...options } : { method: 'GET' };
|
|
@@ -62,5 +69,34 @@ export const fetchWithTokens =
|
|
|
62
69
|
}
|
|
63
70
|
}
|
|
64
71
|
const newOptions = { ...optionTmp, headers };
|
|
65
|
-
|
|
72
|
+
let response: Response;
|
|
73
|
+
try {
|
|
74
|
+
response = await fetch(url, newOptions, ...rest);
|
|
75
|
+
} catch (cause) {
|
|
76
|
+
const error = createNetworkError(cause, phase);
|
|
77
|
+
if (phase === 'api_request') {
|
|
78
|
+
oidc.publishEvent(eventNames.apiRequest_error, error);
|
|
79
|
+
}
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (
|
|
84
|
+
!response.ok &&
|
|
85
|
+
response.headers?.has('DPoP-Nonce') &&
|
|
86
|
+
(response.status === 400 ||
|
|
87
|
+
response.status === 401 ||
|
|
88
|
+
response.headers.get('WWW-Authenticate')?.includes('use_dpop_nonce'))
|
|
89
|
+
) {
|
|
90
|
+
const error = new OidcError(OidcErrorCode.DPOP_NONCE_REQUIRED, 'DPoP nonce required', {
|
|
91
|
+
phase,
|
|
92
|
+
retryable: true,
|
|
93
|
+
status: response.status,
|
|
94
|
+
oauthError: 'use_dpop_nonce',
|
|
95
|
+
});
|
|
96
|
+
if (phase === 'api_request') {
|
|
97
|
+
oidc.publishEvent(eventNames.apiRequest_error, error);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return response;
|
|
66
102
|
};
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,8 @@ export { OidcLocation } from './location.js';
|
|
|
5
5
|
export { getFetchDefault } from './oidc.js';
|
|
6
6
|
export type { OidcUserInfo } from './oidcClient.js';
|
|
7
7
|
export { OidcClient } from './oidcClient.js';
|
|
8
|
+
export type { OidcErrorOptions, OidcErrorPhase } from './oidcError.js';
|
|
9
|
+
export { isOidcError, OidcError, OidcErrorCode } from './oidcError.js';
|
|
8
10
|
export { isOidcStateError, OidcStateError, OidcStateErrorCode } from './oidcStateError.js';
|
|
9
11
|
export type { Tokens } from './parseTokens.js';
|
|
10
12
|
export { TokenRenewMode } from './parseTokens.js';
|
|
@@ -26,6 +28,17 @@ export {
|
|
|
26
28
|
SW_CONTROLLER_CHANGE_RELOAD_COUNT_KEY,
|
|
27
29
|
TOKEN_PLACEHOLDERS,
|
|
28
30
|
} from './protocol.js';
|
|
31
|
+
export {
|
|
32
|
+
isPushedAuthorizationRequestError,
|
|
33
|
+
PushedAuthorizationRequestError,
|
|
34
|
+
PushedAuthorizationRequestErrorCode,
|
|
35
|
+
} from './pushedAuthorizationRequestError.js';
|
|
29
36
|
export { getParseQueryStringFromLocation, getPath } from './route-utils';
|
|
30
|
-
export type {
|
|
37
|
+
export type {
|
|
38
|
+
AuthorityConfiguration,
|
|
39
|
+
Fetch,
|
|
40
|
+
OidcConfiguration,
|
|
41
|
+
PushedAuthorizationRequestMode,
|
|
42
|
+
StringMap,
|
|
43
|
+
} from './types.js';
|
|
31
44
|
export { TokenAutomaticRenewMode } from './types.js';
|
package/src/initWorker.ts
CHANGED
|
@@ -172,7 +172,18 @@ let controllerChangeReloading = false;
|
|
|
172
172
|
// Cache registration promises by URL so that navigator.serviceWorker.register (or a custom
|
|
173
173
|
// service_worker_register) is called at most once per JavaScript session (page lifetime),
|
|
174
174
|
// regardless of how many times initWorkerAsync is invoked.
|
|
175
|
-
const registrationCache = new Map<string, Promise<ServiceWorkerRegistration>>();
|
|
175
|
+
export const registrationCache = new Map<string, Promise<ServiceWorkerRegistration>>();
|
|
176
|
+
|
|
177
|
+
// AbortError surfaces during transient lifecycle events (e.g. iOS Safari tab shutdown or
|
|
178
|
+
// backgrounding) and does not represent a genuine configuration problem. We treat it as
|
|
179
|
+
// non-fatal, clear the cache entry so future calls can retry, and fall back to the
|
|
180
|
+
// non–service-worker path by returning null from initWorkerAsync.
|
|
181
|
+
const isAbortError = (error: unknown): boolean => {
|
|
182
|
+
if (error instanceof DOMException) {
|
|
183
|
+
return error.name === 'AbortError';
|
|
184
|
+
}
|
|
185
|
+
return (error as { name?: string } | null)?.name === 'AbortError';
|
|
186
|
+
};
|
|
176
187
|
|
|
177
188
|
// Session-level guard to prevent infinite reload loops caused by SW update cycles.
|
|
178
189
|
// The controllerchange listener triggers a page reload, but after reload the module-level
|
|
@@ -229,25 +240,34 @@ export const initWorkerAsync = async (
|
|
|
229
240
|
|
|
230
241
|
const swUrl = `${serviceWorkerRelativeUrl}?v=${codeVersion}`;
|
|
231
242
|
|
|
243
|
+
const cacheKey = configuration.service_worker_register ? serviceWorkerRelativeUrl : swUrl;
|
|
244
|
+
|
|
245
|
+
if (!registrationCache.has(cacheKey)) {
|
|
246
|
+
registrationCache.set(
|
|
247
|
+
cacheKey,
|
|
248
|
+
configuration.service_worker_register
|
|
249
|
+
? configuration.service_worker_register(serviceWorkerRelativeUrl)
|
|
250
|
+
: navigator.serviceWorker.register(swUrl, {
|
|
251
|
+
updateViaCache: 'none',
|
|
252
|
+
}),
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
232
256
|
let registration: ServiceWorkerRegistration = null as any;
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
registrationCache.set(
|
|
244
|
-
swUrl,
|
|
245
|
-
navigator.serviceWorker.register(swUrl, {
|
|
246
|
-
updateViaCache: 'none',
|
|
247
|
-
}),
|
|
257
|
+
try {
|
|
258
|
+
registration = await registrationCache.get(cacheKey)!;
|
|
259
|
+
} catch (error) {
|
|
260
|
+
if (isAbortError(error)) {
|
|
261
|
+
// Drop the rejected promise so a later call can attempt registration again
|
|
262
|
+
// once the browser is in a stable state (e.g. tab is foregrounded again).
|
|
263
|
+
registrationCache.delete(cacheKey);
|
|
264
|
+
console.warn(
|
|
265
|
+
'oidc-client: service worker registration was aborted (likely tab shutdown or backgrounding); falling back to non–service-worker mode.',
|
|
266
|
+
error,
|
|
248
267
|
);
|
|
268
|
+
return null;
|
|
249
269
|
}
|
|
250
|
-
|
|
270
|
+
throw error;
|
|
251
271
|
}
|
|
252
272
|
|
|
253
273
|
const versionMismatchKey = `oidc.sw.version_mismatch_reload.${configurationName}`;
|