oidc-spa 7.1.10 → 7.2.0-rc.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 +235 -352
- package/backend.js.map +1 -1
- package/core/AuthResponse.js +12 -49
- package/core/AuthResponse.js.map +1 -1
- package/core/Oidc.d.ts +1 -2
- package/core/Oidc.js.map +1 -1
- package/core/OidcInitializationError.d.ts +0 -13
- package/core/OidcInitializationError.js +8 -318
- package/core/OidcInitializationError.js.map +1 -1
- package/core/OidcMetadata.js +1 -1
- package/core/OidcMetadata.js.map +1 -1
- package/core/StateData.d.ts +5 -5
- package/core/StateData.js +25 -25
- package/core/StateData.js.map +1 -1
- package/core/configId.js +1 -1
- package/core/configId.js.map +1 -1
- package/core/createOidc.d.ts +8 -0
- package/core/createOidc.js +1030 -1292
- package/core/createOidc.js.map +1 -1
- package/core/diagnostic.d.ts +14 -0
- package/core/diagnostic.js +214 -0
- package/core/diagnostic.js.map +1 -0
- package/core/evtIsUserActive.js +26 -27
- package/core/evtIsUserActive.js.map +1 -1
- package/core/handleOidcCallback.js +99 -154
- package/core/handleOidcCallback.js.map +1 -1
- package/core/iframeMessageProtection.d.ts +1 -1
- package/core/iframeMessageProtection.js +40 -106
- package/core/iframeMessageProtection.js.map +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +3 -3
- package/core/index.js.map +1 -1
- package/core/initialLocationHref.js +1 -1
- package/core/initialLocationHref.js.map +1 -1
- package/core/isNewBrowserSession.js +8 -8
- package/core/isNewBrowserSession.js.map +1 -1
- package/core/loginOrGoToAuthServer.d.ts +1 -1
- package/core/loginOrGoToAuthServer.js +188 -310
- package/core/loginOrGoToAuthServer.js.map +1 -1
- package/core/loginPropagationToOtherTabs.js +15 -16
- package/core/loginPropagationToOtherTabs.js.map +1 -1
- package/core/loginSilent.d.ts +2 -3
- package/core/loginSilent.js +118 -214
- package/core/loginSilent.js.map +1 -1
- package/core/logoutPropagationToOtherTabs.js +15 -16
- package/core/logoutPropagationToOtherTabs.js.map +1 -1
- package/core/oidcClientTsUserToTokens.d.ts +1 -1
- package/core/oidcClientTsUserToTokens.js +75 -72
- package/core/oidcClientTsUserToTokens.js.map +1 -1
- package/core/ongoingLoginOrRefreshProcesses.js +23 -89
- package/core/ongoingLoginOrRefreshProcesses.js.map +1 -1
- package/core/persistedAuthState.js +13 -13
- package/core/persistedAuthState.js.map +1 -1
- package/entrypoint.js +9 -9
- package/entrypoint.js.map +1 -1
- package/esm/core/AuthResponse.d.ts +5 -0
- package/{src/core/AuthResponse.ts → esm/core/AuthResponse.js} +3 -9
- package/esm/core/AuthResponse.js.map +1 -0
- package/esm/core/Oidc.d.ts +126 -0
- package/esm/core/Oidc.js +2 -0
- package/esm/core/Oidc.js.map +1 -0
- package/esm/core/OidcInitializationError.d.ts +7 -0
- package/esm/core/OidcInitializationError.js +17 -0
- package/esm/core/OidcInitializationError.js.map +1 -0
- package/{src/core/OidcMetadata.ts → esm/core/OidcMetadata.d.ts} +0 -5
- package/esm/core/OidcMetadata.js +3 -0
- package/esm/core/OidcMetadata.js.map +1 -0
- package/esm/core/StateData.d.ts +42 -0
- package/esm/core/StateData.js +55 -0
- package/esm/core/StateData.js.map +1 -0
- package/esm/core/configId.d.ts +4 -0
- package/esm/core/configId.js +4 -0
- package/esm/core/configId.js.map +1 -0
- package/esm/core/createOidc.d.ts +132 -0
- package/{src/core/createOidc.ts → esm/core/createOidc.js} +282 -826
- package/esm/core/createOidc.js.map +1 -0
- package/esm/core/diagnostic.d.ts +14 -0
- package/{src/core/OidcInitializationError.ts → esm/core/diagnostic.js} +40 -117
- package/esm/core/diagnostic.js.map +1 -0
- package/esm/core/evtIsUserActive.d.ts +5 -0
- package/{src/core/evtIsUserActive.ts → esm/core/evtIsUserActive.js} +14 -46
- package/esm/core/evtIsUserActive.js.map +1 -0
- package/esm/core/handleOidcCallback.d.ts +13 -0
- package/{src/core/handleOidcCallback.ts → esm/core/handleOidcCallback.js} +56 -131
- package/esm/core/handleOidcCallback.js.map +1 -0
- package/esm/core/iframeMessageProtection.d.ts +20 -0
- package/{src/core/iframeMessageProtection.ts → esm/core/iframeMessageProtection.js} +14 -49
- package/esm/core/iframeMessageProtection.js.map +1 -0
- package/{src/core/index.ts → esm/core/index.d.ts} +1 -1
- package/esm/core/index.js +4 -0
- package/esm/core/index.js.map +1 -0
- package/esm/core/initialLocationHref.d.ts +1 -0
- package/{src/core/initialLocationHref.ts → esm/core/initialLocationHref.js} +1 -1
- package/esm/core/initialLocationHref.js.map +1 -0
- package/esm/core/isNewBrowserSession.d.ts +9 -0
- package/{src/core/isNewBrowserSession.ts → esm/core/isNewBrowserSession.js} +3 -15
- package/esm/core/isNewBrowserSession.js.map +1 -0
- package/esm/core/loginOrGoToAuthServer.d.ts +40 -0
- package/{src/core/loginOrGoToAuthServer.ts → esm/core/loginOrGoToAuthServer.js} +60 -168
- package/esm/core/loginOrGoToAuthServer.js.map +1 -0
- package/esm/core/loginPropagationToOtherTabs.d.ts +8 -0
- package/{src/core/loginPropagationToOtherTabs.ts → esm/core/loginPropagationToOtherTabs.js} +7 -25
- package/esm/core/loginPropagationToOtherTabs.js.map +1 -0
- package/esm/core/loginSilent.d.ts +28 -0
- package/esm/core/loginSilent.js +125 -0
- package/esm/core/loginSilent.js.map +1 -0
- package/esm/core/logoutPropagationToOtherTabs.d.ts +10 -0
- package/{src/core/logoutPropagationToOtherTabs.ts → esm/core/logoutPropagationToOtherTabs.js} +8 -28
- package/esm/core/logoutPropagationToOtherTabs.js.map +1 -0
- package/esm/core/oidcClientTsUserToTokens.d.ts +11 -0
- package/esm/core/oidcClientTsUserToTokens.js +155 -0
- package/esm/core/oidcClientTsUserToTokens.js.map +1 -0
- package/esm/core/ongoingLoginOrRefreshProcesses.d.ts +6 -0
- package/{src/core/ongoingLoginOrRefreshProcesses.ts → esm/core/ongoingLoginOrRefreshProcesses.js} +6 -24
- package/esm/core/ongoingLoginOrRefreshProcesses.js.map +1 -0
- package/esm/core/persistedAuthState.d.ts +28 -0
- package/esm/core/persistedAuthState.js +64 -0
- package/esm/core/persistedAuthState.js.map +1 -0
- package/esm/entrypoint.d.ts +7 -0
- package/{src/entrypoint.ts → esm/entrypoint.js} +3 -26
- package/esm/entrypoint.js.map +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +2 -0
- package/esm/index.js.map +1 -0
- package/esm/keycloak/index.d.ts +3 -0
- package/esm/keycloak/index.js +3 -0
- package/esm/keycloak/index.js.map +1 -0
- package/esm/keycloak/isKeycloak.d.ts +3 -0
- package/esm/keycloak/isKeycloak.js +17 -0
- package/esm/keycloak/isKeycloak.js.map +1 -0
- package/esm/keycloak/keycloak-js/Keycloak.d.ts +284 -0
- package/esm/keycloak/keycloak-js/Keycloak.js +774 -0
- package/esm/keycloak/keycloak-js/Keycloak.js.map +1 -0
- package/esm/keycloak/keycloak-js/index.d.ts +2 -0
- package/esm/keycloak/keycloak-js/index.js +2 -0
- package/esm/keycloak/keycloak-js/index.js.map +1 -0
- package/esm/keycloak/keycloak-js/types.d.ts +361 -0
- package/esm/keycloak/keycloak-js/types.js +2 -0
- package/esm/keycloak/keycloak-js/types.js.map +1 -0
- package/esm/keycloak/keycloakIssuerUriParsed.d.ts +9 -0
- package/esm/keycloak/keycloakIssuerUriParsed.js +16 -0
- package/esm/keycloak/keycloakIssuerUriParsed.js.map +1 -0
- package/esm/keycloak/keycloakUtils.d.ts +37 -0
- package/esm/keycloak/keycloakUtils.js +44 -0
- package/esm/keycloak/keycloakUtils.js.map +1 -0
- package/esm/keycloak-js.d.ts +1 -0
- package/esm/keycloak-js.js +2 -0
- package/esm/keycloak-js.js.map +1 -0
- package/esm/mock/index.js +2 -0
- package/esm/mock/index.js.map +1 -0
- package/esm/mock/oidc.d.ts +19 -0
- package/{src/mock/oidc.ts → esm/mock/oidc.js} +28 -88
- package/esm/mock/oidc.js.map +1 -0
- package/esm/mock/react.d.ts +58 -0
- package/esm/mock/react.js +7 -0
- package/esm/mock/react.js.map +1 -0
- package/esm/react/index.js +2 -0
- package/esm/react/index.js.map +1 -0
- package/esm/react/react.d.ts +102 -0
- package/esm/react/react.js +221 -0
- package/esm/react/react.js.map +1 -0
- package/esm/tools/Deferred.d.ts +14 -0
- package/esm/tools/Deferred.js +23 -0
- package/esm/tools/Deferred.js.map +1 -0
- package/esm/tools/EphemeralSessionStorage.d.ts +12 -0
- package/{src/tools/EphemeralSessionStorage.ts → esm/tools/EphemeralSessionStorage.js} +30 -112
- package/esm/tools/EphemeralSessionStorage.js.map +1 -0
- package/esm/tools/Evt.d.ts +11 -0
- package/{src/tools/Evt.ts → esm/tools/Evt.js} +7 -25
- package/esm/tools/Evt.js.map +1 -0
- package/esm/tools/StatefulEvt.d.ts +12 -0
- package/esm/tools/StatefulEvt.js +21 -0
- package/esm/tools/StatefulEvt.js.map +1 -0
- package/esm/tools/ValueOrAsyncGetter.js +2 -0
- package/esm/tools/ValueOrAsyncGetter.js.map +1 -0
- package/esm/tools/asymmetricEncryption.d.ts +18 -0
- package/esm/tools/asymmetricEncryption.js +85 -0
- package/esm/tools/asymmetricEncryption.js.map +1 -0
- package/esm/tools/base64.d.ts +2 -0
- package/{src/tools/base64.ts → esm/tools/base64.js} +3 -3
- package/esm/tools/base64.js.map +1 -0
- package/esm/tools/createObjectThatThrowsIfAccessed.d.ts +8 -0
- package/{src/tools/createObjectThatThrowsIfAccessed.ts → esm/tools/createObjectThatThrowsIfAccessed.js} +7 -18
- package/esm/tools/createObjectThatThrowsIfAccessed.js.map +1 -0
- package/esm/tools/decodeJwt.d.ts +25 -0
- package/esm/tools/decodeJwt.js +60 -0
- package/esm/tools/decodeJwt.js.map +1 -0
- package/esm/tools/generateUrlSafeRandom.d.ts +3 -0
- package/{src/tools/generateUrlSafeRandom.ts → esm/tools/generateUrlSafeRandom.js} +5 -8
- package/esm/tools/generateUrlSafeRandom.js.map +1 -0
- package/esm/tools/getDownlinkAndRtt.d.ts +4 -0
- package/{src/tools/getDownlinkAndRtt.ts → esm/tools/getDownlinkAndRtt.js} +6 -10
- package/esm/tools/getDownlinkAndRtt.js.map +1 -0
- package/esm/tools/getIsOnline.d.ts +7 -0
- package/{src/tools/getIsOnline.ts → esm/tools/getIsOnline.js} +3 -9
- package/esm/tools/getIsOnline.js.map +1 -0
- package/esm/tools/getIsValidRemoteJson.d.ts +1 -0
- package/esm/tools/getIsValidRemoteJson.js +15 -0
- package/esm/tools/getIsValidRemoteJson.js.map +1 -0
- package/esm/tools/getPrUserInteraction.d.ts +4 -0
- package/{src/tools/getPrUserInteraction.ts → esm/tools/getPrUserInteraction.js} +2 -6
- package/esm/tools/getPrUserInteraction.js.map +1 -0
- package/esm/tools/getUserEnvironmentInfo.d.ts +1 -0
- package/esm/tools/getUserEnvironmentInfo.js +50 -0
- package/esm/tools/getUserEnvironmentInfo.js.map +1 -0
- package/esm/tools/haveSharedParentDomain.d.ts +4 -0
- package/{src/tools/haveSharedParentDomain.ts → esm/tools/haveSharedParentDomain.js} +3 -5
- package/esm/tools/haveSharedParentDomain.js.map +1 -0
- package/esm/tools/isDev.d.ts +1 -0
- package/{src/tools/isDev.ts → esm/tools/isDev.js} +5 -12
- package/esm/tools/isDev.js.map +1 -0
- package/esm/tools/parseKeycloakIssuerUri.d.ts +30 -0
- package/esm/tools/parseKeycloakIssuerUri.js +33 -0
- package/esm/tools/parseKeycloakIssuerUri.js.map +1 -0
- package/esm/tools/readExpirationTimeInJwt.d.ts +1 -0
- package/{src/tools/readExpirationTimeInJwt.ts → esm/tools/readExpirationTimeInJwt.js} +6 -7
- package/esm/tools/readExpirationTimeInJwt.js.map +1 -0
- package/esm/tools/startCountdown.d.ts +11 -0
- package/{src/tools/startCountdown.ts → esm/tools/startCountdown.js} +6 -17
- package/esm/tools/startCountdown.js.map +1 -0
- package/esm/tools/subscribeToUserInteraction.d.ts +6 -0
- package/{src/tools/subscribeToUserInteraction.ts → esm/tools/subscribeToUserInteraction.js} +4 -13
- package/esm/tools/subscribeToUserInteraction.js.map +1 -0
- package/esm/tools/toFullyQualifiedUrl.d.ts +10 -0
- package/{src/tools/toFullyQualifiedUrl.ts → esm/tools/toFullyQualifiedUrl.js} +7 -25
- package/esm/tools/toFullyQualifiedUrl.js.map +1 -0
- package/esm/tools/toHumanReadableDuration.d.ts +1 -0
- package/{src/tools/toHumanReadableDuration.ts → esm/tools/toHumanReadableDuration.js} +8 -5
- package/esm/tools/toHumanReadableDuration.js.map +1 -0
- package/esm/tools/urlSearchParams.d.ts +19 -0
- package/{src/tools/urlSearchParams.ts → esm/tools/urlSearchParams.js} +24 -70
- package/esm/tools/urlSearchParams.js.map +1 -0
- package/esm/tools/workerTimers.d.ts +5 -0
- package/{src/tools/workerTimers.ts → esm/tools/workerTimers.js} +7 -27
- package/esm/tools/workerTimers.js.map +1 -0
- package/esm/vendor/frontend/oidc-client-ts.d.ts +1 -0
- package/esm/vendor/frontend/oidc-client-ts.js +3636 -0
- package/{src/vendor/frontend/tsafe.ts → esm/vendor/frontend/tsafe.d.ts} +1 -0
- package/esm/vendor/frontend/tsafe.js +1 -0
- package/esm/vendor/frontend/worker-timers.js +1 -0
- package/index.d.ts +1 -1
- package/index.js +1 -2
- package/index.js.map +1 -1
- package/keycloak/index.d.ts +3 -0
- package/keycloak/index.js +8 -0
- package/keycloak/index.js.map +1 -0
- package/keycloak/isKeycloak.d.ts +3 -0
- package/keycloak/isKeycloak.js +20 -0
- package/keycloak/isKeycloak.js.map +1 -0
- package/keycloak/keycloak-js/Keycloak.d.ts +284 -0
- package/keycloak/keycloak-js/Keycloak.js +778 -0
- package/keycloak/keycloak-js/Keycloak.js.map +1 -0
- package/keycloak/keycloak-js/index.d.ts +2 -0
- package/keycloak/keycloak-js/index.js +6 -0
- package/keycloak/keycloak-js/index.js.map +1 -0
- package/keycloak/keycloak-js/types.d.ts +361 -0
- package/keycloak/keycloak-js/types.js +3 -0
- package/keycloak/keycloak-js/types.js.map +1 -0
- package/keycloak/keycloakIssuerUriParsed.d.ts +9 -0
- package/keycloak/keycloakIssuerUriParsed.js +19 -0
- package/keycloak/keycloakIssuerUriParsed.js.map +1 -0
- package/keycloak/keycloakUtils.d.ts +37 -0
- package/keycloak/keycloakUtils.js +47 -0
- package/keycloak/keycloakUtils.js.map +1 -0
- package/keycloak-js.d.ts +1 -0
- package/keycloak-js.js +18 -0
- package/keycloak-js.js.map +1 -0
- package/mock/index.js.map +1 -1
- package/mock/oidc.js +147 -194
- package/mock/oidc.js.map +1 -1
- package/mock/react.js +2 -2
- package/mock/react.js.map +1 -1
- package/package.json +74 -299
- package/react/index.js.map +1 -1
- package/react/react.js +133 -244
- package/react/react.js.map +1 -1
- package/tools/Deferred.js +13 -35
- package/tools/Deferred.js.map +1 -1
- package/tools/EphemeralSessionStorage.js +46 -48
- package/tools/EphemeralSessionStorage.js.map +1 -1
- package/tools/Evt.js +14 -14
- package/tools/Evt.js.map +1 -1
- package/tools/StatefulEvt.js +5 -5
- package/tools/StatefulEvt.js.map +1 -1
- package/tools/ValueOrAsyncGetter.js.map +1 -1
- package/tools/asymmetricEncryption.js +81 -172
- package/tools/asymmetricEncryption.js.map +1 -1
- package/tools/base64.js +2 -2
- package/tools/base64.js.map +1 -1
- package/tools/createObjectThatThrowsIfAccessed.js +13 -61
- package/tools/createObjectThatThrowsIfAccessed.js.map +1 -1
- package/tools/decodeJwt.d.ts +25 -2
- package/tools/decodeJwt.js +61 -3
- package/tools/decodeJwt.js.map +1 -1
- package/tools/generateUrlSafeRandom.js +5 -30
- package/tools/generateUrlSafeRandom.js.map +1 -1
- package/tools/getDownlinkAndRtt.js +8 -30
- package/tools/getDownlinkAndRtt.js.map +1 -1
- package/tools/getIsOnline.js +3 -3
- package/tools/getIsOnline.js.map +1 -1
- package/tools/getIsValidRemoteJson.js +12 -59
- package/tools/getIsValidRemoteJson.js.map +1 -1
- package/tools/getPrUserInteraction.js +4 -4
- package/tools/getPrUserInteraction.js.map +1 -1
- package/tools/getUserEnvironmentInfo.js +17 -12
- package/tools/getUserEnvironmentInfo.js.map +1 -1
- package/tools/haveSharedParentDomain.js +5 -5
- package/tools/haveSharedParentDomain.js.map +1 -1
- package/tools/isDev.js +2 -2
- package/tools/isDev.js.map +1 -1
- package/tools/parseKeycloakIssuerUri.d.ts +2 -0
- package/tools/parseKeycloakIssuerUri.js +11 -42
- package/tools/parseKeycloakIssuerUri.js.map +1 -1
- package/tools/readExpirationTimeInJwt.js +4 -4
- package/tools/readExpirationTimeInJwt.js.map +1 -1
- package/tools/startCountdown.js +17 -65
- package/tools/startCountdown.js.map +1 -1
- package/tools/subscribeToUserInteraction.js +17 -66
- package/tools/subscribeToUserInteraction.js.map +1 -1
- package/tools/toFullyQualifiedUrl.js +7 -7
- package/tools/toFullyQualifiedUrl.js.map +1 -1
- package/tools/toHumanReadableDuration.js +13 -13
- package/tools/toHumanReadableDuration.js.map +1 -1
- package/tools/urlSearchParams.js +28 -50
- package/tools/urlSearchParams.js.map +1 -1
- package/tools/workerTimers.js +10 -10
- package/tools/workerTimers.js.map +1 -1
- package/vendor/frontend/oidc-client-ts.d.ts +1 -0
- package/vendor/frontend/oidc-client-ts.js +3686 -0
- package/vendor/frontend/tsafe.d.ts +1 -0
- package/vendor/frontend/tsafe.js +1 -1
- package/LICENSE +0 -21
- package/README.md +0 -185
- package/core/trustedFetch.d.ts +0 -2
- package/core/trustedFetch.js +0 -12
- package/core/trustedFetch.js.map +0 -1
- package/src/backend.ts +0 -391
- package/src/core/Oidc.ts +0 -141
- package/src/core/StateData.ts +0 -118
- package/src/core/configId.ts +0 -3
- package/src/core/loginSilent.ts +0 -206
- package/src/core/oidcClientTsUserToTokens.ts +0 -229
- package/src/core/persistedAuthState.ts +0 -122
- package/src/core/trustedFetch.ts +0 -9
- package/src/index.ts +0 -7
- package/src/mock/react.tsx +0 -11
- package/src/react/react.tsx +0 -460
- package/src/tools/Deferred.ts +0 -39
- package/src/tools/StatefulEvt.ts +0 -38
- package/src/tools/asymmetricEncryption.ts +0 -184
- package/src/tools/decodeJwt.ts +0 -2
- package/src/tools/getIsValidRemoteJson.ts +0 -18
- package/src/tools/getUserEnvironmentInfo.ts +0 -42
- package/src/tools/parseKeycloakIssuerUri.ts +0 -68
- package/src/vendor/backend/evt.ts +0 -2
- package/src/vendor/backend/jsonwebtoken.ts +0 -1
- package/src/vendor/backend/node-fetch.ts +0 -2
- package/src/vendor/backend/node-jose.ts +0 -1
- package/src/vendor/backend/tsafe.ts +0 -5
- package/src/vendor/backend/zod.ts +0 -1
- package/src/vendor/frontend/oidc-client-ts-and-jwt-decode.ts +0 -4
- package/vendor/frontend/oidc-client-ts-and-jwt-decode.d.ts +0 -3
- package/vendor/frontend/oidc-client-ts-and-jwt-decode.js +0 -3
- /package/{src/mock/index.ts → esm/mock/index.d.ts} +0 -0
- /package/{src/react/index.ts → esm/react/index.d.ts} +0 -0
- /package/{src/tools/ValueOrAsyncGetter.ts → esm/tools/ValueOrAsyncGetter.d.ts} +0 -0
- /package/{src/vendor/frontend/worker-timers.ts → esm/vendor/frontend/worker-timers.d.ts} +0 -0
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { typeGuard, id } from "../vendor/frontend/tsafe";
|
|
2
|
-
|
|
3
|
-
function getKey(params: { configId: string }) {
|
|
4
|
-
const { configId } = params;
|
|
5
|
-
|
|
6
|
-
return `oidc-spa:auth-state:${configId}`;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
type PersistedAuthState = PersistedAuthState.LoggedIn | PersistedAuthState.ExplicitlyLoggedOut;
|
|
10
|
-
namespace PersistedAuthState {
|
|
11
|
-
type Common = {
|
|
12
|
-
__brand: "PersistedAuthState-v1";
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type LoggedIn = Common & {
|
|
16
|
-
stateDescription: "logged in";
|
|
17
|
-
untilTime: number | undefined;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type ExplicitlyLoggedOut = Common & {
|
|
21
|
-
stateDescription: "explicitly logged out";
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function persistAuthState(params: {
|
|
26
|
-
configId: string;
|
|
27
|
-
state:
|
|
28
|
-
| {
|
|
29
|
-
stateDescription: "logged in";
|
|
30
|
-
idleSessionLifetimeInSeconds: number | undefined;
|
|
31
|
-
refreshTokenExpirationTime: number | undefined;
|
|
32
|
-
}
|
|
33
|
-
| {
|
|
34
|
-
stateDescription: "explicitly logged out";
|
|
35
|
-
}
|
|
36
|
-
| undefined;
|
|
37
|
-
}) {
|
|
38
|
-
const { configId, state } = params;
|
|
39
|
-
|
|
40
|
-
const key = getKey({ configId });
|
|
41
|
-
|
|
42
|
-
if (state === undefined) {
|
|
43
|
-
localStorage.removeItem(key);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
localStorage.setItem(
|
|
48
|
-
key,
|
|
49
|
-
JSON.stringify(
|
|
50
|
-
id<PersistedAuthState>(
|
|
51
|
-
(() => {
|
|
52
|
-
switch (state.stateDescription) {
|
|
53
|
-
case "logged in":
|
|
54
|
-
return id<PersistedAuthState.LoggedIn>({
|
|
55
|
-
__brand: "PersistedAuthState-v1",
|
|
56
|
-
stateDescription: "logged in",
|
|
57
|
-
untilTime: (() => {
|
|
58
|
-
const { idleSessionLifetimeInSeconds, refreshTokenExpirationTime } =
|
|
59
|
-
state;
|
|
60
|
-
|
|
61
|
-
if (idleSessionLifetimeInSeconds !== undefined) {
|
|
62
|
-
return Date.now() + idleSessionLifetimeInSeconds * 1000;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return refreshTokenExpirationTime;
|
|
66
|
-
})()
|
|
67
|
-
});
|
|
68
|
-
case "explicitly logged out":
|
|
69
|
-
return id<PersistedAuthState.ExplicitlyLoggedOut>({
|
|
70
|
-
__brand: "PersistedAuthState-v1",
|
|
71
|
-
stateDescription: "explicitly logged out"
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
})()
|
|
75
|
-
)
|
|
76
|
-
)
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function getPersistedAuthState(params: {
|
|
81
|
-
configId: string;
|
|
82
|
-
}): PersistedAuthState["stateDescription"] | undefined {
|
|
83
|
-
const { configId } = params;
|
|
84
|
-
|
|
85
|
-
const key = getKey({ configId });
|
|
86
|
-
|
|
87
|
-
const value = localStorage.getItem(key);
|
|
88
|
-
|
|
89
|
-
if (value === null) {
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
let state: unknown;
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
state = JSON.parse(value);
|
|
97
|
-
} catch {
|
|
98
|
-
localStorage.removeItem(key);
|
|
99
|
-
return undefined;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (
|
|
103
|
-
!typeGuard<PersistedAuthState>(
|
|
104
|
-
state,
|
|
105
|
-
state instanceof Object &&
|
|
106
|
-
"__brand" in state &&
|
|
107
|
-
state.__brand === id<PersistedAuthState["__brand"]>("PersistedAuthState-v1")
|
|
108
|
-
)
|
|
109
|
-
) {
|
|
110
|
-
localStorage.removeItem(key);
|
|
111
|
-
return undefined;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (state.stateDescription === "logged in") {
|
|
115
|
-
if (state.untilTime !== undefined && state.untilTime <= Date.now()) {
|
|
116
|
-
localStorage.removeItem(key);
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return state.stateDescription;
|
|
122
|
-
}
|
package/src/core/trustedFetch.ts
DELETED
package/src/index.ts
DELETED
package/src/mock/react.tsx
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { createOidcReactApi_dependencyInjection } from "../react/react";
|
|
2
|
-
import { createMockOidc, type ParamsOfCreateMockOidc } from "./oidc";
|
|
3
|
-
import type { ValueOrAsyncGetter } from "../tools/ValueOrAsyncGetter";
|
|
4
|
-
|
|
5
|
-
/** @see: https://docs.oidc-spa.dev/v/v7/mock */
|
|
6
|
-
export function createMockReactOidc<
|
|
7
|
-
DecodedIdToken extends Record<string, unknown> = Record<string, unknown>,
|
|
8
|
-
AutoLogin extends boolean = false
|
|
9
|
-
>(params: ValueOrAsyncGetter<ParamsOfCreateMockOidc<DecodedIdToken, AutoLogin>>) {
|
|
10
|
-
return createOidcReactApi_dependencyInjection(params, createMockOidc);
|
|
11
|
-
}
|
package/src/react/react.tsx
DELETED
|
@@ -1,460 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useEffect,
|
|
3
|
-
useState,
|
|
4
|
-
createContext,
|
|
5
|
-
useContext,
|
|
6
|
-
type ReactNode,
|
|
7
|
-
type ComponentType,
|
|
8
|
-
type FC,
|
|
9
|
-
type JSX
|
|
10
|
-
} from "react";
|
|
11
|
-
import { type Oidc, createOidc, type ParamsOfCreateOidc, OidcInitializationError } from "../core";
|
|
12
|
-
import { assert, type Equals, type Param0 } from "../vendor/frontend/tsafe";
|
|
13
|
-
import { id } from "../vendor/frontend/tsafe";
|
|
14
|
-
import type { ValueOrAsyncGetter } from "../tools/ValueOrAsyncGetter";
|
|
15
|
-
import { Deferred } from "../tools/Deferred";
|
|
16
|
-
import { toFullyQualifiedUrl } from "../tools/toFullyQualifiedUrl";
|
|
17
|
-
|
|
18
|
-
export type OidcReact<DecodedIdToken extends Record<string, unknown>> =
|
|
19
|
-
| OidcReact.NotLoggedIn
|
|
20
|
-
| OidcReact.LoggedIn<DecodedIdToken>;
|
|
21
|
-
|
|
22
|
-
export namespace OidcReact {
|
|
23
|
-
export type Common = Oidc.Common & {
|
|
24
|
-
useAutoLogoutWarningCountdown: (params: { warningDurationSeconds: number }) => {
|
|
25
|
-
secondsLeft: number | undefined;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type NotLoggedIn = Common & {
|
|
30
|
-
isUserLoggedIn: false;
|
|
31
|
-
login: (params?: {
|
|
32
|
-
extraQueryParams?: Record<string, string | undefined>;
|
|
33
|
-
redirectUrl?: string;
|
|
34
|
-
transformUrlBeforeRedirect?: (url: string) => string;
|
|
35
|
-
doesCurrentHrefRequiresAuth?: boolean;
|
|
36
|
-
}) => Promise<never>;
|
|
37
|
-
initializationError: OidcInitializationError | undefined;
|
|
38
|
-
|
|
39
|
-
decodedIdToken?: never;
|
|
40
|
-
logout?: never;
|
|
41
|
-
renewTokens?: never;
|
|
42
|
-
goToAuthServer?: never;
|
|
43
|
-
backFromAuthServer?: never;
|
|
44
|
-
isNewBrowserSession?: never;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export type LoggedIn<DecodedIdToken extends Record<string, unknown>> = Common & {
|
|
48
|
-
isUserLoggedIn: true;
|
|
49
|
-
decodedIdToken: DecodedIdToken;
|
|
50
|
-
logout: Oidc.LoggedIn["logout"];
|
|
51
|
-
renewTokens: Oidc.LoggedIn["renewTokens"];
|
|
52
|
-
login?: never;
|
|
53
|
-
initializationError?: never;
|
|
54
|
-
goToAuthServer: (params: {
|
|
55
|
-
extraQueryParams?: Record<string, string>;
|
|
56
|
-
redirectUrl?: string;
|
|
57
|
-
transformUrlBeforeRedirect?: (url: string) => string;
|
|
58
|
-
}) => Promise<never>;
|
|
59
|
-
|
|
60
|
-
backFromAuthServer:
|
|
61
|
-
| {
|
|
62
|
-
extraQueryParams: Record<string, string>;
|
|
63
|
-
result: Record<string, string>;
|
|
64
|
-
}
|
|
65
|
-
| undefined;
|
|
66
|
-
|
|
67
|
-
isNewBrowserSession: boolean;
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
{
|
|
71
|
-
type Actual = Param0<OidcReact.NotLoggedIn["login"]>;
|
|
72
|
-
type Expected = Omit<Param0<Oidc.NotLoggedIn["login"]>, "doesCurrentHrefRequiresAuth"> & {
|
|
73
|
-
doesCurrentHrefRequiresAuth?: boolean;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
assert<Equals<Actual, Expected>>();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
type OidcReactApi<DecodedIdToken extends Record<string, unknown>, AutoLogin extends boolean> = {
|
|
80
|
-
OidcProvider: AutoLogin extends true
|
|
81
|
-
? (props: {
|
|
82
|
-
fallback?: ReactNode;
|
|
83
|
-
ErrorFallback?: (props: { initializationError: OidcInitializationError }) => ReactNode;
|
|
84
|
-
children: ReactNode;
|
|
85
|
-
}) => JSX.Element
|
|
86
|
-
: (props: { fallback?: ReactNode; children: ReactNode }) => JSX.Element;
|
|
87
|
-
useOidc: AutoLogin extends true
|
|
88
|
-
? {
|
|
89
|
-
(params?: { assert: "user logged in" }): OidcReact.LoggedIn<DecodedIdToken>;
|
|
90
|
-
}
|
|
91
|
-
: {
|
|
92
|
-
(params?: { assert?: undefined }): OidcReact<DecodedIdToken>;
|
|
93
|
-
(params: { assert: "user logged in" }): OidcReact.LoggedIn<DecodedIdToken>;
|
|
94
|
-
(params: { assert: "user not logged in" }): OidcReact.NotLoggedIn;
|
|
95
|
-
};
|
|
96
|
-
getOidc: () => Promise<
|
|
97
|
-
AutoLogin extends true ? Oidc.LoggedIn<DecodedIdToken> : Oidc<DecodedIdToken>
|
|
98
|
-
>;
|
|
99
|
-
} & (AutoLogin extends true
|
|
100
|
-
? {}
|
|
101
|
-
: {
|
|
102
|
-
withLoginEnforced: <Props extends Record<string, unknown>>(
|
|
103
|
-
Component: ComponentType<Props>,
|
|
104
|
-
params?: {
|
|
105
|
-
onRedirecting: () => JSX.Element | null;
|
|
106
|
-
}
|
|
107
|
-
) => FC<Props>;
|
|
108
|
-
enforceLogin: (loaderParams: {
|
|
109
|
-
request?: { url?: string };
|
|
110
|
-
cause?: "preload" | string;
|
|
111
|
-
location?: {
|
|
112
|
-
href?: string;
|
|
113
|
-
};
|
|
114
|
-
}) => Promise<void | never>;
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
export function createOidcReactApi_dependencyInjection<
|
|
118
|
-
DecodedIdToken extends Record<string, unknown>,
|
|
119
|
-
ParamsOfCreateOidc extends {
|
|
120
|
-
autoLogin?: boolean;
|
|
121
|
-
} & (
|
|
122
|
-
| {
|
|
123
|
-
decodedIdTokenSchema: { parse: (data: unknown) => DecodedIdToken } | undefined;
|
|
124
|
-
}
|
|
125
|
-
| {}
|
|
126
|
-
)
|
|
127
|
-
>(
|
|
128
|
-
paramsOrGetParams: ValueOrAsyncGetter<ParamsOfCreateOidc>,
|
|
129
|
-
createOidc: (params: ParamsOfCreateOidc) => Promise<Oidc<DecodedIdToken>>
|
|
130
|
-
): OidcReactApi<
|
|
131
|
-
DecodedIdToken,
|
|
132
|
-
ParamsOfCreateOidc extends { autoLogin?: true | undefined } ? true : false
|
|
133
|
-
> {
|
|
134
|
-
const dReadyToCreate = new Deferred<void>();
|
|
135
|
-
|
|
136
|
-
const oidcContext = createContext<{ oidc: Oidc<DecodedIdToken>; fallback: ReactNode } | undefined>(
|
|
137
|
-
undefined
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
// NOTE: It can be InitializationError only if autoLogin is true
|
|
141
|
-
const prOidcOrInitializationError = (async () => {
|
|
142
|
-
const params = await (async () => {
|
|
143
|
-
if (typeof paramsOrGetParams === "function") {
|
|
144
|
-
const getParams = paramsOrGetParams;
|
|
145
|
-
|
|
146
|
-
await dReadyToCreate.pr;
|
|
147
|
-
|
|
148
|
-
const params = await getParams();
|
|
149
|
-
|
|
150
|
-
return params;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const params = paramsOrGetParams;
|
|
154
|
-
|
|
155
|
-
return params;
|
|
156
|
-
})();
|
|
157
|
-
|
|
158
|
-
let oidc: Oidc<DecodedIdToken>;
|
|
159
|
-
|
|
160
|
-
try {
|
|
161
|
-
oidc = await createOidc(params);
|
|
162
|
-
} catch (error) {
|
|
163
|
-
if (!(error instanceof OidcInitializationError)) {
|
|
164
|
-
throw error;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return error;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return oidc;
|
|
171
|
-
})();
|
|
172
|
-
|
|
173
|
-
let prOidcOrInitializationError_resolvedValue:
|
|
174
|
-
| Oidc<DecodedIdToken>
|
|
175
|
-
| OidcInitializationError
|
|
176
|
-
| undefined = undefined;
|
|
177
|
-
prOidcOrInitializationError.then(value => (prOidcOrInitializationError_resolvedValue = value));
|
|
178
|
-
|
|
179
|
-
function OidcProvider(props: {
|
|
180
|
-
fallback?: ReactNode;
|
|
181
|
-
ErrorFallback?: (props: { initializationError: OidcInitializationError }) => ReactNode;
|
|
182
|
-
children: ReactNode;
|
|
183
|
-
}) {
|
|
184
|
-
const { fallback, ErrorFallback, children } = props;
|
|
185
|
-
|
|
186
|
-
const [oidcOrInitializationError, setOidcOrInitializationError] = useState<
|
|
187
|
-
Oidc<DecodedIdToken> | OidcInitializationError | undefined
|
|
188
|
-
>(prOidcOrInitializationError_resolvedValue);
|
|
189
|
-
|
|
190
|
-
useEffect(() => {
|
|
191
|
-
if (oidcOrInitializationError !== undefined) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
dReadyToCreate.resolve();
|
|
196
|
-
prOidcOrInitializationError.then(setOidcOrInitializationError);
|
|
197
|
-
}, []);
|
|
198
|
-
|
|
199
|
-
if (oidcOrInitializationError === undefined) {
|
|
200
|
-
return <>{fallback === undefined ? null : fallback}</>;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (oidcOrInitializationError instanceof OidcInitializationError) {
|
|
204
|
-
const initializationError = oidcOrInitializationError;
|
|
205
|
-
|
|
206
|
-
return (
|
|
207
|
-
<>
|
|
208
|
-
{ErrorFallback === undefined ? (
|
|
209
|
-
<h1 style={{ color: "red" }}>
|
|
210
|
-
An error occurred while initializing the OIDC client:
|
|
211
|
-
{initializationError.message}
|
|
212
|
-
</h1>
|
|
213
|
-
) : (
|
|
214
|
-
<ErrorFallback initializationError={initializationError} />
|
|
215
|
-
)}
|
|
216
|
-
</>
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const oidc = oidcOrInitializationError;
|
|
221
|
-
|
|
222
|
-
return (
|
|
223
|
-
<oidcContext.Provider value={{ oidc, fallback: fallback ?? null }}>
|
|
224
|
-
{children}
|
|
225
|
-
</oidcContext.Provider>
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const useAutoLogoutWarningCountdown: OidcReact.LoggedIn<DecodedIdToken>["useAutoLogoutWarningCountdown"] =
|
|
230
|
-
({ warningDurationSeconds }) => {
|
|
231
|
-
const contextValue = useContext(oidcContext);
|
|
232
|
-
|
|
233
|
-
assert(contextValue !== undefined);
|
|
234
|
-
|
|
235
|
-
const { oidc } = contextValue;
|
|
236
|
-
|
|
237
|
-
const [secondsLeft, setSecondsLeft] = useState<number | undefined>(undefined);
|
|
238
|
-
|
|
239
|
-
useEffect(() => {
|
|
240
|
-
if (!oidc.isUserLoggedIn) {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
const { unsubscribeFromAutoLogoutCountdown } = oidc.subscribeToAutoLogoutCountdown(
|
|
245
|
-
({ secondsLeft }) =>
|
|
246
|
-
setSecondsLeft(
|
|
247
|
-
secondsLeft === undefined || secondsLeft > warningDurationSeconds
|
|
248
|
-
? undefined
|
|
249
|
-
: secondsLeft
|
|
250
|
-
)
|
|
251
|
-
);
|
|
252
|
-
|
|
253
|
-
return () => {
|
|
254
|
-
unsubscribeFromAutoLogoutCountdown();
|
|
255
|
-
};
|
|
256
|
-
}, [warningDurationSeconds]);
|
|
257
|
-
|
|
258
|
-
return { secondsLeft };
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
function useOidc(params?: {
|
|
262
|
-
assert?: "user logged in" | "user not logged in";
|
|
263
|
-
}): OidcReact<DecodedIdToken> {
|
|
264
|
-
const { assert: assert_params } = params ?? {};
|
|
265
|
-
|
|
266
|
-
const contextValue = useContext(oidcContext);
|
|
267
|
-
|
|
268
|
-
assert(contextValue !== undefined, "You must use useOidc inside the corresponding OidcProvider");
|
|
269
|
-
|
|
270
|
-
const { oidc } = contextValue;
|
|
271
|
-
|
|
272
|
-
check_assertion: {
|
|
273
|
-
if (assert_params === undefined) {
|
|
274
|
-
break check_assertion;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const getMessage = (v: string) =>
|
|
278
|
-
[
|
|
279
|
-
"There is a logic error in the application.",
|
|
280
|
-
`If this component is mounted the user is supposed ${v}.`,
|
|
281
|
-
"An explicit assertion was made in this sense."
|
|
282
|
-
].join(" ");
|
|
283
|
-
|
|
284
|
-
switch (assert_params) {
|
|
285
|
-
case "user logged in":
|
|
286
|
-
if (!oidc.isUserLoggedIn) {
|
|
287
|
-
throw new Error(getMessage("to be logged in but currently they arn't"));
|
|
288
|
-
}
|
|
289
|
-
break;
|
|
290
|
-
case "user not logged in":
|
|
291
|
-
if (oidc.isUserLoggedIn) {
|
|
292
|
-
throw new Error(getMessage("not to be logged in but currently they are"));
|
|
293
|
-
}
|
|
294
|
-
break;
|
|
295
|
-
default:
|
|
296
|
-
assert<Equals<typeof assert_params, never>>(false);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const [, reRenderIfDecodedIdTokenChanged] = useState(
|
|
301
|
-
!oidc.isUserLoggedIn ? undefined : oidc.getDecodedIdToken()
|
|
302
|
-
);
|
|
303
|
-
|
|
304
|
-
useEffect(() => {
|
|
305
|
-
if (!oidc.isUserLoggedIn) {
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const { unsubscribe } = oidc.subscribeToTokensChange(() =>
|
|
310
|
-
reRenderIfDecodedIdTokenChanged(oidc.getDecodedIdToken())
|
|
311
|
-
);
|
|
312
|
-
|
|
313
|
-
reRenderIfDecodedIdTokenChanged(oidc.getDecodedIdToken());
|
|
314
|
-
|
|
315
|
-
return unsubscribe;
|
|
316
|
-
}, []);
|
|
317
|
-
|
|
318
|
-
const common: OidcReact.Common = {
|
|
319
|
-
params: oidc.params,
|
|
320
|
-
useAutoLogoutWarningCountdown
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
if (!oidc.isUserLoggedIn) {
|
|
324
|
-
return id<OidcReact.NotLoggedIn>({
|
|
325
|
-
...common,
|
|
326
|
-
isUserLoggedIn: false,
|
|
327
|
-
login: ({ doesCurrentHrefRequiresAuth = false, ...rest } = {}) =>
|
|
328
|
-
oidc.login({ doesCurrentHrefRequiresAuth, ...rest }),
|
|
329
|
-
initializationError: oidc.initializationError
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
const oidcReact: OidcReact.LoggedIn<DecodedIdToken> = {
|
|
334
|
-
...common,
|
|
335
|
-
isUserLoggedIn: true,
|
|
336
|
-
decodedIdToken: oidc.getDecodedIdToken(),
|
|
337
|
-
logout: oidc.logout,
|
|
338
|
-
renewTokens: oidc.renewTokens,
|
|
339
|
-
goToAuthServer: oidc.goToAuthServer,
|
|
340
|
-
isNewBrowserSession: oidc.isNewBrowserSession,
|
|
341
|
-
backFromAuthServer: oidc.backFromAuthServer
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
return oidcReact;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
function withLoginEnforced<Props extends Record<string, unknown>>(
|
|
348
|
-
Component: ComponentType<Props>,
|
|
349
|
-
params?: {
|
|
350
|
-
onRedirecting?: () => JSX.Element | null;
|
|
351
|
-
}
|
|
352
|
-
): FC<Props> {
|
|
353
|
-
const { onRedirecting } = params ?? {};
|
|
354
|
-
|
|
355
|
-
function ComponentWithLoginEnforced(props: Props) {
|
|
356
|
-
const contextValue = useContext(oidcContext);
|
|
357
|
-
|
|
358
|
-
assert(contextValue !== undefined, "094283");
|
|
359
|
-
|
|
360
|
-
const { oidc, fallback } = contextValue;
|
|
361
|
-
|
|
362
|
-
useEffect(() => {
|
|
363
|
-
if (oidc.isUserLoggedIn) {
|
|
364
|
-
return;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
oidc.login({ doesCurrentHrefRequiresAuth: true });
|
|
368
|
-
}, []);
|
|
369
|
-
|
|
370
|
-
if (!oidc.isUserLoggedIn) {
|
|
371
|
-
return onRedirecting === undefined ? fallback : onRedirecting();
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
return <Component {...props} />;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
ComponentWithLoginEnforced.displayName = `${
|
|
378
|
-
Component.displayName ?? Component.name ?? "Component"
|
|
379
|
-
}WithLoginEnforced`;
|
|
380
|
-
|
|
381
|
-
return ComponentWithLoginEnforced;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
async function enforceLogin(loaderParams: {
|
|
385
|
-
request?: { url?: string };
|
|
386
|
-
cause?: "preload" | string;
|
|
387
|
-
location?: { href?: string };
|
|
388
|
-
}): Promise<void | never> {
|
|
389
|
-
const { cause } = loaderParams;
|
|
390
|
-
|
|
391
|
-
const redirectUrl = (() => {
|
|
392
|
-
if (loaderParams.request?.url !== undefined) {
|
|
393
|
-
return toFullyQualifiedUrl({
|
|
394
|
-
urlish: loaderParams.request.url,
|
|
395
|
-
doAssertNoQueryParams: false
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
if (loaderParams.location?.href !== undefined) {
|
|
400
|
-
return toFullyQualifiedUrl({
|
|
401
|
-
urlish: loaderParams.location.href,
|
|
402
|
-
doAssertNoQueryParams: false
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
return location.href;
|
|
407
|
-
})();
|
|
408
|
-
|
|
409
|
-
const oidc = await getOidc();
|
|
410
|
-
|
|
411
|
-
if (!oidc.isUserLoggedIn) {
|
|
412
|
-
if (cause === "preload") {
|
|
413
|
-
throw new Error(
|
|
414
|
-
"oidc-spa: User is not yet logged in. This is an expected error, nothing to be addressed."
|
|
415
|
-
);
|
|
416
|
-
}
|
|
417
|
-
const doesCurrentHrefRequiresAuth =
|
|
418
|
-
location.href.replace(/\/$/, "") === redirectUrl.replace(/\/$/, "");
|
|
419
|
-
|
|
420
|
-
await oidc.login({
|
|
421
|
-
redirectUrl,
|
|
422
|
-
doesCurrentHrefRequiresAuth
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
async function getOidc(): Promise<Oidc<DecodedIdToken>> {
|
|
428
|
-
dReadyToCreate.resolve();
|
|
429
|
-
|
|
430
|
-
const oidcOrInitializationError = await prOidcOrInitializationError;
|
|
431
|
-
|
|
432
|
-
if (oidcOrInitializationError instanceof OidcInitializationError) {
|
|
433
|
-
const error = oidcOrInitializationError;
|
|
434
|
-
throw error;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
const oidc = oidcOrInitializationError;
|
|
438
|
-
|
|
439
|
-
return oidc;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
const oidcReact: OidcReactApi<DecodedIdToken, false> = {
|
|
443
|
-
OidcProvider,
|
|
444
|
-
useOidc: useOidc as any,
|
|
445
|
-
getOidc,
|
|
446
|
-
withLoginEnforced,
|
|
447
|
-
enforceLogin
|
|
448
|
-
};
|
|
449
|
-
|
|
450
|
-
// @ts-expect-error: We know what we are doing
|
|
451
|
-
return oidcReact;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/** @see: https://docs.oidc-spa.dev/v/v7/usage#react-api */
|
|
455
|
-
export function createReactOidc<
|
|
456
|
-
DecodedIdToken extends Record<string, unknown> = Oidc.Tokens.DecodedIdToken_base,
|
|
457
|
-
AutoLogin extends boolean = false
|
|
458
|
-
>(params: ValueOrAsyncGetter<ParamsOfCreateOidc<DecodedIdToken, AutoLogin>>) {
|
|
459
|
-
return createOidcReactApi_dependencyInjection(params, createOidc);
|
|
460
|
-
}
|
package/src/tools/Deferred.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { overwriteReadonlyProp } from "../vendor/frontend/tsafe";
|
|
2
|
-
|
|
3
|
-
export class Deferred<T> {
|
|
4
|
-
public readonly pr: Promise<T>;
|
|
5
|
-
|
|
6
|
-
/** NOTE: Does not need to be called bound to instance*/
|
|
7
|
-
public readonly resolve: (value: T) => void;
|
|
8
|
-
public readonly reject: (error: any) => void;
|
|
9
|
-
|
|
10
|
-
constructor() {
|
|
11
|
-
let resolve!: (value: T) => void;
|
|
12
|
-
let reject!: (error: any) => void;
|
|
13
|
-
|
|
14
|
-
this.pr = new Promise<T>((resolve_, reject_) => {
|
|
15
|
-
resolve = value => {
|
|
16
|
-
overwriteReadonlyProp(this, "isPending", false);
|
|
17
|
-
resolve_(value);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
reject = error => {
|
|
21
|
-
overwriteReadonlyProp(this, "isPending", false);
|
|
22
|
-
reject_(error);
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
this.resolve = resolve;
|
|
27
|
-
this.reject = reject;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public readonly isPending: boolean = true;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export namespace Deferred {
|
|
34
|
-
export type Unpack<T extends Deferred<any>> = T extends Deferred<infer U> ? U : never;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class VoidDeferred extends Deferred<undefined> {
|
|
38
|
-
public declare readonly resolve: () => void;
|
|
39
|
-
}
|
package/src/tools/StatefulEvt.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export type StatefulEvt<T> = {
|
|
2
|
-
current: T;
|
|
3
|
-
subscribe: (next: (data: T) => void) => Subscription;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export type StatefulReadonlyEvt<T> = {
|
|
7
|
-
readonly current: T;
|
|
8
|
-
subscribe: (next: (data: T) => void) => Subscription;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type Subscription = {
|
|
12
|
-
unsubscribe: () => void;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export function createStatefulEvt<T>(getInitialValue: () => T): StatefulEvt<T> {
|
|
16
|
-
let nextFunctions: ((data: T) => void)[] = [];
|
|
17
|
-
|
|
18
|
-
let wrappedState: [T] | undefined = undefined;
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
get current() {
|
|
22
|
-
if (wrappedState === undefined) {
|
|
23
|
-
wrappedState = [getInitialValue()];
|
|
24
|
-
}
|
|
25
|
-
return wrappedState[0];
|
|
26
|
-
},
|
|
27
|
-
set current(data: T) {
|
|
28
|
-
wrappedState = [data];
|
|
29
|
-
|
|
30
|
-
nextFunctions.forEach(next => next(data));
|
|
31
|
-
},
|
|
32
|
-
subscribe: (next: (data: T) => void) => {
|
|
33
|
-
nextFunctions.push(next);
|
|
34
|
-
|
|
35
|
-
return { unsubscribe: () => nextFunctions.splice(nextFunctions.indexOf(next), 1) };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|