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
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2017 Brett Epps <https://github.com/eppsilon>
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
7
|
+
* associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
8
|
+
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
|
10
|
+
* following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
13
|
+
* portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
16
|
+
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
17
|
+
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
18
|
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
19
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
20
|
+
*/
|
|
21
|
+
export type KeycloakOnLoad = "login-required" | "check-sso";
|
|
22
|
+
export type KeycloakResponseMode = "query" | "fragment";
|
|
23
|
+
export type KeycloakResponseType = "code" | "id_token token" | "code id_token token";
|
|
24
|
+
export type KeycloakFlow = "standard" | "implicit" | "hybrid";
|
|
25
|
+
export type KeycloakPkceMethod = "S256" | false;
|
|
26
|
+
|
|
27
|
+
export interface KeycloakServerConfig {
|
|
28
|
+
/**
|
|
29
|
+
* URL to the Keycloak server, for example: http://keycloak-server/auth
|
|
30
|
+
*/
|
|
31
|
+
url: string;
|
|
32
|
+
/**
|
|
33
|
+
* Name of the realm, for example: 'myrealm'
|
|
34
|
+
*/
|
|
35
|
+
realm: string;
|
|
36
|
+
/**
|
|
37
|
+
* Client identifier, example: 'myapp'
|
|
38
|
+
*/
|
|
39
|
+
clientId: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* OpenIdProviderMetadata The OpenID version of the adapter configuration, based on the {@link https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata OpenID Connect Discovery specification}.
|
|
44
|
+
*/
|
|
45
|
+
export interface OpenIdProviderMetadata {
|
|
46
|
+
/** URL of the OP's OAuth 2.0 Authorization Endpoint. */
|
|
47
|
+
authorization_endpoint: string;
|
|
48
|
+
/** URL of the OP's OAuth 2.0 Token Endpoint. */
|
|
49
|
+
token_endpoint: string;
|
|
50
|
+
/** URL of the OP's UserInfo Endpoint. */
|
|
51
|
+
userinfo_endpoint?: string;
|
|
52
|
+
/** URL of an OP iframe that supports cross-origin communications for session state information with the RP Client, using the HTML5 postMessage API. */
|
|
53
|
+
check_session_iframe?: string;
|
|
54
|
+
/** URL at the OP to which an RP can perform a redirect to request that the End-User be logged out at the OP. */
|
|
55
|
+
end_session_endpoint?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface Acr {
|
|
59
|
+
/**
|
|
60
|
+
* Array of values, which will be used inside ID Token `acr` claim sent inside the `claims` parameter to Keycloak server during login.
|
|
61
|
+
* Values should correspond to the ACR levels defined in the ACR to Loa mapping for realm or client or to the numbers (levels) inside defined
|
|
62
|
+
* Keycloak authentication flow. See section 5.5.1 of OIDC 1.0 specification for the details.
|
|
63
|
+
*/
|
|
64
|
+
values: string[];
|
|
65
|
+
/**
|
|
66
|
+
* This parameter specifies if ACR claims is considered essential or not.
|
|
67
|
+
*/
|
|
68
|
+
essential: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface KeycloakInitOptions {
|
|
72
|
+
/**
|
|
73
|
+
* Adds a [cryptographic nonce](https://en.wikipedia.org/wiki/Cryptographic_nonce)
|
|
74
|
+
* to verify that the authentication response matches the request.
|
|
75
|
+
* @default true
|
|
76
|
+
*
|
|
77
|
+
* NOTE oidc-spa: Not supported because redundant with PKCE and we only support PKCE.
|
|
78
|
+
*/
|
|
79
|
+
//useNonce?: boolean;
|
|
80
|
+
useNonce?: false;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* Allow usage of different types of adapters or a custom adapter to make Keycloak work in different environments.
|
|
85
|
+
*
|
|
86
|
+
* The following options are supported:
|
|
87
|
+
* - `default` - Use default APIs that are available in browsers.
|
|
88
|
+
* - `cordova` - Use a WebView in Cordova.
|
|
89
|
+
* - `cordova-native` - Use Cordova native APIs, this is recommended over `cordova`.
|
|
90
|
+
*
|
|
91
|
+
* It's also possible to pass in a custom adapter for the environment you are running Keycloak in. In order to do so extend the `KeycloakAdapter` interface and implement the methods that are defined there.
|
|
92
|
+
*
|
|
93
|
+
* For example:
|
|
94
|
+
*
|
|
95
|
+
* ```ts
|
|
96
|
+
* // Implement the 'KeycloakAdapter' interface so that all required methods are guaranteed to be present.
|
|
97
|
+
* const MyCustomAdapter: KeycloakAdapter = {
|
|
98
|
+
* login(options) {
|
|
99
|
+
* // Write your own implementation here.
|
|
100
|
+
* }
|
|
101
|
+
*
|
|
102
|
+
* // The other methods go here...
|
|
103
|
+
* };
|
|
104
|
+
*
|
|
105
|
+
* keycloak.init({
|
|
106
|
+
* adapter: MyCustomAdapter,
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* NOTE oidc-spa: We do not support adapters
|
|
111
|
+
*
|
|
112
|
+
*/
|
|
113
|
+
//adapter?: 'default' | 'cordova' | 'cordova-native' | KeycloakAdapter;
|
|
114
|
+
adapter?: "default";
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Specifies an action to do on load.
|
|
118
|
+
*
|
|
119
|
+
* NOTE oidc-spa: Default "check-sso"
|
|
120
|
+
*/
|
|
121
|
+
onLoad?: KeycloakOnLoad;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Set an initial value for the token.
|
|
125
|
+
*/
|
|
126
|
+
token?: string;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Set an initial value for the refresh token.
|
|
130
|
+
*/
|
|
131
|
+
refreshToken?: string;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Set an initial value for the id token (only together with `token` or
|
|
135
|
+
* `refreshToken`).
|
|
136
|
+
*/
|
|
137
|
+
idToken?: string;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Set an initial value for skew between local time and Keycloak server in
|
|
141
|
+
* seconds (only together with `token` or `refreshToken`).
|
|
142
|
+
*
|
|
143
|
+
* NOTE oidc-spa: Not supported
|
|
144
|
+
*/
|
|
145
|
+
//timeSkew?: number;
|
|
146
|
+
timeSkew?: undefined;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Set to enable/disable monitoring login state.
|
|
150
|
+
* @default true (in keycloak-js but false in oidc-spa)
|
|
151
|
+
*
|
|
152
|
+
* NOTE oidc-spa: we check session via broadcast channels.
|
|
153
|
+
*/
|
|
154
|
+
//checkLoginIframe?: boolean;
|
|
155
|
+
checkLoginIframe?: false;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Set the interval to check login state (in seconds).
|
|
159
|
+
* @default 5
|
|
160
|
+
*
|
|
161
|
+
* NOTE oidc-spa: Not applicable
|
|
162
|
+
*/
|
|
163
|
+
//checkLoginIframeInterval?: number;
|
|
164
|
+
checkLoginIframeInterval?: undefined;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Set the OpenID Connect response mode to send to Keycloak upon login.
|
|
168
|
+
* @default fragment After successful authentication Keycloak will redirect
|
|
169
|
+
* to JavaScript application with OpenID Connect parameters
|
|
170
|
+
* added in URL fragment. This is generally safer and
|
|
171
|
+
* recommended over query.
|
|
172
|
+
*
|
|
173
|
+
* NOTE oidc-spa: We enforce 'fragment' against keycloak
|
|
174
|
+
*/
|
|
175
|
+
//responseMode?: KeycloakResponseMode;
|
|
176
|
+
responseMode?: "fragment";
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Specifies a default uri to redirect to after login or logout.
|
|
180
|
+
* This is currently supported for adapter 'cordova-native' and 'default'
|
|
181
|
+
*/
|
|
182
|
+
redirectUri?: string;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Specifies an uri to redirect to after silent check-sso.
|
|
186
|
+
* Silent check-sso will only happen, when this redirect uri is given and
|
|
187
|
+
* the specified uri is available within the application.
|
|
188
|
+
*
|
|
189
|
+
* NOTE oidc-spa: Not applicable, we use the root as silentSsoRedirectUri
|
|
190
|
+
*/
|
|
191
|
+
// silentCheckSsoRedirectUri?: string;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Specifies whether the silent check-sso should fallback to "non-silent"
|
|
195
|
+
* check-sso when 3rd party cookies are blocked by the browser. Defaults
|
|
196
|
+
* to true.
|
|
197
|
+
*
|
|
198
|
+
* NOTE oidc-spa: We enforce true.
|
|
199
|
+
*/
|
|
200
|
+
//silentCheckSsoFallback?: boolean;
|
|
201
|
+
silentCheckSsoFallback?: true;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Set the OpenID Connect flow.
|
|
205
|
+
* @default standard
|
|
206
|
+
*
|
|
207
|
+
* NOTE oidc-spa: Only standard flow supported, only safe flow for SPAs
|
|
208
|
+
*/
|
|
209
|
+
//flow?: KeycloakFlow;
|
|
210
|
+
flow?: "standard";
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Configures the Proof Key for Code Exchange (PKCE) method to use. This will default to 'S256'.
|
|
214
|
+
* Can be disabled by passing `false`.
|
|
215
|
+
*
|
|
216
|
+
* NOTE oidc-spa: PKCE can't be disabled, we enforce the use of S256.
|
|
217
|
+
*/
|
|
218
|
+
//pkceMethod?: KeycloakPkceMethod;
|
|
219
|
+
pkceMethod?: "S256";
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Enables logging messages from Keycloak to the console.
|
|
223
|
+
* @default false
|
|
224
|
+
*/
|
|
225
|
+
enableLogging?: boolean;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Set the default scope parameter to the login endpoint. Use a space-delimited list of scopes.
|
|
229
|
+
* Note that the scope 'openid' will be always be added to the list of scopes by the adapter.
|
|
230
|
+
* Note that the default scope specified here is overwritten if the `login()` options specify scope explicitly.
|
|
231
|
+
*/
|
|
232
|
+
scope?: string;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Configures how long will Keycloak adapter wait for receiving messages from server in ms. This is used,
|
|
236
|
+
* for example, when waiting for response of 3rd party cookies check.
|
|
237
|
+
*
|
|
238
|
+
* @default 10000
|
|
239
|
+
*
|
|
240
|
+
* NOTE oidc-spa: Computed dynamically depending of the connection speed, at least 7 seconds in production.
|
|
241
|
+
*/
|
|
242
|
+
//messageReceiveTimeout?: number
|
|
243
|
+
messageReceiveTimeout?: undefined;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* When onLoad is 'login-required', sets the 'ui_locales' query param in compliance with section 3.1.2.1
|
|
247
|
+
* of the OIDC 1.0 specification.
|
|
248
|
+
*/
|
|
249
|
+
locale?: string;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* HTTP method for calling the end_session endpoint. Defaults to 'GET'.
|
|
253
|
+
*
|
|
254
|
+
* NOTE oidc-spa: only 'GET' supported.
|
|
255
|
+
*/
|
|
256
|
+
//logoutMethod?: 'GET' | 'POST';
|
|
257
|
+
logoutMethod?: "GET";
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export interface KeycloakLoginOptions {
|
|
261
|
+
/**
|
|
262
|
+
* Specifies the scope parameter for the login url
|
|
263
|
+
* The scope 'openid' will be added to the scope if it is missing or undefined.
|
|
264
|
+
*
|
|
265
|
+
* NOTE oidc-spa: The scopes can be provided only at the init() level.
|
|
266
|
+
* If it's a problem for you please open an issue on https://github.com/keycloakify/oidc-spa
|
|
267
|
+
*/
|
|
268
|
+
//scope?: string;
|
|
269
|
+
scope?: undefined;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Specifies the uri to redirect to after login.
|
|
273
|
+
*
|
|
274
|
+
* NOTE oidc-spa: In this implementation the redirectUri is not actually
|
|
275
|
+
* the parameter that will be specified to keycloak as redirect_uri,
|
|
276
|
+
* functionally however it's the same for you, this is where the user will
|
|
277
|
+
* be redirected after login.
|
|
278
|
+
*/
|
|
279
|
+
redirectUri?: string;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* By default the login screen is displayed if the user is not logged into
|
|
283
|
+
* Keycloak. To only authenticate to the application if the user is already
|
|
284
|
+
* logged in and not display the login page if the user is not logged in, set
|
|
285
|
+
* this option to `'none'`. To always require re-authentication and ignore
|
|
286
|
+
* SSO, set this option to `'login'`. To always prompt the user for consent,
|
|
287
|
+
* set this option to `'consent'`. This ensures that consent is requested,
|
|
288
|
+
* even if it has been given previously.
|
|
289
|
+
*
|
|
290
|
+
* NOTE oidc-spa: This feature is not supported, as we believe it
|
|
291
|
+
* exposes too much complexity to the user. oidc-spa manages this internally.
|
|
292
|
+
* While this approach offers less fine-grained control, the defaults are
|
|
293
|
+
* sensible and designed to spare you from dealing with protocol intricacies.
|
|
294
|
+
* If you feel otherwise, we welcome discussion—please open an issue at https://github.com/keycloakify/oidc-spa.
|
|
295
|
+
*/
|
|
296
|
+
//prompt?: "none" | "login" | "consent";
|
|
297
|
+
prompt?: undefined;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* If value is `'register'` then user is redirected to registration page,
|
|
301
|
+
* otherwise to login page.
|
|
302
|
+
*/
|
|
303
|
+
action?: string;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Used just if user is already authenticated. Specifies maximum time since
|
|
307
|
+
* the authentication of user happened. If user is already authenticated for
|
|
308
|
+
* longer time than `'maxAge'`, the SSO is ignored and he will need to
|
|
309
|
+
* authenticate again.
|
|
310
|
+
*
|
|
311
|
+
* NOTE oidc-spa: Not supported as we think this are policies that should
|
|
312
|
+
* be defined and enforced on the server using "Idle Session Lifetime" and not
|
|
313
|
+
* hard coded in the client.
|
|
314
|
+
*/
|
|
315
|
+
//maxAge?: number;
|
|
316
|
+
maxAge?: undefined;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Used to pre-fill the username/email field on the login form.
|
|
320
|
+
*/
|
|
321
|
+
loginHint?: string;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Sets the `acr` claim of the ID token sent inside the `claims` parameter. See section 5.5.1 of the OIDC 1.0 specification.
|
|
325
|
+
*/
|
|
326
|
+
acr?: Acr;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Configures the 'acr_values' query param in compliance with section 3.1.2.1
|
|
330
|
+
* of the OIDC 1.0 specification.
|
|
331
|
+
* Used to tell Keycloak what level of authentication the user needs.
|
|
332
|
+
*/
|
|
333
|
+
acrValues?: string;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Used to tell Keycloak which IDP the user wants to authenticate with.
|
|
337
|
+
*/
|
|
338
|
+
idpHint?: string;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Sets the 'ui_locales' query param in compliance with section 3.1.2.1
|
|
342
|
+
* of the OIDC 1.0 specification.
|
|
343
|
+
*/
|
|
344
|
+
locale?: string;
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Specifies arguments that are passed to the Cordova in-app-browser (if applicable).
|
|
348
|
+
* Options 'hidden' and 'location' are not affected by these arguments.
|
|
349
|
+
* All available options are defined at https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/.
|
|
350
|
+
* Example of use: { zoom: "no", hardwareback: "yes" }
|
|
351
|
+
*
|
|
352
|
+
* NOTE oidc-spa: Not supported.
|
|
353
|
+
*/
|
|
354
|
+
//cordovaOptions?: { [optionName: string]: string };
|
|
355
|
+
cordovaOptions?: undefined;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export interface KeycloakLogoutOptions {
|
|
359
|
+
/**
|
|
360
|
+
* Specifies the uri to redirect to after logout.
|
|
361
|
+
*/
|
|
362
|
+
redirectUri?: string;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* HTTP method for calling the end_session endpoint. Defaults to 'GET'.
|
|
366
|
+
*
|
|
367
|
+
* NOTE oidc-spa: Only 'GET' supported.
|
|
368
|
+
*/
|
|
369
|
+
//logoutMethod?: 'GET' | 'POST';
|
|
370
|
+
logoutMethod?: "GET";
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export interface KeycloakRegisterOptions extends Omit<KeycloakLoginOptions, "action"> {}
|
|
374
|
+
|
|
375
|
+
export interface KeycloakAccountOptions {
|
|
376
|
+
/**
|
|
377
|
+
* Specifies the uri to redirect to when redirecting back to the application.
|
|
378
|
+
*/
|
|
379
|
+
redirectUri?: string;
|
|
380
|
+
}
|
|
381
|
+
export interface KeycloakError {
|
|
382
|
+
error: string;
|
|
383
|
+
error_description: string;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export interface KeycloakRedirectUriOptions {
|
|
387
|
+
/**
|
|
388
|
+
* Specifies the uri to redirect to after login.
|
|
389
|
+
*/
|
|
390
|
+
redirectUri?: string;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export interface KeycloakAdapter {
|
|
394
|
+
login(options?: KeycloakLoginOptions): Promise<void>;
|
|
395
|
+
logout(options?: KeycloakLogoutOptions): Promise<void>;
|
|
396
|
+
register(options?: KeycloakRegisterOptions): Promise<void>;
|
|
397
|
+
accountManagement(): Promise<void>;
|
|
398
|
+
redirectUri(options?: KeycloakRedirectUriOptions): string;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export interface KeycloakProfile {
|
|
402
|
+
id?: string;
|
|
403
|
+
username?: string;
|
|
404
|
+
email?: string;
|
|
405
|
+
firstName?: string;
|
|
406
|
+
lastName?: string;
|
|
407
|
+
enabled?: boolean;
|
|
408
|
+
emailVerified?: boolean;
|
|
409
|
+
totp?: boolean;
|
|
410
|
+
createdTimestamp?: number;
|
|
411
|
+
attributes?: Record<string, unknown>;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export interface KeycloakTokenParsed {
|
|
415
|
+
iss?: string;
|
|
416
|
+
sub?: string;
|
|
417
|
+
aud?: string;
|
|
418
|
+
exp?: number;
|
|
419
|
+
iat?: number;
|
|
420
|
+
auth_time?: number;
|
|
421
|
+
nonce?: string;
|
|
422
|
+
acr?: string;
|
|
423
|
+
amr?: string;
|
|
424
|
+
azp?: string;
|
|
425
|
+
session_state?: string;
|
|
426
|
+
realm_access?: KeycloakRoles;
|
|
427
|
+
resource_access?: KeycloakResourceAccess;
|
|
428
|
+
[key: string]: any; // Add other attributes here.
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
export interface KeycloakResourceAccess {
|
|
432
|
+
[key: string]: KeycloakRoles;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export interface KeycloakRoles {
|
|
436
|
+
roles: string[];
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export interface KeycloakUserInfo {
|
|
440
|
+
sub: string;
|
|
441
|
+
[key: string]: any;
|
|
442
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { assert } from "../vendor/frontend/tsafe";
|
|
2
|
+
import { isKeycloak } from "./isKeycloak";
|
|
3
|
+
|
|
4
|
+
export type KeycloakIssuerUriParsed = {
|
|
5
|
+
origin: string;
|
|
6
|
+
realm: string;
|
|
7
|
+
/** If defined starts with / and end with no `/` */
|
|
8
|
+
kcHttpRelativePath: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function parseKeycloakIssuerUri(params: { issuerUri: string }): KeycloakIssuerUriParsed {
|
|
12
|
+
const { issuerUri } = params;
|
|
13
|
+
|
|
14
|
+
assert(isKeycloak({ issuerUri }));
|
|
15
|
+
|
|
16
|
+
const url = new URL(issuerUri.replace(/\/$/, ""));
|
|
17
|
+
|
|
18
|
+
const split = url.pathname.split("/realms/");
|
|
19
|
+
|
|
20
|
+
assert(split.length === 2);
|
|
21
|
+
|
|
22
|
+
const [kcHttpRelativePath, realm] = split;
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
origin: url.origin,
|
|
26
|
+
realm,
|
|
27
|
+
kcHttpRelativePath: kcHttpRelativePath === "" ? undefined : kcHttpRelativePath
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { toFullyQualifiedUrl } from "../tools/toFullyQualifiedUrl";
|
|
2
|
+
|
|
3
|
+
import { type KeycloakIssuerUriParsed, parseKeycloakIssuerUri } from "./keycloakIssuerUriParsed";
|
|
4
|
+
|
|
5
|
+
export type KeycloakUtils = {
|
|
6
|
+
issuerUriParsed: KeycloakIssuerUriParsed;
|
|
7
|
+
adminConsoleUrl: string;
|
|
8
|
+
adminConsoleUrl_master: string;
|
|
9
|
+
getAccountUrl: (params: {
|
|
10
|
+
clientId: string;
|
|
11
|
+
backToAppFromAccountUrl: string;
|
|
12
|
+
locale?: string;
|
|
13
|
+
}) => string;
|
|
14
|
+
fetchUserProfile: (params: { accessToken: string }) => Promise<KeycloakProfile>;
|
|
15
|
+
fetchUserInfo: (params: { accessToken: string }) => Promise<KeycloakUserInfo>;
|
|
16
|
+
transformUrlBeforeRedirectForRegister: (authorizationUrl: string) => string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type KeycloakProfile = {
|
|
20
|
+
id?: string;
|
|
21
|
+
username?: string;
|
|
22
|
+
email?: string;
|
|
23
|
+
firstName?: string;
|
|
24
|
+
lastName?: string;
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
emailVerified?: boolean;
|
|
27
|
+
totp?: boolean;
|
|
28
|
+
createdTimestamp?: number;
|
|
29
|
+
attributes?: Record<string, unknown>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type KeycloakUserInfo = {
|
|
33
|
+
sub: string;
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export function createKeycloakUtils(params: { issuerUri: string }): KeycloakUtils {
|
|
38
|
+
const { issuerUri } = params;
|
|
39
|
+
|
|
40
|
+
const issuerUriParsed = parseKeycloakIssuerUri({ issuerUri });
|
|
41
|
+
|
|
42
|
+
const keycloakServerUrl = `${issuerUriParsed.origin}${issuerUriParsed.kcHttpRelativePath ?? ""}`;
|
|
43
|
+
|
|
44
|
+
const getAdminConsoleUrl = (realm: string) =>
|
|
45
|
+
`${keycloakServerUrl}/admin/${encodeURIComponent(realm)}/console`;
|
|
46
|
+
|
|
47
|
+
const realmUrl = `${keycloakServerUrl}/realms/${encodeURIComponent(issuerUriParsed.realm)}`;
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
issuerUriParsed,
|
|
51
|
+
adminConsoleUrl: getAdminConsoleUrl(issuerUriParsed.realm),
|
|
52
|
+
adminConsoleUrl_master: getAdminConsoleUrl("master"),
|
|
53
|
+
getAccountUrl: ({ clientId, backToAppFromAccountUrl, locale }) => {
|
|
54
|
+
const accountUrlObj = new URL(
|
|
55
|
+
`${keycloakServerUrl}/realms/${issuerUriParsed.realm}/account`
|
|
56
|
+
);
|
|
57
|
+
accountUrlObj.searchParams.set("referrer", clientId);
|
|
58
|
+
accountUrlObj.searchParams.set(
|
|
59
|
+
"referrer_uri",
|
|
60
|
+
toFullyQualifiedUrl({
|
|
61
|
+
urlish: backToAppFromAccountUrl,
|
|
62
|
+
doAssertNoQueryParams: false
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
if (locale !== undefined) {
|
|
66
|
+
accountUrlObj.searchParams.set("kc_locale", locale);
|
|
67
|
+
}
|
|
68
|
+
return accountUrlObj.href;
|
|
69
|
+
},
|
|
70
|
+
fetchUserProfile: ({ accessToken }) =>
|
|
71
|
+
fetch(`${realmUrl}/account`, {
|
|
72
|
+
headers: {
|
|
73
|
+
Accept: "application/json",
|
|
74
|
+
Authorization: `Bearer ${accessToken}`
|
|
75
|
+
}
|
|
76
|
+
}).then(r => r.json()),
|
|
77
|
+
fetchUserInfo: ({ accessToken }) =>
|
|
78
|
+
fetch(`${realmUrl}/protocol/openid-connect/userinfo`, {
|
|
79
|
+
headers: {
|
|
80
|
+
Accept: "application/json",
|
|
81
|
+
Authorization: `Bearer ${accessToken}`
|
|
82
|
+
}
|
|
83
|
+
}).then(r => r.json()),
|
|
84
|
+
transformUrlBeforeRedirectForRegister: authorizationUrl => {
|
|
85
|
+
const urlObj = new URL(authorizationUrl);
|
|
86
|
+
urlObj.pathname = urlObj.pathname.replace(/\/auth$/, "/registrations");
|
|
87
|
+
return urlObj.href;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./keycloak/keycloak-js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./oidc";
|