oidc-spa 7.2.0 → 7.2.2
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/backend.js.map +1 -1
- package/core/AuthResponse.js.map +1 -1
- package/core/Oidc.js.map +1 -1
- package/core/OidcInitializationError.js.map +1 -1
- package/core/OidcMetadata.js.map +1 -1
- package/core/StateData.js.map +1 -1
- package/core/configId.js.map +1 -1
- package/core/createOidc.js +1 -1
- package/core/createOidc.js.map +1 -1
- package/core/diagnostic.js.map +1 -1
- package/core/evtIsUserActive.js.map +1 -1
- package/core/handleOidcCallback.js.map +1 -1
- package/core/iframeMessageProtection.js.map +1 -1
- package/core/index.js.map +1 -1
- package/core/initialLocationHref.js.map +1 -1
- package/core/isNewBrowserSession.js.map +1 -1
- package/core/loginOrGoToAuthServer.js.map +1 -1
- package/core/loginPropagationToOtherTabs.js.map +1 -1
- package/core/loginSilent.js.map +1 -1
- package/core/logoutPropagationToOtherTabs.js.map +1 -1
- package/core/oidcClientTsUserToTokens.js.map +1 -1
- package/core/ongoingLoginOrRefreshProcesses.js.map +1 -1
- package/core/persistedAuthState.js.map +1 -1
- package/entrypoint.js.map +1 -1
- package/esm/core/AuthResponse.js +2 -2
- package/esm/core/AuthResponse.js.map +1 -1
- package/esm/core/Oidc.d.ts +1 -1
- package/esm/core/Oidc.js.map +1 -1
- package/esm/core/OidcInitializationError.js.map +1 -1
- package/esm/core/OidcMetadata.js +2 -2
- package/esm/core/OidcMetadata.js.map +1 -1
- package/esm/core/StateData.js +3 -3
- package/esm/core/StateData.js.map +1 -1
- package/esm/core/configId.js.map +1 -1
- package/esm/core/createOidc.d.ts +2 -2
- package/esm/core/createOidc.js +33 -33
- package/esm/core/createOidc.js.map +1 -1
- package/esm/core/diagnostic.d.ts +1 -1
- package/esm/core/diagnostic.js +4 -4
- package/esm/core/diagnostic.js.map +1 -1
- package/esm/core/evtIsUserActive.d.ts +1 -1
- package/esm/core/evtIsUserActive.js +5 -5
- package/esm/core/evtIsUserActive.js.map +1 -1
- package/esm/core/handleOidcCallback.d.ts +2 -2
- package/esm/core/handleOidcCallback.js +5 -5
- package/esm/core/handleOidcCallback.js.map +1 -1
- package/esm/core/iframeMessageProtection.d.ts +1 -1
- package/esm/core/iframeMessageProtection.js +3 -3
- package/esm/core/iframeMessageProtection.js.map +1 -1
- package/esm/core/index.d.ts +4 -4
- package/esm/core/index.js +4 -4
- package/esm/core/index.js.map +1 -1
- package/esm/core/initialLocationHref.js.map +1 -1
- package/esm/core/isNewBrowserSession.d.ts +1 -1
- package/esm/core/isNewBrowserSession.js.map +1 -1
- package/esm/core/loginOrGoToAuthServer.d.ts +2 -2
- package/esm/core/loginOrGoToAuthServer.js +6 -6
- package/esm/core/loginOrGoToAuthServer.js.map +1 -1
- package/esm/core/loginPropagationToOtherTabs.js +3 -3
- package/esm/core/loginPropagationToOtherTabs.js.map +1 -1
- package/esm/core/loginSilent.d.ts +2 -2
- package/esm/core/loginSilent.js +8 -8
- package/esm/core/loginSilent.js.map +1 -1
- package/esm/core/logoutPropagationToOtherTabs.js +3 -3
- package/esm/core/logoutPropagationToOtherTabs.js.map +1 -1
- package/esm/core/oidcClientTsUserToTokens.d.ts +2 -2
- package/esm/core/oidcClientTsUserToTokens.js +4 -4
- package/esm/core/oidcClientTsUserToTokens.js.map +1 -1
- package/esm/core/ongoingLoginOrRefreshProcesses.js +3 -3
- package/esm/core/ongoingLoginOrRefreshProcesses.js.map +1 -1
- package/esm/core/persistedAuthState.js +2 -2
- package/esm/core/persistedAuthState.js.map +1 -1
- package/esm/entrypoint.js +3 -3
- package/esm/entrypoint.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +2 -2
- package/esm/index.js.map +1 -1
- package/esm/keycloak/index.d.ts +3 -3
- package/esm/keycloak/index.js +3 -3
- package/esm/keycloak/index.js.map +1 -1
- package/esm/keycloak/isKeycloak.js.map +1 -1
- package/esm/keycloak/keycloak-js/Keycloak.d.ts +1 -1
- package/esm/keycloak/keycloak-js/Keycloak.js +9 -9
- package/esm/keycloak/keycloak-js/Keycloak.js.map +1 -1
- package/esm/keycloak/keycloak-js/index.d.ts +2 -2
- package/esm/keycloak/keycloak-js/index.js +2 -2
- package/esm/keycloak/keycloak-js/index.js.map +1 -1
- package/esm/keycloak/keycloak-js/types.js.map +1 -1
- package/esm/keycloak/keycloakIssuerUriParsed.js +3 -3
- package/esm/keycloak/keycloakIssuerUriParsed.js.map +1 -1
- package/esm/keycloak/keycloakUtils.d.ts +1 -1
- package/esm/keycloak/keycloakUtils.js +3 -3
- package/esm/keycloak/keycloakUtils.js.map +1 -1
- package/esm/keycloak-js.d.ts +1 -1
- package/esm/keycloak-js.js +2 -2
- package/esm/keycloak-js.js.map +1 -1
- package/esm/mock/index.d.ts +1 -1
- package/esm/mock/index.js +2 -2
- package/esm/mock/index.js.map +1 -1
- package/esm/mock/oidc.d.ts +1 -1
- package/esm/mock/oidc.js +6 -6
- package/esm/mock/oidc.js.map +1 -1
- package/esm/mock/react.d.ts +8 -8
- package/esm/mock/react.js +3 -3
- package/esm/mock/react.js.map +1 -1
- package/esm/react/index.d.ts +1 -1
- package/esm/react/index.js +2 -2
- package/esm/react/index.js.map +1 -1
- package/esm/react/react.d.ts +2 -2
- package/esm/react/react.js +6 -6
- package/esm/react/react.js.map +1 -1
- package/esm/tools/Deferred.js.map +1 -1
- package/esm/tools/EphemeralSessionStorage.js +2 -2
- package/esm/tools/EphemeralSessionStorage.js.map +1 -1
- package/esm/tools/Evt.js +3 -3
- package/esm/tools/Evt.js.map +1 -1
- package/esm/tools/StatefulEvt.js.map +1 -1
- package/esm/tools/ValueOrAsyncGetter.js.map +1 -1
- package/esm/tools/asymmetricEncryption.js.map +1 -1
- package/esm/tools/base64.js.map +1 -1
- package/esm/tools/createObjectThatThrowsIfAccessed.js.map +1 -1
- package/esm/tools/decodeJwt.js.map +1 -1
- package/esm/tools/generateUrlSafeRandom.js.map +1 -1
- package/esm/tools/getDownlinkAndRtt.js +2 -2
- package/esm/tools/getDownlinkAndRtt.js.map +1 -1
- package/esm/tools/getIsOnline.js +2 -2
- package/esm/tools/getIsOnline.js.map +1 -1
- package/esm/tools/getIsValidRemoteJson.js.map +1 -1
- package/esm/tools/getPrUserInteraction.js +2 -2
- package/esm/tools/getPrUserInteraction.js.map +1 -1
- package/esm/tools/getUserEnvironmentInfo.js.map +1 -1
- package/esm/tools/haveSharedParentDomain.js.map +1 -1
- package/esm/tools/isDev.js.map +1 -1
- package/esm/tools/parseKeycloakIssuerUri.js +2 -2
- package/esm/tools/parseKeycloakIssuerUri.js.map +1 -1
- package/esm/tools/readExpirationTimeInJwt.js +3 -3
- package/esm/tools/readExpirationTimeInJwt.js.map +1 -1
- package/esm/tools/startCountdown.js +2 -2
- package/esm/tools/startCountdown.js.map +1 -1
- package/esm/tools/subscribeToUserInteraction.js +2 -2
- package/esm/tools/subscribeToUserInteraction.js.map +1 -1
- package/esm/tools/toFullyQualifiedUrl.js.map +1 -1
- package/esm/tools/toHumanReadableDuration.js.map +1 -1
- package/esm/tools/urlSearchParams.js.map +1 -1
- package/esm/tools/workerTimers.js +2 -2
- package/esm/tools/workerTimers.js.map +1 -1
- package/index.js.map +1 -1
- package/keycloak/index.js.map +1 -1
- package/keycloak/isKeycloak.js.map +1 -1
- package/keycloak/keycloak-js/Keycloak.js.map +1 -1
- package/keycloak/keycloak-js/index.js.map +1 -1
- package/keycloak/keycloak-js/types.js.map +1 -1
- package/keycloak/keycloakIssuerUriParsed.js.map +1 -1
- package/keycloak/keycloakUtils.js.map +1 -1
- package/keycloak-js.js.map +1 -1
- package/mock/index.js.map +1 -1
- package/mock/oidc.js.map +1 -1
- package/mock/react.js.map +1 -1
- package/package.json +1 -1
- package/react/index.js.map +1 -1
- package/react/react.js.map +1 -1
- package/src/backend.ts +391 -0
- package/src/core/AuthResponse.ts +26 -0
- package/src/core/Oidc.ts +140 -0
- package/src/core/OidcInitializationError.ts +19 -0
- package/src/core/OidcMetadata.ts +271 -0
- package/src/core/StateData.ts +118 -0
- package/src/core/configId.ts +3 -0
- package/src/core/createOidc.ts +1576 -0
- package/src/core/diagnostic.ts +267 -0
- package/src/core/evtIsUserActive.ts +108 -0
- package/src/core/handleOidcCallback.ts +321 -0
- package/src/core/iframeMessageProtection.ts +100 -0
- package/src/core/index.ts +4 -0
- package/src/core/initialLocationHref.ts +5 -0
- package/src/core/isNewBrowserSession.ts +37 -0
- package/src/core/loginOrGoToAuthServer.ts +324 -0
- package/src/core/loginPropagationToOtherTabs.ts +51 -0
- package/src/core/loginSilent.ts +242 -0
- package/src/core/logoutPropagationToOtherTabs.ts +53 -0
- package/src/core/oidcClientTsUserToTokens.ts +229 -0
- package/src/core/ongoingLoginOrRefreshProcesses.ts +47 -0
- package/src/core/persistedAuthState.ts +122 -0
- package/src/entrypoint.ts +69 -0
- package/src/index.ts +1 -0
- package/src/keycloak/index.ts +8 -0
- package/src/keycloak/isKeycloak.ts +23 -0
- package/src/keycloak/keycloak-js/Keycloak.ts +1097 -0
- package/src/keycloak/keycloak-js/index.ts +2 -0
- package/src/keycloak/keycloak-js/types.ts +442 -0
- package/src/keycloak/keycloakIssuerUriParsed.ts +29 -0
- package/src/keycloak/keycloakUtils.ts +90 -0
- package/src/keycloak-js.ts +1 -0
- package/src/mock/index.ts +1 -0
- package/src/mock/oidc.ts +211 -0
- package/src/mock/react.tsx +11 -0
- package/src/react/index.ts +1 -0
- package/src/react/react.tsx +476 -0
- package/src/tools/Deferred.ts +33 -0
- package/src/tools/EphemeralSessionStorage.ts +223 -0
- package/src/tools/Evt.ts +56 -0
- package/src/tools/StatefulEvt.ts +38 -0
- package/src/tools/ValueOrAsyncGetter.ts +1 -0
- package/src/tools/asymmetricEncryption.ts +184 -0
- package/src/tools/base64.ts +7 -0
- package/src/tools/createObjectThatThrowsIfAccessed.ts +40 -0
- package/src/tools/decodeJwt.ts +95 -0
- package/src/tools/generateUrlSafeRandom.ts +26 -0
- package/src/tools/getDownlinkAndRtt.ts +22 -0
- package/src/tools/getIsOnline.ts +20 -0
- package/src/tools/getIsValidRemoteJson.ts +18 -0
- package/src/tools/getPrUserInteraction.ts +27 -0
- package/src/tools/getUserEnvironmentInfo.ts +42 -0
- package/src/tools/haveSharedParentDomain.ts +13 -0
- package/src/tools/isDev.ts +30 -0
- package/src/tools/parseKeycloakIssuerUri.ts +49 -0
- package/src/tools/readExpirationTimeInJwt.ts +16 -0
- package/src/tools/startCountdown.ts +36 -0
- package/src/tools/subscribeToUserInteraction.ts +33 -0
- package/src/tools/toFullyQualifiedUrl.ts +58 -0
- package/src/tools/toHumanReadableDuration.ts +21 -0
- package/src/tools/urlSearchParams.ts +130 -0
- package/src/tools/workerTimers.ts +57 -0
- package/src/vendor/backend/evt.ts +2 -0
- package/src/vendor/backend/jsonwebtoken.ts +1 -0
- package/src/vendor/backend/node-fetch.ts +2 -0
- package/src/vendor/backend/node-jose.ts +1 -0
- package/src/vendor/backend/tsafe.ts +5 -0
- package/src/vendor/backend/zod.ts +1 -0
- package/src/vendor/frontend/oidc-client-ts.ts +1 -0
- package/src/vendor/frontend/tsafe.ts +6 -0
- package/src/vendor/frontend/worker-timers.ts +2 -0
- package/tools/Deferred.js.map +1 -1
- package/tools/EphemeralSessionStorage.js.map +1 -1
- package/tools/Evt.js.map +1 -1
- package/tools/StatefulEvt.js.map +1 -1
- package/tools/ValueOrAsyncGetter.js.map +1 -1
- package/tools/asymmetricEncryption.js.map +1 -1
- package/tools/base64.js.map +1 -1
- package/tools/createObjectThatThrowsIfAccessed.js.map +1 -1
- package/tools/decodeJwt.js.map +1 -1
- package/tools/generateUrlSafeRandom.js.map +1 -1
- package/tools/getDownlinkAndRtt.js.map +1 -1
- package/tools/getIsOnline.js.map +1 -1
- package/tools/getIsValidRemoteJson.js.map +1 -1
- package/tools/getPrUserInteraction.js.map +1 -1
- package/tools/getUserEnvironmentInfo.js.map +1 -1
- package/tools/haveSharedParentDomain.js.map +1 -1
- package/tools/isDev.js.map +1 -1
- package/tools/parseKeycloakIssuerUri.js.map +1 -1
- package/tools/readExpirationTimeInJwt.js.map +1 -1
- package/tools/startCountdown.js.map +1 -1
- package/tools/subscribeToUserInteraction.js.map +1 -1
- package/tools/toFullyQualifiedUrl.js.map +1 -1
- package/tools/toHumanReadableDuration.js.map +1 -1
- package/tools/urlSearchParams.js.map +1 -1
- package/tools/workerTimers.js.map +1 -1
package/src/core/Oidc.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { OidcInitializationError } from "./OidcInitializationError";
|
|
2
|
+
|
|
3
|
+
export declare type Oidc<
|
|
4
|
+
DecodedIdToken extends Record<string, unknown> = Oidc.Tokens.DecodedIdToken_base
|
|
5
|
+
> = Oidc.LoggedIn<DecodedIdToken> | Oidc.NotLoggedIn;
|
|
6
|
+
|
|
7
|
+
export declare namespace Oidc {
|
|
8
|
+
export type Common = {
|
|
9
|
+
params: {
|
|
10
|
+
issuerUri: string;
|
|
11
|
+
clientId: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type NotLoggedIn = Common & {
|
|
16
|
+
isUserLoggedIn: false;
|
|
17
|
+
login: (params: {
|
|
18
|
+
doesCurrentHrefRequiresAuth: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Add extra query parameters to the url before redirecting to the login pages.
|
|
21
|
+
*/
|
|
22
|
+
extraQueryParams?: Record<string, string | undefined>;
|
|
23
|
+
/**
|
|
24
|
+
* Where to redirect after successful login.
|
|
25
|
+
* Default: window.location.href (here)
|
|
26
|
+
*
|
|
27
|
+
* It does not need to include the origin, eg: "/dashboard"
|
|
28
|
+
*/
|
|
29
|
+
redirectUrl?: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Transform the url before redirecting to the login pages.
|
|
33
|
+
* Prefer using the extraQueryParams parameter if you're only adding query parameters.
|
|
34
|
+
*/
|
|
35
|
+
transformUrlBeforeRedirect?: (url: string) => string;
|
|
36
|
+
}) => Promise<never>;
|
|
37
|
+
initializationError: OidcInitializationError | undefined;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type LoggedIn<DecodedIdToken extends Record<string, unknown> = Record<string, unknown>> =
|
|
41
|
+
Common & {
|
|
42
|
+
isUserLoggedIn: true;
|
|
43
|
+
renewTokens(params?: {
|
|
44
|
+
extraTokenParams?: Record<string, string | undefined>;
|
|
45
|
+
}): Promise<void>;
|
|
46
|
+
getTokens: () => Promise<Tokens<DecodedIdToken>>;
|
|
47
|
+
subscribeToTokensChange: (onTokenChange: (tokens: Tokens<DecodedIdToken>) => void) => {
|
|
48
|
+
unsubscribe: () => void;
|
|
49
|
+
};
|
|
50
|
+
getDecodedIdToken: () => DecodedIdToken;
|
|
51
|
+
logout: (
|
|
52
|
+
params:
|
|
53
|
+
| { redirectTo: "home" | "current page" }
|
|
54
|
+
| { redirectTo: "specific url"; url: string }
|
|
55
|
+
) => Promise<never>;
|
|
56
|
+
goToAuthServer: (params: {
|
|
57
|
+
extraQueryParams?: Record<string, string | undefined>;
|
|
58
|
+
redirectUrl?: string;
|
|
59
|
+
transformUrlBeforeRedirect?: (url: string) => string;
|
|
60
|
+
}) => Promise<never>;
|
|
61
|
+
subscribeToAutoLogoutCountdown: (
|
|
62
|
+
tickCallback: (params: { secondsLeft: number | undefined }) => void
|
|
63
|
+
) => { unsubscribeFromAutoLogoutCountdown: () => void };
|
|
64
|
+
/**
|
|
65
|
+
* If you called `goToAuthServer` or `login` with extraQueryParams, this object let you know the outcome of the
|
|
66
|
+
* of the action that was intended.
|
|
67
|
+
*
|
|
68
|
+
* For example, on a Keycloak server, if you called `goToAuthServer({ extraQueryParams: { kc_action: "UPDATE_PASSWORD" } })`
|
|
69
|
+
* you'll get back: `{ extraQueryParams: { kc_action: "UPDATE_PASSWORD" }, result: { kc_action_status: "success" } }` (or "cancelled")
|
|
70
|
+
*/
|
|
71
|
+
backFromAuthServer:
|
|
72
|
+
| {
|
|
73
|
+
extraQueryParams: Record<string, string>;
|
|
74
|
+
result: Record<string, string>;
|
|
75
|
+
}
|
|
76
|
+
| undefined;
|
|
77
|
+
/**
|
|
78
|
+
* This is true when the user has just returned from the login pages.
|
|
79
|
+
* This is also true when the user navigate to your app and was able to be silently signed in because there was still a valid session.
|
|
80
|
+
* This false however when the use just reload the page.
|
|
81
|
+
*
|
|
82
|
+
* This can be used to perform some action related to session initialization
|
|
83
|
+
* but avoiding doing it repeatedly every time the user reload the page.
|
|
84
|
+
*
|
|
85
|
+
* Note that this is referring to the browser session and not the OIDC session
|
|
86
|
+
* on the server side.
|
|
87
|
+
*
|
|
88
|
+
* If you want to perform an action only when a new OIDC session is created
|
|
89
|
+
* you can test oidc.isNewBrowserSession && oidc.backFromAuthServer !== undefined
|
|
90
|
+
*/
|
|
91
|
+
isNewBrowserSession: boolean;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type Tokens<DecodedIdToken extends Record<string, unknown> = Tokens.DecodedIdToken_base> =
|
|
95
|
+
| Tokens.WithRefreshToken<DecodedIdToken>
|
|
96
|
+
| Tokens.WithoutRefreshToken<DecodedIdToken>;
|
|
97
|
+
|
|
98
|
+
export namespace Tokens {
|
|
99
|
+
export type Common<DecodedIdToken> = {
|
|
100
|
+
accessToken: string;
|
|
101
|
+
accessTokenExpirationTime: number;
|
|
102
|
+
idToken: string;
|
|
103
|
+
decodedIdToken: DecodedIdToken;
|
|
104
|
+
/**
|
|
105
|
+
* decodedIdToken_original = decodeJwt(idToken);
|
|
106
|
+
* decodedIdToken = decodedIdTokenSchema.parse(decodedIdToken_original)
|
|
107
|
+
*
|
|
108
|
+
* The idea here is that if you have provided a zod schema as `decodedIdTokenSchema`
|
|
109
|
+
* it will strip out every claim that you haven't specified.
|
|
110
|
+
* You might even be applying some transformation.
|
|
111
|
+
*
|
|
112
|
+
* `decodedIdToken_original` is the actual decoded payload of the id_token, untransformed.
|
|
113
|
+
* */
|
|
114
|
+
decodedIdToken_original: DecodedIdToken_base;
|
|
115
|
+
/** Read from id_token's JWT, iat claim value, it's a JavaScript timestamp (millisecond epoch) */
|
|
116
|
+
issuedAtTime: number;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export type WithRefreshToken<DecodedIdToken> = Common<DecodedIdToken> & {
|
|
120
|
+
hasRefreshToken: true;
|
|
121
|
+
refreshToken: string;
|
|
122
|
+
refreshTokenExpirationTime: number | undefined;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export type WithoutRefreshToken<DecodedIdToken> = Common<DecodedIdToken> & {
|
|
126
|
+
hasRefreshToken: false;
|
|
127
|
+
refreshToken?: never;
|
|
128
|
+
refreshTokenExpirationTime?: never;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export type DecodedIdToken_base = {
|
|
132
|
+
iss: string;
|
|
133
|
+
sub: string;
|
|
134
|
+
aud: string | string[];
|
|
135
|
+
exp: number;
|
|
136
|
+
iat: number;
|
|
137
|
+
[claimName: string]: unknown;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class OidcInitializationError extends Error {
|
|
2
|
+
public readonly isAuthServerLikelyDown: boolean;
|
|
3
|
+
|
|
4
|
+
constructor(params: { messageOrCause: string | Error; isAuthServerLikelyDown: boolean }) {
|
|
5
|
+
super(
|
|
6
|
+
(() => {
|
|
7
|
+
if (typeof params.messageOrCause === "string") {
|
|
8
|
+
return params.messageOrCause;
|
|
9
|
+
} else {
|
|
10
|
+
return `Unknown initialization error: ${params.messageOrCause.message}`;
|
|
11
|
+
}
|
|
12
|
+
})(),
|
|
13
|
+
// @ts-expect-error
|
|
14
|
+
{ cause: typeof params.messageOrCause === "string" ? undefined : params.messageOrCause }
|
|
15
|
+
);
|
|
16
|
+
this.isAuthServerLikelyDown = params.isAuthServerLikelyDown;
|
|
17
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { type OidcMetadata as OidcClientTsOidcMetadata } from "../vendor/frontend/oidc-client-ts";
|
|
2
|
+
import { assert, type Equals } from "../vendor/frontend/tsafe";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* OpenID Providers have metadata describing their configuration.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export type OidcMetadata = {
|
|
10
|
+
/**
|
|
11
|
+
* REQUIRED. URL using the `https` scheme with no query or fragment component that the OP asserts as its Issuer
|
|
12
|
+
* Identifier. If Issuer discovery is supported
|
|
13
|
+
* (see [Section 2](https://openid.net/specs/openid-connect-discovery-1_0.html#IssuerDiscovery)),
|
|
14
|
+
* this value MUST be identical to the issuer value
|
|
15
|
+
* returned by WebFinger. This also MUST be identical to the `iss` Claim value in ID Tokens issued from this Issuer.
|
|
16
|
+
*
|
|
17
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
18
|
+
*/
|
|
19
|
+
issuer: string;
|
|
20
|
+
/**
|
|
21
|
+
* REQUIRED. URL of the OP's OAuth 2.0 Authorization Endpoint
|
|
22
|
+
* [[OpenID.Core](https://openid.net/specs/openid-connect-discovery-1_0.html#OpenID.Core)].
|
|
23
|
+
* This URL MUST use the `https` scheme and MAY contain port, path, and query parameter components.
|
|
24
|
+
*
|
|
25
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
26
|
+
*/
|
|
27
|
+
authorization_endpoint: string;
|
|
28
|
+
/**
|
|
29
|
+
* URL of the OP's OAuth 2.0 Token Endpoint
|
|
30
|
+
* [[OpenID.Core](https://openid.net/specs/openid-connect-discovery-1_0.html#OpenID.Core)].
|
|
31
|
+
* This is REQUIRED unless only the Implicit Flow is used. This URL MUST use the `https` scheme and MAY contain
|
|
32
|
+
* port, path, and query parameter components.
|
|
33
|
+
*
|
|
34
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
35
|
+
*/
|
|
36
|
+
token_endpoint: string;
|
|
37
|
+
/**
|
|
38
|
+
* OPTIONAL. JSON array containing a list of Client Authentication methods supported by this Token Endpoint.
|
|
39
|
+
* The options are `client_secret_post`, `client_secret_basic`, `client_secret_jwt`, and `private_key_jwt`, as
|
|
40
|
+
* described in Section 9 of
|
|
41
|
+
* [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-discovery-1_0.html#OpenID.Core)
|
|
42
|
+
* [OpenID.Core]. Other authentication methods MAY be defined by extensions. If omitted, the default is
|
|
43
|
+
* `client_secret_basic` -- the HTTP Basic Authentication Scheme specified in Section 2.3.1 of
|
|
44
|
+
* [OAuth 2.0](https://openid.net/specs/openid-connect-discovery-1_0.html#RFC6749) [RFC6749].
|
|
45
|
+
*
|
|
46
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
47
|
+
*/
|
|
48
|
+
token_endpoint_auth_methods_supported: string[];
|
|
49
|
+
/**
|
|
50
|
+
* OPTIONAL. JSON array containing a list of the JWS signing algorithms (`alg` values) supported by the
|
|
51
|
+
* Token Endpoint for the signature on the JWT
|
|
52
|
+
* [[JWT](https://openid.net/specs/openid-connect-discovery-1_0.html#JWT)]
|
|
53
|
+
* used to authenticate the Client at the Token Endpoint for the `private_key_jwt` and `client_secret_jwt`
|
|
54
|
+
* authentication methods. Servers SHOULD support RS256. The value none MUST NOT be used.
|
|
55
|
+
*
|
|
56
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
57
|
+
*/
|
|
58
|
+
token_endpoint_auth_signing_alg_values_supported: string[];
|
|
59
|
+
/**
|
|
60
|
+
* RECOMMENDED. URL of the OP's UserInfo Endpoint
|
|
61
|
+
* [[OpenID.Core](https://openid.net/specs/openid-connect-discovery-1_0.html#OpenID.Core)].
|
|
62
|
+
* This URL MUST use the https scheme and MAY contain port, path, and query parameter components.
|
|
63
|
+
*
|
|
64
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
65
|
+
*/
|
|
66
|
+
userinfo_endpoint: string;
|
|
67
|
+
/**
|
|
68
|
+
* REQUIRED. URL of an OP iframe that supports cross-origin communications for session state information with the
|
|
69
|
+
* RP Client, using the HTML5 postMessage API. This URL MUST use the `https` scheme and MAY contain port, path, and
|
|
70
|
+
* query parameter components. The page is loaded from an invisible iframe embedded in an RP page so that it can run
|
|
71
|
+
* in the OP's security context. It accepts postMessage requests from the relevant RP iframe and uses postMessage to
|
|
72
|
+
* post back the login status of the End-User at the OP.
|
|
73
|
+
*
|
|
74
|
+
* @see https://openid.net/specs/openid-connect-session-1_0.html#OPMetadata
|
|
75
|
+
*/
|
|
76
|
+
check_session_iframe: string;
|
|
77
|
+
/**
|
|
78
|
+
* REQUIRED. URL at the OP to which an RP can perform a redirect to request that the End-User be logged out at the OP.
|
|
79
|
+
*
|
|
80
|
+
* @see https://openid.net/specs/openid-connect-session-1_0-17.html#OPMetadata
|
|
81
|
+
*/
|
|
82
|
+
end_session_endpoint: string;
|
|
83
|
+
/**
|
|
84
|
+
* REQUIRED. URL of the OP's JWK Set
|
|
85
|
+
* [[JWK](https://openid.net/specs/openid-connect-discovery-1_0.html#JWK)]
|
|
86
|
+
* document, which MUST use the `https` scheme. This contains the signing key(s) the RP uses to validate signatures from
|
|
87
|
+
* the OP. The JWK Set MAY also contain the Server's encryption key(s), which are used by RPs to encrypt requests to the Server.
|
|
88
|
+
* When both signing and encryption keys are made available, a `use` (public key use) parameter value is REQUIRED for all keys
|
|
89
|
+
* in the referenced JWK Set to indicate each key's intended usage. Although some algorithms allow the same key to be used for
|
|
90
|
+
* both signatures and encryption, doing so is NOT RECOMMENDED, as it is less secure. The JWK `x5c` parameter MAY be used to provide
|
|
91
|
+
* X.509 representations of keys provided. When used, the bare key values MUST still be present and MUST match those in the
|
|
92
|
+
* certificate. The JWK Set MUST NOT contain private or symmetric key values.
|
|
93
|
+
*
|
|
94
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
95
|
+
*/
|
|
96
|
+
jwks_uri: string;
|
|
97
|
+
/**
|
|
98
|
+
* RECOMMENDED. URL of the OP's Dynamic Client Registration Endpoint
|
|
99
|
+
* [[OpenID.Registration](https://openid.net/specs/openid-connect-discovery-1_0.html#OpenID.Registration)],
|
|
100
|
+
* which MUST use the `https` scheme.
|
|
101
|
+
*
|
|
102
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
103
|
+
*/
|
|
104
|
+
registration_endpoint: string;
|
|
105
|
+
/**
|
|
106
|
+
* RECOMMENDED. JSON array containing a list of the
|
|
107
|
+
* [OAuth 2.0](https://openid.net/specs/openid-connect-discovery-1_0.html#RFC6749)
|
|
108
|
+
* [RFC6749] scope values that this server supports. The server MUST support the openid scope value. Servers MAY choose not
|
|
109
|
+
* to advertise some supported scope values even when this parameter is used, although those defined in
|
|
110
|
+
* [[OpenID.Core](https://openid.net/specs/openid-connect-discovery-1_0.html#OpenID.Core)]
|
|
111
|
+
* SHOULD be listed, if supported.
|
|
112
|
+
*
|
|
113
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
114
|
+
*/
|
|
115
|
+
scopes_supported: string[];
|
|
116
|
+
/**
|
|
117
|
+
* REQUIRED. JSON array containing a list of the OAuth 2.0 `response_type` values that this OP supports. Dynamic OpenID
|
|
118
|
+
* Providers MUST support the `code`, `id_token`, and the `id_token token` Response Type values.
|
|
119
|
+
*
|
|
120
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
121
|
+
*/
|
|
122
|
+
response_types_supported: string[];
|
|
123
|
+
/**
|
|
124
|
+
* OPTIONAL. JSON array containing a list of the Authentication Context Class References that this OP supports.
|
|
125
|
+
*
|
|
126
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
127
|
+
*/
|
|
128
|
+
acr_values_supported: string[];
|
|
129
|
+
/**
|
|
130
|
+
* REQUIRED. JSON array containing a list of the Subject Identifier types that this OP supports. Valid types include `pairwise`
|
|
131
|
+
* and `public`.
|
|
132
|
+
*
|
|
133
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
134
|
+
*/
|
|
135
|
+
subject_types_supported: string[];
|
|
136
|
+
/**
|
|
137
|
+
* OPTIONAL. JSON array containing a list of the JWS signing algorithms (`alg` values) supported by the OP for Request Objects,
|
|
138
|
+
* which are described in Section 6.1 of
|
|
139
|
+
* [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-discovery-1_0.html#OpenID.Core)
|
|
140
|
+
* [OpenID.Core]. These algorithms are used both when the Request Object is passed by value (using the `request` parameter) and
|
|
141
|
+
* when it is passed by reference (using the `request_uri` parameter). Servers SHOULD support `none` and `RS256`.
|
|
142
|
+
*
|
|
143
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
144
|
+
*/
|
|
145
|
+
request_object_signing_alg_values_supported: string[];
|
|
146
|
+
/**
|
|
147
|
+
* OPTIONAL. JSON array containing a list of the `display` parameter values that the OpenID Provider supports. These values are
|
|
148
|
+
* described in Section 3.1.2.1 of
|
|
149
|
+
* [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-discovery-1_0.html#OpenID.Core)
|
|
150
|
+
* [OpenID.Core].
|
|
151
|
+
*
|
|
152
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
153
|
+
*/
|
|
154
|
+
display_values_supported: string[];
|
|
155
|
+
/**
|
|
156
|
+
* OPTIONAL. JSON array containing a list of the Claim Types that the OpenID Provider supports. These Claim Types are described
|
|
157
|
+
* in Section 5.6 of
|
|
158
|
+
* [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-discovery-1_0.html#OpenID.Core)
|
|
159
|
+
* [OpenID.Core]. Values defined by this specification are `normal`, `aggregated`, and `distributed`. If omitted, the
|
|
160
|
+
* implementation supports only normal Claims.
|
|
161
|
+
*
|
|
162
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
163
|
+
*/
|
|
164
|
+
claim_types_supported: string[];
|
|
165
|
+
/**
|
|
166
|
+
* RECOMMENDED. JSON array containing a list of the Claim Names of the Claims that the OpenID Provider MAY be able to supply
|
|
167
|
+
* values for. Note that for privacy or other reasons, this might not be an exhaustive list.
|
|
168
|
+
*
|
|
169
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
170
|
+
*/
|
|
171
|
+
claims_supported: string[];
|
|
172
|
+
/**
|
|
173
|
+
* OPTIONAL. Boolean value specifying whether the OP supports use of the `claims` parameter, with `true` indicating support. If
|
|
174
|
+
* omitted, the default value is `false`.
|
|
175
|
+
*
|
|
176
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
177
|
+
*/
|
|
178
|
+
claims_parameter_supported: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* OPTIONAL. URL of a page containing human-readable information that developers might want or need to know when using the
|
|
181
|
+
* OpenID Provider. In particular, if the OpenID Provider does not support Dynamic Client Registration, then information on
|
|
182
|
+
* how to register Clients needs to be provided in this documentation.
|
|
183
|
+
*
|
|
184
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
185
|
+
*/
|
|
186
|
+
service_documentation: string;
|
|
187
|
+
/**
|
|
188
|
+
* OPTIONAL. Languages and scripts supported for the user interface, represented as a JSON array of
|
|
189
|
+
* [BCP47](https://openid.net/specs/openid-connect-discovery-1_0.html#RFC5646)
|
|
190
|
+
* [RFC5646] language tag values.
|
|
191
|
+
*
|
|
192
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
193
|
+
*/
|
|
194
|
+
ui_locales_supported: string[];
|
|
195
|
+
/**
|
|
196
|
+
* The fully qualified URL of the server's revocation endpoint defined by
|
|
197
|
+
* [OAuth 2.0 Token Revocation](https://openid.net/specs/openid-heart-oauth2-2015-12-07.html#RFC7009)
|
|
198
|
+
* [RFC7009].
|
|
199
|
+
*
|
|
200
|
+
* @see https://openid.net/specs/openid-heart-oauth2-2015-12-07.html#rfc.section.4.1
|
|
201
|
+
*/
|
|
202
|
+
revocation_endpoint: string;
|
|
203
|
+
/**
|
|
204
|
+
* The fully qualified URL of the server's introspection endpoint defined by
|
|
205
|
+
* [OAuth Token Introspection](https://openid.net/specs/openid-heart-oauth2-2015-12-07.html#RFC7662)
|
|
206
|
+
* [RFC7662].
|
|
207
|
+
*
|
|
208
|
+
* @see https://openid.net/specs/openid-heart-oauth2-2015-12-07.html#rfc.section.4.1
|
|
209
|
+
*/
|
|
210
|
+
introspection_endpoint: string;
|
|
211
|
+
/**
|
|
212
|
+
* OPTIONAL. Boolean value specifying whether the OP supports HTTP-based logout, with `true` indicating support. If omitted,
|
|
213
|
+
* the default value is `false`.
|
|
214
|
+
*
|
|
215
|
+
* @see https://openid.net/specs/openid-connect-frontchannel-1_0.html#OPLogout
|
|
216
|
+
*/
|
|
217
|
+
frontchannel_logout_supported: boolean;
|
|
218
|
+
/**
|
|
219
|
+
* OPTIONAL. Boolean value specifying whether the OP can pass iss (issuer) and `sid` (session ID) query parameters to identify
|
|
220
|
+
* the RP session with the OP when the `frontchannel_logout_uri` is used. If supported, the `sid` Claim is also included in
|
|
221
|
+
* ID Tokens issued by the OP. If omitted, the default value is `false`.
|
|
222
|
+
*
|
|
223
|
+
* @see https://openid.net/specs/openid-connect-frontchannel-1_0.html#OPLogout
|
|
224
|
+
*/
|
|
225
|
+
frontchannel_logout_session_supported: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* OPTIONAL. Boolean value specifying whether the OP supports back-channel logout, with `true` indicating support. If omitted,
|
|
228
|
+
* the default value is `false`.
|
|
229
|
+
*
|
|
230
|
+
* @see https://openid.net/specs/openid-connect-backchannel-1_0.html#BCSupport
|
|
231
|
+
*/
|
|
232
|
+
backchannel_logout_supported: boolean;
|
|
233
|
+
/**
|
|
234
|
+
* OPTIONAL. Boolean value specifying whether the OP can pass a `sid` (session ID) Claim in the Logout Token to identify the
|
|
235
|
+
* RP session with the OP. If supported, the `sid` Claim is also included in ID Tokens issued by the OP. If omitted, the default
|
|
236
|
+
* value is `false`.
|
|
237
|
+
*
|
|
238
|
+
* @see https://openid.net/specs/openid-connect-backchannel-1_0.html#BCSupport
|
|
239
|
+
*/
|
|
240
|
+
backchannel_logout_session_supported: boolean;
|
|
241
|
+
/**
|
|
242
|
+
* OPTIONAL. JSON array containing a list of the OAuth 2.0 Grant Type values that this OP supports. Dynamic OpenID Providers
|
|
243
|
+
* MUST support the `authorization_code` and `implicit` Grant Type values and MAY support other Grant Types. If omitted, the
|
|
244
|
+
* default value is [`"authorization_code"`, `"implicit"`].
|
|
245
|
+
*
|
|
246
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
247
|
+
*/
|
|
248
|
+
grant_types_supported: string[];
|
|
249
|
+
/**
|
|
250
|
+
* OPTIONAL. JSON array containing a list of the OAuth 2.0 response_mode values that this OP supports, as specified in
|
|
251
|
+
* [OAuth 2.0 Multiple Response Type Encoding Practices](https://openid.net/specs/openid-connect-discovery-1_0.html#OAuth.Responses)
|
|
252
|
+
* [OAuth.Responses]. If omitted, the default for Dynamic OpenID Providers is [`"query"`, `"fragment"`].
|
|
253
|
+
*
|
|
254
|
+
* @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
|
255
|
+
*/
|
|
256
|
+
response_modes_supported: string[];
|
|
257
|
+
/**
|
|
258
|
+
* OPTIONAL. JSON array containing a list of
|
|
259
|
+
* [Proof Key for Code Exchange (PKCE)](https://datatracker.ietf.org/doc/html/rfc7636)
|
|
260
|
+
* [RFC7636] code challenge methods supported by this authorization server. Code challenge method values are used in
|
|
261
|
+
* the "code_challenge_method" parameter defined in Section 4.3 of [RFC7636]. The valid code challenge method values are
|
|
262
|
+
* those registered in the
|
|
263
|
+
* [IANA "PKCE Code Challenge Methods" registry](https://datatracker.ietf.org/doc/html/rfc8414#ref-IANA.OAuth.Parameters)
|
|
264
|
+
* [IANA.OAuth.Parameters]. If omitted, the authorization server does not support PKCE.
|
|
265
|
+
*
|
|
266
|
+
* @see https://datatracker.ietf.org/doc/html/rfc8414
|
|
267
|
+
*/
|
|
268
|
+
code_challenge_methods_supported: string[];
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
assert<Equals<OidcMetadata, OidcClientTsOidcMetadata>>;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { typeGuard, assert } from "../vendor/frontend/tsafe";
|
|
2
|
+
import { generateUrlSafeRandom } from "../tools/generateUrlSafeRandom";
|
|
3
|
+
|
|
4
|
+
export type StateData = StateData.IFrame | StateData.Redirect;
|
|
5
|
+
|
|
6
|
+
export namespace StateData {
|
|
7
|
+
type Common = {
|
|
8
|
+
configId: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type IFrame = Common & {
|
|
12
|
+
context: "iframe";
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type Redirect = Redirect.Login | Redirect.Logout;
|
|
16
|
+
export namespace Redirect {
|
|
17
|
+
type Common_Redirect = Common & {
|
|
18
|
+
context: "redirect";
|
|
19
|
+
redirectUrl: string;
|
|
20
|
+
hasBeenProcessedByCallback: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type Login = Common_Redirect & {
|
|
24
|
+
action: "login";
|
|
25
|
+
redirectUrl_consentRequiredCase: string;
|
|
26
|
+
extraQueryParams: Record<string, string>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type Logout = Common_Redirect & {
|
|
30
|
+
action: "logout";
|
|
31
|
+
sessionId: string | undefined;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const STATE_QUERY_PARAM_VALUE_IDENTIFIER_PREFIX = "b2lkYy1zcGEu";
|
|
37
|
+
const RANDOM_STRING_LENGTH = 32 - STATE_QUERY_PARAM_VALUE_IDENTIFIER_PREFIX.length;
|
|
38
|
+
|
|
39
|
+
export function generateStateUrlParamValue(): string {
|
|
40
|
+
return `${STATE_QUERY_PARAM_VALUE_IDENTIFIER_PREFIX}${generateUrlSafeRandom({
|
|
41
|
+
length: RANDOM_STRING_LENGTH
|
|
42
|
+
})}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getIsStatQueryParamValue(params: { maybeStateUrlParamValue: string }): boolean {
|
|
46
|
+
const { maybeStateUrlParamValue } = params;
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
maybeStateUrlParamValue.startsWith(STATE_QUERY_PARAM_VALUE_IDENTIFIER_PREFIX) &&
|
|
50
|
+
maybeStateUrlParamValue.length ===
|
|
51
|
+
STATE_QUERY_PARAM_VALUE_IDENTIFIER_PREFIX.length + RANDOM_STRING_LENGTH
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const STATE_STORE_KEY_PREFIX = "oidc.";
|
|
56
|
+
|
|
57
|
+
function getKey(params: { stateUrlParamValue: string }) {
|
|
58
|
+
const { stateUrlParamValue } = params;
|
|
59
|
+
|
|
60
|
+
return `${STATE_STORE_KEY_PREFIX}${stateUrlParamValue}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function getStateStore(params: { stateUrlParamValue: string }): { data: StateData } | undefined {
|
|
64
|
+
const { stateUrlParamValue } = params;
|
|
65
|
+
|
|
66
|
+
const item = localStorage.getItem(getKey({ stateUrlParamValue }));
|
|
67
|
+
|
|
68
|
+
if (item === null) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const obj = JSON.parse(item);
|
|
73
|
+
|
|
74
|
+
assert(
|
|
75
|
+
typeGuard<{ data: StateData }>(
|
|
76
|
+
obj,
|
|
77
|
+
obj instanceof Object && obj.data instanceof Object && typeof obj.data.context === "string"
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return obj;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function setStateStore(params: { stateUrlParamValue: string; obj: { data: StateData } }) {
|
|
85
|
+
const { stateUrlParamValue, obj } = params;
|
|
86
|
+
|
|
87
|
+
localStorage.setItem(getKey({ stateUrlParamValue }), JSON.stringify(obj));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function clearStateStore(params: { stateUrlParamValue: string }) {
|
|
91
|
+
const { stateUrlParamValue } = params;
|
|
92
|
+
localStorage.removeItem(getKey({ stateUrlParamValue }));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function getStateData(params: { stateUrlParamValue: string }): StateData | undefined {
|
|
96
|
+
const { stateUrlParamValue } = params;
|
|
97
|
+
|
|
98
|
+
const stateStore = getStateStore({ stateUrlParamValue });
|
|
99
|
+
|
|
100
|
+
if (stateStore === undefined) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return stateStore.data;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function markStateDataAsProcessedByCallback(params: { stateUrlParamValue: string }) {
|
|
108
|
+
const { stateUrlParamValue } = params;
|
|
109
|
+
|
|
110
|
+
const obj = getStateStore({ stateUrlParamValue });
|
|
111
|
+
|
|
112
|
+
assert(obj !== undefined, "180465");
|
|
113
|
+
assert(obj.data.context === "redirect", "649531");
|
|
114
|
+
|
|
115
|
+
obj.data.hasBeenProcessedByCallback = true;
|
|
116
|
+
|
|
117
|
+
setStateStore({ stateUrlParamValue, obj });
|
|
118
|
+
}
|