@civic/auth 0.1.3 → 0.1.4-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +13 -10
- package/dist/cjs/browser/storage.d.ts +3 -0
- package/dist/cjs/browser/storage.d.ts.map +1 -1
- package/dist/cjs/browser/storage.js +8 -0
- package/dist/cjs/browser/storage.js.map +1 -1
- package/dist/cjs/lib/cookies.d.ts +2 -2
- package/dist/cjs/lib/cookies.d.ts.map +1 -1
- package/dist/cjs/lib/cookies.js +7 -5
- package/dist/cjs/lib/cookies.js.map +1 -1
- package/dist/cjs/lib/postMessage.js +1 -1
- package/dist/cjs/lib/postMessage.js.map +1 -1
- package/dist/cjs/lib/windowUtil.d.ts.map +1 -1
- package/dist/cjs/lib/windowUtil.js +1 -0
- package/dist/cjs/lib/windowUtil.js.map +1 -1
- package/dist/cjs/nextjs/GetUser.d.ts.map +1 -1
- package/dist/cjs/nextjs/GetUser.js +2 -13
- package/dist/cjs/nextjs/GetUser.js.map +1 -1
- package/dist/cjs/nextjs/config.d.ts.map +1 -1
- package/dist/cjs/nextjs/config.js +12 -0
- package/dist/cjs/nextjs/config.js.map +1 -1
- package/dist/cjs/nextjs/hooks/index.d.ts +1 -1
- package/dist/cjs/nextjs/hooks/index.d.ts.map +1 -1
- package/dist/cjs/nextjs/hooks/index.js +3 -3
- package/dist/cjs/nextjs/hooks/index.js.map +1 -1
- package/dist/cjs/nextjs/hooks/useUserCookie.d.ts +4 -1
- package/dist/cjs/nextjs/hooks/useUserCookie.d.ts.map +1 -1
- package/dist/cjs/nextjs/hooks/useUserCookie.js +43 -15
- package/dist/cjs/nextjs/hooks/useUserCookie.js.map +1 -1
- package/dist/cjs/nextjs/providers/NextAuthProvider.d.ts +5 -1
- package/dist/cjs/nextjs/providers/NextAuthProvider.d.ts.map +1 -1
- package/dist/cjs/nextjs/providers/NextAuthProvider.js +74 -35
- package/dist/cjs/nextjs/providers/NextAuthProvider.js.map +1 -1
- package/dist/cjs/nextjs/routeHandler.js +2 -2
- package/dist/cjs/nextjs/routeHandler.js.map +1 -1
- package/dist/cjs/reactjs/components/UserButton.js +20 -10
- package/dist/cjs/reactjs/components/UserButton.js.map +1 -1
- package/dist/cjs/reactjs/hooks/index.d.ts +0 -1
- package/dist/cjs/reactjs/hooks/index.d.ts.map +1 -1
- package/dist/cjs/reactjs/hooks/index.js +1 -3
- package/dist/cjs/reactjs/hooks/index.js.map +1 -1
- package/dist/cjs/services/AuthenticationService.d.ts +4 -1
- package/dist/cjs/services/AuthenticationService.d.ts.map +1 -1
- package/dist/cjs/services/AuthenticationService.js +38 -7
- package/dist/cjs/services/AuthenticationService.js.map +1 -1
- package/dist/cjs/shared/components/BlockDisplay.d.ts +7 -0
- package/dist/cjs/shared/components/BlockDisplay.d.ts.map +1 -0
- package/dist/cjs/shared/components/BlockDisplay.js +31 -0
- package/dist/cjs/shared/components/BlockDisplay.js.map +1 -0
- package/dist/cjs/shared/components/CivicAuthIframe.js +18 -8
- package/dist/cjs/shared/components/CivicAuthIframe.js.map +1 -1
- package/dist/cjs/shared/components/CivicAuthIframeContainer.d.ts.map +1 -1
- package/dist/cjs/shared/components/CivicAuthIframeContainer.js +39 -20
- package/dist/cjs/shared/components/CivicAuthIframeContainer.js.map +1 -1
- package/dist/cjs/shared/components/IFrameAndLoading.d.ts +7 -0
- package/dist/cjs/shared/components/IFrameAndLoading.d.ts.map +1 -0
- package/dist/cjs/shared/components/IFrameAndLoading.js +28 -0
- package/dist/cjs/shared/components/IFrameAndLoading.js.map +1 -0
- package/dist/cjs/shared/hooks/index.d.ts +5 -1
- package/dist/cjs/shared/hooks/index.d.ts.map +1 -1
- package/dist/cjs/shared/hooks/index.js +11 -3
- package/dist/cjs/shared/hooks/index.js.map +1 -1
- package/dist/cjs/shared/hooks/useCivicAuthConfig.d.ts +3 -0
- package/dist/cjs/shared/hooks/useCivicAuthConfig.d.ts.map +1 -0
- package/dist/cjs/shared/hooks/useCivicAuthConfig.js +13 -0
- package/dist/cjs/shared/hooks/useCivicAuthConfig.js.map +1 -0
- package/dist/cjs/shared/hooks/useClientTokenExchangeSession.d.ts +3 -0
- package/dist/cjs/shared/hooks/useClientTokenExchangeSession.d.ts.map +1 -0
- package/dist/cjs/shared/hooks/useClientTokenExchangeSession.js +16 -0
- package/dist/cjs/shared/hooks/useClientTokenExchangeSession.js.map +1 -0
- package/dist/cjs/shared/hooks/useCurrentUrl.d.ts +3 -0
- package/dist/cjs/shared/hooks/useCurrentUrl.d.ts.map +1 -0
- package/dist/cjs/shared/hooks/useCurrentUrl.js +27 -0
- package/dist/cjs/shared/hooks/useCurrentUrl.js.map +1 -0
- package/dist/cjs/shared/hooks/useIsInIframe.d.ts +3 -0
- package/dist/cjs/shared/hooks/useIsInIframe.d.ts.map +1 -0
- package/dist/cjs/shared/hooks/useIsInIframe.js +17 -0
- package/dist/cjs/shared/hooks/useIsInIframe.js.map +1 -0
- package/dist/cjs/shared/hooks/useOAuthEndpoints.d.ts +4 -0
- package/dist/cjs/shared/hooks/useOAuthEndpoints.d.ts.map +1 -0
- package/dist/cjs/shared/hooks/useOAuthEndpoints.js +17 -0
- package/dist/cjs/shared/hooks/useOAuthEndpoints.js.map +1 -0
- package/dist/cjs/shared/hooks/useRefresh.d.ts +4 -0
- package/dist/cjs/shared/hooks/useRefresh.d.ts.map +1 -0
- package/dist/cjs/shared/hooks/useRefresh.js +41 -0
- package/dist/cjs/shared/hooks/useRefresh.js.map +1 -0
- package/dist/cjs/shared/hooks/useSession.d.ts +1 -1
- package/dist/cjs/shared/hooks/useSession.d.ts.map +1 -1
- package/dist/cjs/shared/hooks/useSignIn.d.ts +14 -0
- package/dist/cjs/shared/hooks/useSignIn.d.ts.map +1 -0
- package/dist/cjs/shared/hooks/useSignIn.js +74 -0
- package/dist/cjs/shared/hooks/useSignIn.js.map +1 -0
- package/dist/cjs/shared/lib/GenericAuthenticationRefresher.d.ts +4 -0
- package/dist/cjs/shared/lib/GenericAuthenticationRefresher.d.ts.map +1 -1
- package/dist/cjs/shared/lib/GenericAuthenticationRefresher.js +30 -0
- package/dist/cjs/shared/lib/GenericAuthenticationRefresher.js.map +1 -1
- package/dist/cjs/shared/lib/session.d.ts +1 -1
- package/dist/cjs/shared/lib/session.d.ts.map +1 -1
- package/dist/cjs/shared/lib/session.js +12 -1
- package/dist/cjs/shared/lib/session.js.map +1 -1
- package/dist/cjs/shared/lib/types.d.ts +14 -1
- package/dist/cjs/shared/lib/types.d.ts.map +1 -1
- package/dist/cjs/shared/lib/types.js +2 -0
- package/dist/cjs/shared/lib/types.js.map +1 -1
- package/dist/cjs/shared/lib/util.d.ts.map +1 -1
- package/dist/cjs/shared/lib/util.js +28 -9
- package/dist/cjs/shared/lib/util.js.map +1 -1
- package/dist/cjs/shared/providers/AuthProvider.d.ts +3 -2
- package/dist/cjs/shared/providers/AuthProvider.d.ts.map +1 -1
- package/dist/cjs/shared/providers/AuthProvider.js +53 -244
- package/dist/cjs/shared/providers/AuthProvider.js.map +1 -1
- package/dist/cjs/shared/providers/CivicAuthConfigContext.d.ts +16 -0
- package/dist/cjs/shared/providers/CivicAuthConfigContext.d.ts.map +1 -0
- package/dist/cjs/shared/providers/CivicAuthConfigContext.js +80 -0
- package/dist/cjs/shared/providers/CivicAuthConfigContext.js.map +1 -0
- package/dist/cjs/shared/providers/CivicAuthProvider.d.ts.map +1 -1
- package/dist/cjs/shared/providers/CivicAuthProvider.js +23 -6
- package/dist/cjs/shared/providers/CivicAuthProvider.js.map +1 -1
- package/dist/cjs/shared/providers/ClientTokenExchangeSessionProvider.d.ts +17 -0
- package/dist/cjs/shared/providers/ClientTokenExchangeSessionProvider.d.ts.map +1 -0
- package/dist/cjs/shared/providers/ClientTokenExchangeSessionProvider.js +183 -0
- package/dist/cjs/shared/providers/ClientTokenExchangeSessionProvider.js.map +1 -0
- package/dist/cjs/shared/providers/IframeProvider.d.ts +7 -4
- package/dist/cjs/shared/providers/IframeProvider.d.ts.map +1 -1
- package/dist/cjs/shared/providers/IframeProvider.js +37 -9
- package/dist/cjs/shared/providers/IframeProvider.js.map +1 -1
- package/dist/cjs/shared/providers/SessionProvider.d.ts +10 -4
- package/dist/cjs/shared/providers/SessionProvider.d.ts.map +1 -1
- package/dist/cjs/shared/providers/SessionProvider.js +32 -12
- package/dist/cjs/shared/providers/SessionProvider.js.map +1 -1
- package/dist/cjs/shared/providers/TokenProvider.d.ts.map +1 -1
- package/dist/cjs/shared/providers/TokenProvider.js +29 -30
- package/dist/cjs/shared/providers/TokenProvider.js.map +1 -1
- package/dist/cjs/shared/providers/UserProvider.d.ts +6 -4
- package/dist/cjs/shared/providers/UserProvider.d.ts.map +1 -1
- package/dist/cjs/shared/providers/UserProvider.js +49 -26
- package/dist/cjs/shared/providers/UserProvider.js.map +1 -1
- package/dist/cjs/types.d.ts +5 -5
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/types.js +4 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils.d.ts.map +1 -1
- package/dist/esm/browser/storage.d.ts +3 -0
- package/dist/esm/browser/storage.d.ts.map +1 -1
- package/dist/esm/browser/storage.js +8 -0
- package/dist/esm/browser/storage.js.map +1 -1
- package/dist/esm/lib/cookies.d.ts +2 -2
- package/dist/esm/lib/cookies.d.ts.map +1 -1
- package/dist/esm/lib/cookies.js +7 -5
- package/dist/esm/lib/cookies.js.map +1 -1
- package/dist/esm/lib/postMessage.js +1 -1
- package/dist/esm/lib/postMessage.js.map +1 -1
- package/dist/esm/lib/windowUtil.d.ts.map +1 -1
- package/dist/esm/lib/windowUtil.js +1 -0
- package/dist/esm/lib/windowUtil.js.map +1 -1
- package/dist/esm/nextjs/GetUser.d.ts.map +1 -1
- package/dist/esm/nextjs/GetUser.js +2 -13
- package/dist/esm/nextjs/GetUser.js.map +1 -1
- package/dist/esm/nextjs/config.d.ts.map +1 -1
- package/dist/esm/nextjs/config.js +12 -0
- package/dist/esm/nextjs/config.js.map +1 -1
- package/dist/esm/nextjs/hooks/index.d.ts +1 -1
- package/dist/esm/nextjs/hooks/index.d.ts.map +1 -1
- package/dist/esm/nextjs/hooks/index.js +1 -1
- package/dist/esm/nextjs/hooks/index.js.map +1 -1
- package/dist/esm/nextjs/hooks/useUserCookie.d.ts +4 -1
- package/dist/esm/nextjs/hooks/useUserCookie.d.ts.map +1 -1
- package/dist/esm/nextjs/hooks/useUserCookie.js +45 -17
- package/dist/esm/nextjs/hooks/useUserCookie.js.map +1 -1
- package/dist/esm/nextjs/providers/NextAuthProvider.d.ts +5 -1
- package/dist/esm/nextjs/providers/NextAuthProvider.d.ts.map +1 -1
- package/dist/esm/nextjs/providers/NextAuthProvider.js +59 -30
- package/dist/esm/nextjs/providers/NextAuthProvider.js.map +1 -1
- package/dist/esm/nextjs/routeHandler.js +2 -2
- package/dist/esm/nextjs/routeHandler.js.map +1 -1
- package/dist/esm/reactjs/components/UserButton.js +3 -3
- package/dist/esm/reactjs/components/UserButton.js.map +1 -1
- package/dist/esm/reactjs/hooks/index.d.ts +0 -1
- package/dist/esm/reactjs/hooks/index.d.ts.map +1 -1
- package/dist/esm/reactjs/hooks/index.js +0 -1
- package/dist/esm/reactjs/hooks/index.js.map +1 -1
- package/dist/esm/services/AuthenticationService.d.ts +4 -1
- package/dist/esm/services/AuthenticationService.d.ts.map +1 -1
- package/dist/esm/services/AuthenticationService.js +39 -8
- package/dist/esm/services/AuthenticationService.js.map +1 -1
- package/dist/esm/shared/components/BlockDisplay.d.ts +7 -0
- package/dist/esm/shared/components/BlockDisplay.d.ts.map +1 -0
- package/dist/esm/shared/components/BlockDisplay.js +25 -0
- package/dist/esm/shared/components/BlockDisplay.js.map +1 -0
- package/dist/esm/shared/components/CivicAuthIframe.js +1 -1
- package/dist/esm/shared/components/CivicAuthIframe.js.map +1 -1
- package/dist/esm/shared/components/CivicAuthIframeContainer.d.ts.map +1 -1
- package/dist/esm/shared/components/CivicAuthIframeContainer.js +23 -14
- package/dist/esm/shared/components/CivicAuthIframeContainer.js.map +1 -1
- package/dist/esm/shared/components/IFrameAndLoading.d.ts +7 -0
- package/dist/esm/shared/components/IFrameAndLoading.d.ts.map +1 -0
- package/dist/esm/shared/components/IFrameAndLoading.js +22 -0
- package/dist/esm/shared/components/IFrameAndLoading.js.map +1 -0
- package/dist/esm/shared/hooks/index.d.ts +5 -1
- package/dist/esm/shared/hooks/index.d.ts.map +1 -1
- package/dist/esm/shared/hooks/index.js +5 -1
- package/dist/esm/shared/hooks/index.js.map +1 -1
- package/dist/esm/shared/hooks/useCivicAuthConfig.d.ts +3 -0
- package/dist/esm/shared/hooks/useCivicAuthConfig.d.ts.map +1 -0
- package/dist/esm/shared/hooks/useCivicAuthConfig.js +10 -0
- package/dist/esm/shared/hooks/useCivicAuthConfig.js.map +1 -0
- package/dist/esm/shared/hooks/useClientTokenExchangeSession.d.ts +3 -0
- package/dist/esm/shared/hooks/useClientTokenExchangeSession.d.ts.map +1 -0
- package/dist/esm/shared/hooks/useClientTokenExchangeSession.js +13 -0
- package/dist/esm/shared/hooks/useClientTokenExchangeSession.js.map +1 -0
- package/dist/esm/shared/hooks/useCurrentUrl.d.ts +3 -0
- package/dist/esm/shared/hooks/useCurrentUrl.d.ts.map +1 -0
- package/dist/esm/shared/hooks/useCurrentUrl.js +24 -0
- package/dist/esm/shared/hooks/useCurrentUrl.js.map +1 -0
- package/dist/esm/shared/hooks/useIsInIframe.d.ts +3 -0
- package/dist/esm/shared/hooks/useIsInIframe.d.ts.map +1 -0
- package/dist/esm/shared/hooks/useIsInIframe.js +14 -0
- package/dist/esm/shared/hooks/useIsInIframe.js.map +1 -0
- package/dist/esm/shared/hooks/useOAuthEndpoints.d.ts +4 -0
- package/dist/esm/shared/hooks/useOAuthEndpoints.d.ts.map +1 -0
- package/dist/esm/shared/hooks/useOAuthEndpoints.js +14 -0
- package/dist/esm/shared/hooks/useOAuthEndpoints.js.map +1 -0
- package/dist/esm/shared/hooks/useRefresh.d.ts +4 -0
- package/dist/esm/shared/hooks/useRefresh.d.ts.map +1 -0
- package/dist/esm/shared/hooks/useRefresh.js +38 -0
- package/dist/esm/shared/hooks/useRefresh.js.map +1 -0
- package/dist/esm/shared/hooks/useSession.d.ts +1 -1
- package/dist/esm/shared/hooks/useSession.d.ts.map +1 -1
- package/dist/esm/shared/hooks/useSignIn.d.ts +14 -0
- package/dist/esm/shared/hooks/useSignIn.d.ts.map +1 -0
- package/dist/esm/shared/hooks/useSignIn.js +71 -0
- package/dist/esm/shared/hooks/useSignIn.js.map +1 -0
- package/dist/esm/shared/lib/GenericAuthenticationRefresher.d.ts +4 -0
- package/dist/esm/shared/lib/GenericAuthenticationRefresher.d.ts.map +1 -1
- package/dist/esm/shared/lib/GenericAuthenticationRefresher.js +30 -0
- package/dist/esm/shared/lib/GenericAuthenticationRefresher.js.map +1 -1
- package/dist/esm/shared/lib/session.d.ts +1 -1
- package/dist/esm/shared/lib/session.d.ts.map +1 -1
- package/dist/esm/shared/lib/session.js +12 -1
- package/dist/esm/shared/lib/session.js.map +1 -1
- package/dist/esm/shared/lib/types.d.ts +14 -1
- package/dist/esm/shared/lib/types.d.ts.map +1 -1
- package/dist/esm/shared/lib/types.js +2 -0
- package/dist/esm/shared/lib/types.js.map +1 -1
- package/dist/esm/shared/lib/util.d.ts.map +1 -1
- package/dist/esm/shared/lib/util.js +11 -2
- package/dist/esm/shared/lib/util.js.map +1 -1
- package/dist/esm/shared/providers/AuthProvider.d.ts +3 -2
- package/dist/esm/shared/providers/AuthProvider.d.ts.map +1 -1
- package/dist/esm/shared/providers/AuthProvider.js +37 -238
- package/dist/esm/shared/providers/AuthProvider.js.map +1 -1
- package/dist/esm/shared/providers/CivicAuthConfigContext.d.ts +16 -0
- package/dist/esm/shared/providers/CivicAuthConfigContext.d.ts.map +1 -0
- package/dist/esm/shared/providers/CivicAuthConfigContext.js +43 -0
- package/dist/esm/shared/providers/CivicAuthConfigContext.js.map +1 -0
- package/dist/esm/shared/providers/CivicAuthProvider.d.ts.map +1 -1
- package/dist/esm/shared/providers/CivicAuthProvider.js +23 -6
- package/dist/esm/shared/providers/CivicAuthProvider.js.map +1 -1
- package/dist/esm/shared/providers/ClientTokenExchangeSessionProvider.d.ts +17 -0
- package/dist/esm/shared/providers/ClientTokenExchangeSessionProvider.d.ts.map +1 -0
- package/dist/esm/shared/providers/ClientTokenExchangeSessionProvider.js +146 -0
- package/dist/esm/shared/providers/ClientTokenExchangeSessionProvider.js.map +1 -0
- package/dist/esm/shared/providers/IframeProvider.d.ts +7 -4
- package/dist/esm/shared/providers/IframeProvider.d.ts.map +1 -1
- package/dist/esm/shared/providers/IframeProvider.js +21 -3
- package/dist/esm/shared/providers/IframeProvider.js.map +1 -1
- package/dist/esm/shared/providers/SessionProvider.d.ts +10 -4
- package/dist/esm/shared/providers/SessionProvider.d.ts.map +1 -1
- package/dist/esm/shared/providers/SessionProvider.js +15 -5
- package/dist/esm/shared/providers/SessionProvider.js.map +1 -1
- package/dist/esm/shared/providers/TokenProvider.d.ts.map +1 -1
- package/dist/esm/shared/providers/TokenProvider.js +13 -24
- package/dist/esm/shared/providers/TokenProvider.js.map +1 -1
- package/dist/esm/shared/providers/UserProvider.d.ts +6 -4
- package/dist/esm/shared/providers/UserProvider.d.ts.map +1 -1
- package/dist/esm/shared/providers/UserProvider.js +33 -20
- package/dist/esm/shared/providers/UserProvider.js.map +1 -1
- package/dist/esm/types.d.ts +5 -5
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +3 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils.d.ts.map +1 -1
- package/dist/src/browser/storage.d.ts +3 -0
- package/dist/src/browser/storage.d.ts.map +1 -1
- package/dist/src/browser/storage.js +8 -0
- package/dist/src/browser/storage.js.map +1 -1
- package/dist/src/lib/cookies.d.ts +2 -2
- package/dist/src/lib/cookies.d.ts.map +1 -1
- package/dist/src/lib/cookies.js +7 -5
- package/dist/src/lib/cookies.js.map +1 -1
- package/dist/src/lib/postMessage.js +1 -1
- package/dist/src/lib/postMessage.js.map +1 -1
- package/dist/src/lib/windowUtil.d.ts.map +1 -1
- package/dist/src/lib/windowUtil.js +1 -0
- package/dist/src/lib/windowUtil.js.map +1 -1
- package/dist/src/nextjs/GetUser.d.ts.map +1 -1
- package/dist/src/nextjs/GetUser.js +2 -13
- package/dist/src/nextjs/GetUser.js.map +1 -1
- package/dist/src/nextjs/config.d.ts.map +1 -1
- package/dist/src/nextjs/config.js +12 -0
- package/dist/src/nextjs/config.js.map +1 -1
- package/dist/src/nextjs/hooks/index.d.ts +1 -1
- package/dist/src/nextjs/hooks/index.d.ts.map +1 -1
- package/dist/src/nextjs/hooks/index.js +1 -1
- package/dist/src/nextjs/hooks/index.js.map +1 -1
- package/dist/src/nextjs/hooks/useRefresh.d.ts +4 -0
- package/dist/src/nextjs/hooks/useRefresh.d.ts.map +1 -0
- package/dist/src/nextjs/hooks/useRefresh.js +38 -0
- package/dist/src/nextjs/hooks/useRefresh.js.map +1 -0
- package/dist/src/nextjs/hooks/useUserCookie.d.ts +4 -1
- package/dist/src/nextjs/hooks/useUserCookie.d.ts.map +1 -1
- package/dist/src/nextjs/hooks/useUserCookie.js +45 -17
- package/dist/src/nextjs/hooks/useUserCookie.js.map +1 -1
- package/dist/src/nextjs/providers/NextAuthProvider.d.ts +5 -1
- package/dist/src/nextjs/providers/NextAuthProvider.d.ts.map +1 -1
- package/dist/src/nextjs/providers/NextAuthProvider.js +59 -30
- package/dist/src/nextjs/providers/NextAuthProvider.js.map +1 -1
- package/dist/src/nextjs/routeHandler.js +2 -2
- package/dist/src/nextjs/routeHandler.js.map +1 -1
- package/dist/src/reactjs/components/UserButton.js +3 -3
- package/dist/src/reactjs/components/UserButton.js.map +1 -1
- package/dist/src/reactjs/hooks/index.d.ts +0 -1
- package/dist/src/reactjs/hooks/index.d.ts.map +1 -1
- package/dist/src/reactjs/hooks/index.js +0 -1
- package/dist/src/reactjs/hooks/index.js.map +1 -1
- package/dist/src/reactjs/hooks/useRefresh.d.ts +4 -0
- package/dist/src/reactjs/hooks/useRefresh.d.ts.map +1 -0
- package/dist/src/reactjs/hooks/useRefresh.js +28 -0
- package/dist/src/reactjs/hooks/useRefresh.js.map +1 -0
- package/dist/src/services/AuthenticationService.d.ts +4 -1
- package/dist/src/services/AuthenticationService.d.ts.map +1 -1
- package/dist/src/services/AuthenticationService.js +39 -8
- package/dist/src/services/AuthenticationService.js.map +1 -1
- package/dist/src/shared/components/BlockDisplay.d.ts +7 -0
- package/dist/src/shared/components/BlockDisplay.d.ts.map +1 -0
- package/dist/src/shared/components/BlockDisplay.js +25 -0
- package/dist/src/shared/components/BlockDisplay.js.map +1 -0
- package/dist/src/shared/components/CivicAuthIframe.js +1 -1
- package/dist/src/shared/components/CivicAuthIframe.js.map +1 -1
- package/dist/src/shared/components/CivicAuthIframeContainer.d.ts.map +1 -1
- package/dist/src/shared/components/CivicAuthIframeContainer.js +23 -14
- package/dist/src/shared/components/CivicAuthIframeContainer.js.map +1 -1
- package/dist/src/shared/components/IFrameAndLoading.d.ts +7 -0
- package/dist/src/shared/components/IFrameAndLoading.d.ts.map +1 -0
- package/dist/src/shared/components/IFrameAndLoading.js +22 -0
- package/dist/src/shared/components/IFrameAndLoading.js.map +1 -0
- package/dist/src/shared/hooks/index.d.ts +5 -1
- package/dist/src/shared/hooks/index.d.ts.map +1 -1
- package/dist/src/shared/hooks/index.js +5 -1
- package/dist/src/shared/hooks/index.js.map +1 -1
- package/dist/src/shared/hooks/useCivicAuthConfig.d.ts +3 -0
- package/dist/src/shared/hooks/useCivicAuthConfig.d.ts.map +1 -0
- package/dist/src/shared/hooks/useCivicAuthConfig.js +10 -0
- package/dist/src/shared/hooks/useCivicAuthConfig.js.map +1 -0
- package/dist/src/shared/hooks/useClientTokenExchangeSession.d.ts +3 -0
- package/dist/src/shared/hooks/useClientTokenExchangeSession.d.ts.map +1 -0
- package/dist/src/shared/hooks/useClientTokenExchangeSession.js +13 -0
- package/dist/src/shared/hooks/useClientTokenExchangeSession.js.map +1 -0
- package/dist/src/shared/hooks/useCurrentUrl.d.ts +3 -0
- package/dist/src/shared/hooks/useCurrentUrl.d.ts.map +1 -0
- package/dist/src/shared/hooks/useCurrentUrl.js +24 -0
- package/dist/src/shared/hooks/useCurrentUrl.js.map +1 -0
- package/dist/src/shared/hooks/useIsInIframe.d.ts +3 -0
- package/dist/src/shared/hooks/useIsInIframe.d.ts.map +1 -0
- package/dist/src/shared/hooks/useIsInIframe.js +14 -0
- package/dist/src/shared/hooks/useIsInIframe.js.map +1 -0
- package/dist/src/shared/hooks/useOAuthEndpoints.d.ts +4 -0
- package/dist/src/shared/hooks/useOAuthEndpoints.d.ts.map +1 -0
- package/dist/src/shared/hooks/useOAuthEndpoints.js +14 -0
- package/dist/src/shared/hooks/useOAuthEndpoints.js.map +1 -0
- package/dist/src/shared/hooks/useRefresh.d.ts +4 -0
- package/dist/src/shared/hooks/useRefresh.d.ts.map +1 -0
- package/dist/src/shared/hooks/useRefresh.js +38 -0
- package/dist/src/shared/hooks/useRefresh.js.map +1 -0
- package/dist/src/shared/hooks/useSession.d.ts +1 -1
- package/dist/src/shared/hooks/useSession.d.ts.map +1 -1
- package/dist/src/shared/hooks/useSignIn.d.ts +14 -0
- package/dist/src/shared/hooks/useSignIn.d.ts.map +1 -0
- package/dist/src/shared/hooks/useSignIn.js +71 -0
- package/dist/src/shared/hooks/useSignIn.js.map +1 -0
- package/dist/src/shared/lib/GenericAuthenticationRefresher.d.ts +4 -0
- package/dist/src/shared/lib/GenericAuthenticationRefresher.d.ts.map +1 -1
- package/dist/src/shared/lib/GenericAuthenticationRefresher.js +30 -0
- package/dist/src/shared/lib/GenericAuthenticationRefresher.js.map +1 -1
- package/dist/src/shared/lib/session.d.ts +1 -1
- package/dist/src/shared/lib/session.d.ts.map +1 -1
- package/dist/src/shared/lib/session.js +12 -1
- package/dist/src/shared/lib/session.js.map +1 -1
- package/dist/src/shared/lib/types.d.ts +14 -1
- package/dist/src/shared/lib/types.d.ts.map +1 -1
- package/dist/src/shared/lib/types.js +2 -0
- package/dist/src/shared/lib/types.js.map +1 -1
- package/dist/src/shared/lib/util.d.ts.map +1 -1
- package/dist/src/shared/lib/util.js +11 -2
- package/dist/src/shared/lib/util.js.map +1 -1
- package/dist/src/shared/providers/AuthProvider.d.ts +3 -2
- package/dist/src/shared/providers/AuthProvider.d.ts.map +1 -1
- package/dist/src/shared/providers/AuthProvider.js +37 -238
- package/dist/src/shared/providers/AuthProvider.js.map +1 -1
- package/dist/src/shared/providers/CivicAuthConfigContext.d.ts +16 -0
- package/dist/src/shared/providers/CivicAuthConfigContext.d.ts.map +1 -0
- package/dist/src/shared/providers/CivicAuthConfigContext.js +43 -0
- package/dist/src/shared/providers/CivicAuthConfigContext.js.map +1 -0
- package/dist/src/shared/providers/CivicAuthProvider.d.ts.map +1 -1
- package/dist/src/shared/providers/CivicAuthProvider.js +23 -6
- package/dist/src/shared/providers/CivicAuthProvider.js.map +1 -1
- package/dist/src/shared/providers/ClientTokenExchangeSessionProvider.d.ts +17 -0
- package/dist/src/shared/providers/ClientTokenExchangeSessionProvider.d.ts.map +1 -0
- package/dist/src/shared/providers/ClientTokenExchangeSessionProvider.js +146 -0
- package/dist/src/shared/providers/ClientTokenExchangeSessionProvider.js.map +1 -0
- package/dist/src/shared/providers/IframeProvider.d.ts +7 -4
- package/dist/src/shared/providers/IframeProvider.d.ts.map +1 -1
- package/dist/src/shared/providers/IframeProvider.js +21 -3
- package/dist/src/shared/providers/IframeProvider.js.map +1 -1
- package/dist/src/shared/providers/SessionProvider.d.ts +10 -4
- package/dist/src/shared/providers/SessionProvider.d.ts.map +1 -1
- package/dist/src/shared/providers/SessionProvider.js +15 -5
- package/dist/src/shared/providers/SessionProvider.js.map +1 -1
- package/dist/src/shared/providers/TokenProvider.d.ts.map +1 -1
- package/dist/src/shared/providers/TokenProvider.js +13 -24
- package/dist/src/shared/providers/TokenProvider.js.map +1 -1
- package/dist/src/shared/providers/UserProvider.d.ts +6 -4
- package/dist/src/shared/providers/UserProvider.d.ts.map +1 -1
- package/dist/src/shared/providers/UserProvider.js +33 -20
- package/dist/src/shared/providers/UserProvider.js.map +1 -1
- package/dist/src/types.d.ts +5 -5
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +3 -1
- package/dist/src/types.js.map +1 -1
- package/dist/test/integration/sdk.test.d.ts.map +1 -1
- package/dist/test/integration/sdk.test.js +39 -33
- package/dist/test/integration/sdk.test.js.map +1 -1
- package/dist/test/unit/nextjs/NextAuthProvider.test.js +8 -6
- package/dist/test/unit/nextjs/NextAuthProvider.test.js.map +1 -1
- package/dist/test/unit/nextjs/getUser.test.js +2 -16
- package/dist/test/unit/nextjs/getUser.test.js.map +1 -1
- package/dist/test/unit/server/refresh.test.d.ts.map +1 -0
- package/dist/test/unit/services/AuthenticationService.test.js +18 -1
- package/dist/test/unit/services/AuthenticationService.test.js.map +1 -1
- package/dist/test/unit/shared/components/CivicAuthIframeContainer.test.js +12 -10
- package/dist/test/unit/shared/components/CivicAuthIframeContainer.test.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -1
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -10
- package/.prettierignore +0 -3
- package/.prettierrc +0 -1
- package/.turbo/turbo-build.log +0 -13
- package/.turbo/turbo-lint$colon$fix.log +0 -10
- package/.turbo/turbo-test.log +0 -1153
- package/dist/cjs/nextjs/hooks/useTokenCookie.d.ts +0 -3
- package/dist/cjs/nextjs/hooks/useTokenCookie.d.ts.map +0 -1
- package/dist/cjs/nextjs/hooks/useTokenCookie.js +0 -41
- package/dist/cjs/nextjs/hooks/useTokenCookie.js.map +0 -1
- package/dist/cjs/shared/hooks/useConfig.d.ts +0 -3
- package/dist/cjs/shared/hooks/useConfig.d.ts.map +0 -1
- package/dist/cjs/shared/hooks/useConfig.js +0 -16
- package/dist/cjs/shared/hooks/useConfig.js.map +0 -1
- package/dist/cjs/shared/providers/ConfigProvider.d.ts +0 -21
- package/dist/cjs/shared/providers/ConfigProvider.d.ts.map +0 -1
- package/dist/cjs/shared/providers/ConfigProvider.js +0 -46
- package/dist/cjs/shared/providers/ConfigProvider.js.map +0 -1
- package/dist/esm/nextjs/hooks/useTokenCookie.d.ts +0 -3
- package/dist/esm/nextjs/hooks/useTokenCookie.d.ts.map +0 -1
- package/dist/esm/nextjs/hooks/useTokenCookie.js +0 -37
- package/dist/esm/nextjs/hooks/useTokenCookie.js.map +0 -1
- package/dist/esm/shared/hooks/useConfig.d.ts +0 -3
- package/dist/esm/shared/hooks/useConfig.d.ts.map +0 -1
- package/dist/esm/shared/hooks/useConfig.js +0 -13
- package/dist/esm/shared/hooks/useConfig.js.map +0 -1
- package/dist/esm/shared/providers/ConfigProvider.d.ts +0 -21
- package/dist/esm/shared/providers/ConfigProvider.d.ts.map +0 -1
- package/dist/esm/shared/providers/ConfigProvider.js +0 -19
- package/dist/esm/shared/providers/ConfigProvider.js.map +0 -1
- package/dist/src/config.d.ts +0 -3
- package/dist/src/config.js +0 -5
- package/dist/src/config.js.map +0 -1
- package/dist/src/constants.d.ts +0 -9
- package/dist/src/constants.d.ts.map +0 -1
- package/dist/src/constants.js +0 -17
- package/dist/src/constants.js.map +0 -1
- package/dist/src/index.d.ts +0 -4
- package/dist/src/index.js +0 -2
- package/dist/src/index.js.map +0 -1
- package/dist/src/lib/jwt.d.ts +0 -3
- package/dist/src/lib/jwt.js +0 -9
- package/dist/src/lib/jwt.js.map +0 -1
- package/dist/src/lib/logger.d.ts +0 -26
- package/dist/src/lib/logger.d.ts.map +0 -1
- package/dist/src/lib/logger.js +0 -55
- package/dist/src/lib/logger.js.map +0 -1
- package/dist/src/lib/oauth.d.ts +0 -19
- package/dist/src/lib/oauth.js +0 -60
- package/dist/src/lib/oauth.js.map +0 -1
- package/dist/src/lib/postMessage.d.ts +0 -4
- package/dist/src/lib/windowUtil.d.ts +0 -4
- package/dist/src/nextjs/GetUser.d.ts +0 -6
- package/dist/src/nextjs/config.d.ts +0 -178
- package/dist/src/nextjs/cookies.d.ts +0 -30
- package/dist/src/nextjs/cookies.js +0 -112
- package/dist/src/nextjs/cookies.js.map +0 -1
- package/dist/src/nextjs/index.d.ts +0 -7
- package/dist/src/nextjs/index.js +0 -6
- package/dist/src/nextjs/index.js.map +0 -1
- package/dist/src/nextjs/middleware/index.d.ts +0 -2
- package/dist/src/nextjs/middleware/index.js +0 -2
- package/dist/src/nextjs/middleware/index.js.map +0 -1
- package/dist/src/nextjs/middleware.d.ts +0 -59
- package/dist/src/nextjs/middleware.js +0 -107
- package/dist/src/nextjs/middleware.js.map +0 -1
- package/dist/src/nextjs/routeHandler.d.ts +0 -18
- package/dist/src/nextjs/utils.d.ts +0 -3
- package/dist/src/nextjs/utils.js +0 -5
- package/dist/src/nextjs/utils.js.map +0 -1
- package/dist/src/reactjs/components/SignInButton.d.ts +0 -8
- package/dist/src/reactjs/components/SignInButton.js +0 -14
- package/dist/src/reactjs/components/SignInButton.js.map +0 -1
- package/dist/src/reactjs/components/SignOutButton.d.ts +0 -6
- package/dist/src/reactjs/components/SignOutButton.js +0 -14
- package/dist/src/reactjs/components/SignOutButton.js.map +0 -1
- package/dist/src/reactjs/components/UserButton.d.ts +0 -8
- package/dist/src/reactjs/components/index.d.ts +0 -6
- package/dist/src/reactjs/components/index.js +0 -6
- package/dist/src/reactjs/components/index.js.map +0 -1
- package/dist/src/reactjs/hooks/useAuth.d.ts +0 -3
- package/dist/src/reactjs/hooks/useAuth.js +0 -12
- package/dist/src/reactjs/hooks/useAuth.js.map +0 -1
- package/dist/src/reactjs/hooks/useUser.d.ts +0 -4
- package/dist/src/reactjs/hooks/useUser.js +0 -12
- package/dist/src/reactjs/hooks/useUser.js.map +0 -1
- package/dist/src/reactjs/index.d.ts +0 -6
- package/dist/src/reactjs/index.js +0 -8
- package/dist/src/reactjs/index.js.map +0 -1
- package/dist/src/reactjs/providers/index.d.ts +0 -8
- package/dist/src/reactjs/providers/index.js +0 -7
- package/dist/src/reactjs/providers/index.js.map +0 -1
- package/dist/src/server/ServerAuthenticationResolver.d.ts +0 -19
- package/dist/src/server/ServerAuthenticationResolver.js +0 -61
- package/dist/src/server/ServerAuthenticationResolver.js.map +0 -1
- package/dist/src/server/config.d.ts +0 -9
- package/dist/src/server/config.js +0 -2
- package/dist/src/server/config.js.map +0 -1
- package/dist/src/server/index.d.ts +0 -7
- package/dist/src/server/index.js +0 -5
- package/dist/src/server/index.js.map +0 -1
- package/dist/src/server/login.d.ts +0 -17
- package/dist/src/server/login.js +0 -37
- package/dist/src/server/login.js.map +0 -1
- package/dist/src/server/refresh.d.ts +0 -7
- package/dist/src/server/refresh.js +0 -13
- package/dist/src/server/refresh.js.map +0 -1
- package/dist/src/services/PKCE.d.ts +0 -20
- package/dist/src/services/PKCE.js +0 -44
- package/dist/src/services/PKCE.js.map +0 -1
- package/dist/src/services/types.d.ts +0 -23
- package/dist/src/services/types.js +0 -7
- package/dist/src/services/types.js.map +0 -1
- package/dist/src/shared/components/CivicAuthIframe.d.ts +0 -8
- package/dist/src/shared/components/CivicAuthIframeContainer.d.ts +0 -9
- package/dist/src/shared/components/CloseIcon.d.ts +0 -4
- package/dist/src/shared/components/CloseIcon.d.ts.map +0 -1
- package/dist/src/shared/components/CloseIcon.js +0 -6
- package/dist/src/shared/components/CloseIcon.js.map +0 -1
- package/dist/src/shared/components/LoadingIcon.d.ts +0 -4
- package/dist/src/shared/components/LoadingIcon.d.ts.map +0 -1
- package/dist/src/shared/components/LoadingIcon.js +0 -30
- package/dist/src/shared/components/LoadingIcon.js.map +0 -1
- package/dist/src/shared/hooks/useAuth.d.ts +0 -3
- package/dist/src/shared/hooks/useAuth.js +0 -12
- package/dist/src/shared/hooks/useAuth.js.map +0 -1
- package/dist/src/shared/hooks/useIframe.d.ts +0 -3
- package/dist/src/shared/hooks/useIframe.js +0 -13
- package/dist/src/shared/hooks/useIframe.js.map +0 -1
- package/dist/src/shared/hooks/useSession.js +0 -13
- package/dist/src/shared/hooks/useSession.js.map +0 -1
- package/dist/src/shared/hooks/useToken.d.ts +0 -3
- package/dist/src/shared/hooks/useToken.js +0 -12
- package/dist/src/shared/hooks/useToken.js.map +0 -1
- package/dist/src/shared/lib/UserSession.d.ts +0 -12
- package/dist/src/shared/lib/UserSession.js +0 -20
- package/dist/src/shared/lib/UserSession.js.map +0 -1
- package/dist/src/shared/lib/storage.d.ts +0 -25
- package/dist/src/shared/lib/storage.js +0 -17
- package/dist/src/shared/lib/storage.js.map +0 -1
- package/dist/src/shared/lib/util.d.ts +0 -33
- package/dist/src/shared/providers/AuthContext.d.ts +0 -10
- package/dist/src/shared/providers/AuthContext.js +0 -3
- package/dist/src/shared/providers/AuthContext.js.map +0 -1
- package/dist/src/shared/providers/CivicAuthProvider.d.ts +0 -6
- package/dist/src/shared/providers/TokenProvider.d.ts +0 -18
- package/dist/src/utils.d.ts +0 -15
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/src/utils.js +0 -43
- package/dist/src/utils.js.map +0 -1
- package/dist/test/integration/sdk.test.d.ts +0 -2
- package/dist/test/support/fixtures.d.ts +0 -26
- package/dist/test/support/fixtures.d.ts.map +0 -1
- package/dist/test/support/fixtures.js +0 -55
- package/dist/test/support/fixtures.js.map +0 -1
- package/dist/test/support/tokens.json +0 -26
- package/dist/test/unit/lib/oauth.test.d.ts +0 -2
- package/dist/test/unit/lib/oauth.test.js +0 -55
- package/dist/test/unit/lib/oauth.test.js.map +0 -1
- package/dist/test/unit/logger.test.d.ts +0 -2
- package/dist/test/unit/logger.test.d.ts.map +0 -1
- package/dist/test/unit/logger.test.js +0 -141
- package/dist/test/unit/logger.test.js.map +0 -1
- package/dist/test/unit/nextjs/NextAuthProvider.test.d.ts +0 -2
- package/dist/test/unit/nextjs/config.test.d.ts +0 -2
- package/dist/test/unit/nextjs/config.test.js +0 -189
- package/dist/test/unit/nextjs/config.test.js.map +0 -1
- package/dist/test/unit/nextjs/getUser.test.d.ts +0 -2
- package/dist/test/unit/nextjs/middleware.test.d.ts +0 -2
- package/dist/test/unit/nextjs/middleware.test.js +0 -113
- package/dist/test/unit/nextjs/middleware.test.js.map +0 -1
- package/dist/test/unit/nextjs/utils.test.d.ts +0 -2
- package/dist/test/unit/nextjs/utils.test.js +0 -13
- package/dist/test/unit/nextjs/utils.test.js.map +0 -1
- package/dist/test/unit/publicApi/apiSnapshot.test.d.ts +0 -2
- package/dist/test/unit/publicApi/apiSnapshot.test.js +0 -10
- package/dist/test/unit/publicApi/apiSnapshot.test.js.map +0 -1
- package/dist/test/unit/react/components/SignInButton.test.d.ts +0 -2
- package/dist/test/unit/react/components/SignInButton.test.js +0 -31
- package/dist/test/unit/react/components/SignInButton.test.js.map +0 -1
- package/dist/test/unit/react/components/SignOutButton.test.d.ts +0 -2
- package/dist/test/unit/react/components/SignOutButton.test.js +0 -30
- package/dist/test/unit/react/components/SignOutButton.test.js.map +0 -1
- package/dist/test/unit/server/login.test.d.ts +0 -2
- package/dist/test/unit/server/login.test.js +0 -127
- package/dist/test/unit/server/login.test.js.map +0 -1
- package/dist/test/unit/server/session.test.d.ts +0 -2
- package/dist/test/unit/server/session.test.js +0 -41
- package/dist/test/unit/server/session.test.js.map +0 -1
- package/dist/test/unit/services/AuthenticationService.test.d.ts +0 -2
- package/dist/test/unit/services/ServerAuthenticationResolver.test.d.ts +0 -2
- package/dist/test/unit/services/ServerAuthenticationResolver.test.js +0 -74
- package/dist/test/unit/services/ServerAuthenticationResolver.test.js.map +0 -1
- package/dist/test/unit/shared/GenericAuthenticationRefresher.test.d.ts +0 -2
- package/dist/test/unit/shared/GenericAuthenticationRefresher.test.js +0 -61
- package/dist/test/unit/shared/GenericAuthenticationRefresher.test.js.map +0 -1
- package/dist/test/unit/shared/UserSession.test.d.ts +0 -2
- package/dist/test/unit/shared/UserSession.test.js +0 -37
- package/dist/test/unit/shared/UserSession.test.js.map +0 -1
- package/dist/test/unit/shared/components/CivicAuthIframeContainer.test.d.ts +0 -2
- package/dist/test/unit/shared/storage.test.d.ts +0 -2
- package/dist/test/unit/shared/storage.test.js +0 -53
- package/dist/test/unit/shared/storage.test.js.map +0 -1
- package/dist/test/unit/utils.test.d.ts +0 -2
- package/dist/test/unit/utils.test.d.ts.map +0 -1
- package/dist/test/unit/utils.test.js +0 -40
- package/dist/test/unit/utils.test.js.map +0 -1
- package/dist/vitest.config.d.ts +0 -3
- package/dist/vitest.config.d.ts.map +0 -1
- package/dist/vitest.config.js +0 -40
- package/dist/vitest.config.js.map +0 -1
- package/src/browser/storage.ts +0 -11
- package/src/config.ts +0 -6
- package/src/constants.ts +0 -29
- package/src/index.ts +0 -16
- package/src/lib/cookies.ts +0 -28
- package/src/lib/jwt.ts +0 -15
- package/src/lib/logger.ts +0 -72
- package/src/lib/oauth.ts +0 -83
- package/src/lib/postMessage.ts +0 -22
- package/src/lib/windowUtil.ts +0 -29
- package/src/nextjs/GetUser.ts +0 -22
- package/src/nextjs/config.ts +0 -203
- package/src/nextjs/cookies.ts +0 -162
- package/src/nextjs/hooks/index.ts +0 -1
- package/src/nextjs/hooks/useTokenCookie.ts +0 -41
- package/src/nextjs/hooks/useUserCookie.ts +0 -41
- package/src/nextjs/index.ts +0 -20
- package/src/nextjs/middleware/index.ts +0 -1
- package/src/nextjs/middleware.ts +0 -155
- package/src/nextjs/providers/NextAuthProvider.tsx +0 -87
- package/src/nextjs/routeHandler.ts +0 -297
- package/src/nextjs/utils.ts +0 -9
- package/src/reactjs/components/SignInButton.tsx +0 -32
- package/src/reactjs/components/SignOutButton.tsx +0 -24
- package/src/reactjs/components/UserButton.tsx +0 -239
- package/src/reactjs/components/index.ts +0 -5
- package/src/reactjs/hooks/index.ts +0 -6
- package/src/reactjs/hooks/useAuth.ts +0 -15
- package/src/reactjs/hooks/useUser.ts +0 -20
- package/src/reactjs/index.ts +0 -19
- package/src/reactjs/providers/index.ts +0 -27
- package/src/server/ServerAuthenticationResolver.ts +0 -107
- package/src/server/config.ts +0 -9
- package/src/server/index.ts +0 -13
- package/src/server/login.ts +0 -59
- package/src/server/refresh.ts +0 -23
- package/src/services/AuthenticationService.ts +0 -329
- package/src/services/PKCE.ts +0 -45
- package/src/services/types.ts +0 -54
- package/src/shared/components/CivicAuthIframe.tsx +0 -26
- package/src/shared/components/CivicAuthIframeContainer.tsx +0 -195
- package/src/shared/components/CloseIcon.tsx +0 -21
- package/src/shared/components/LoadingIcon.tsx +0 -53
- package/src/shared/hooks/index.ts +0 -4
- package/src/shared/hooks/useAuth.ts +0 -15
- package/src/shared/hooks/useConfig.ts +0 -14
- package/src/shared/hooks/useIframe.ts +0 -14
- package/src/shared/hooks/useSession.ts +0 -14
- package/src/shared/hooks/useToken.ts +0 -15
- package/src/shared/lib/GenericAuthenticationRefresher.ts +0 -75
- package/src/shared/lib/UserSession.ts +0 -25
- package/src/shared/lib/session.ts +0 -11
- package/src/shared/lib/storage.ts +0 -40
- package/src/shared/lib/types.ts +0 -26
- package/src/shared/lib/util.ts +0 -212
- package/src/shared/providers/AuthContext.tsx +0 -11
- package/src/shared/providers/AuthProvider.tsx +0 -397
- package/src/shared/providers/CivicAuthProvider.tsx +0 -31
- package/src/shared/providers/ConfigProvider.tsx +0 -50
- package/src/shared/providers/IframeProvider.tsx +0 -34
- package/src/shared/providers/SessionProvider.tsx +0 -29
- package/src/shared/providers/TokenProvider.tsx +0 -78
- package/src/shared/providers/UserProvider.tsx +0 -80
- package/src/types.ts +0 -227
- package/src/utils.ts +0 -58
- package/test/integration/sdk.test.tsx +0 -266
- package/test/support/fixtures.ts +0 -56
- package/test/support/tokens.json +0 -26
- package/test/unit/lib/oauth.test.ts +0 -72
- package/test/unit/logger.test.ts +0 -175
- package/test/unit/nextjs/NextAuthProvider.test.tsx +0 -38
- package/test/unit/nextjs/config.test.ts +0 -218
- package/test/unit/nextjs/getUser.test.ts +0 -41
- package/test/unit/nextjs/middleware.test.ts +0 -138
- package/test/unit/nextjs/routeHandler.test.ts.skipped +0 -369
- package/test/unit/nextjs/utils.test.ts +0 -17
- package/test/unit/publicApi/__snapshots__/apiSnapshot.test.ts.snap +0 -17
- package/test/unit/publicApi/apiSnapshot.test.ts +0 -11
- package/test/unit/react/components/SignInButton.test.tsx +0 -50
- package/test/unit/react/components/SignOutButton.test.tsx +0 -49
- package/test/unit/server/login.test.ts +0 -181
- package/test/unit/server/session.test.ts +0 -51
- package/test/unit/services/AuthenticationService.test.ts +0 -152
- package/test/unit/services/ServerAuthenticationResolver.test.ts +0 -115
- package/test/unit/shared/GenericAuthenticationRefresher.test.ts +0 -89
- package/test/unit/shared/UserSession.test.ts +0 -42
- package/test/unit/shared/components/CivicAuthIframeContainer.test.tsx +0 -154
- package/test/unit/shared/storage.test.ts +0 -67
- package/test/unit/utils.test.ts +0 -48
- package/tsconfig.build.json +0 -9
- package/tsconfig.cjs.json +0 -8
- package/tsconfig.esm.json +0 -7
- package/tsconfig.json +0 -42
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -41
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
UserProvider,
|
|
3
|
-
UserContext,
|
|
4
|
-
type UserContextType,
|
|
5
|
-
} from "@/shared/providers/UserProvider.js";
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
TokenProvider,
|
|
9
|
-
TokenContext,
|
|
10
|
-
type TokenContextType,
|
|
11
|
-
} from "@/shared/providers/TokenProvider.js";
|
|
12
|
-
|
|
13
|
-
export { AuthProvider } from "@/shared/providers/AuthProvider.js";
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
SessionProvider,
|
|
17
|
-
SessionContext,
|
|
18
|
-
type SessionContextType,
|
|
19
|
-
} from "@/shared/providers/SessionProvider.js";
|
|
20
|
-
|
|
21
|
-
export {
|
|
22
|
-
CivicAuthProvider,
|
|
23
|
-
type CivicAuthProviderProps,
|
|
24
|
-
} from "@/shared/providers/CivicAuthProvider.js";
|
|
25
|
-
|
|
26
|
-
export { AuthContext } from "@/shared/providers/AuthContext.js";
|
|
27
|
-
export type { AuthContextType } from "@/shared/providers/AuthContext.js";
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { GenericPublicClientPKCEProducer } from "@/services/PKCE.js";
|
|
2
|
-
import { OAuth2Client } from "oslo/oauth2";
|
|
3
|
-
import type {
|
|
4
|
-
AuthStorage,
|
|
5
|
-
Endpoints,
|
|
6
|
-
OIDCTokenResponseBody,
|
|
7
|
-
SessionData,
|
|
8
|
-
} from "@/types.js";
|
|
9
|
-
import type { AuthConfig } from "@/server/config.js";
|
|
10
|
-
import {
|
|
11
|
-
exchangeTokens,
|
|
12
|
-
getEndpointsWithOverrides,
|
|
13
|
-
retrieveTokens,
|
|
14
|
-
storeTokens,
|
|
15
|
-
} from "@/shared/lib/util.js";
|
|
16
|
-
import type { AuthenticationResolver, PKCEProducer } from "@/services/types.ts";
|
|
17
|
-
import { DEFAULT_AUTH_SERVER } from "@/constants.js";
|
|
18
|
-
|
|
19
|
-
export class ServerAuthenticationResolver implements AuthenticationResolver {
|
|
20
|
-
private pkceProducer: PKCEProducer;
|
|
21
|
-
private oauth2client: OAuth2Client | undefined;
|
|
22
|
-
private endpoints: Endpoints | undefined;
|
|
23
|
-
|
|
24
|
-
private constructor(
|
|
25
|
-
readonly authConfig: AuthConfig,
|
|
26
|
-
readonly storage: AuthStorage,
|
|
27
|
-
readonly endpointOverrides?: Partial<Endpoints>,
|
|
28
|
-
) {
|
|
29
|
-
this.pkceProducer = new GenericPublicClientPKCEProducer(storage);
|
|
30
|
-
}
|
|
31
|
-
validateExistingSession(): Promise<SessionData> {
|
|
32
|
-
throw new Error("Method not implemented.");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get oauthServer(): string {
|
|
36
|
-
return this.authConfig.oauthServer || DEFAULT_AUTH_SERVER;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async init(): Promise<this> {
|
|
40
|
-
// resolve oauth config
|
|
41
|
-
this.endpoints = await getEndpointsWithOverrides(
|
|
42
|
-
this.oauthServer,
|
|
43
|
-
this.endpointOverrides,
|
|
44
|
-
);
|
|
45
|
-
this.oauth2client = new OAuth2Client(
|
|
46
|
-
this.authConfig.clientId,
|
|
47
|
-
this.endpoints.auth,
|
|
48
|
-
this.endpoints.token,
|
|
49
|
-
{
|
|
50
|
-
redirectURI: this.authConfig.redirectUrl,
|
|
51
|
-
},
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
return this;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async tokenExchange(
|
|
58
|
-
code: string,
|
|
59
|
-
state: string,
|
|
60
|
-
): Promise<OIDCTokenResponseBody> {
|
|
61
|
-
if (!this.oauth2client) await this.init();
|
|
62
|
-
const codeVerifier = await this.pkceProducer.getCodeVerifier();
|
|
63
|
-
if (!codeVerifier) throw new Error("Code verifier not found in storage");
|
|
64
|
-
|
|
65
|
-
// exchange auth code for tokens
|
|
66
|
-
const tokens = await exchangeTokens(
|
|
67
|
-
code,
|
|
68
|
-
state,
|
|
69
|
-
this.pkceProducer,
|
|
70
|
-
this.oauth2client!, // clean up types here to avoid the ! operator
|
|
71
|
-
this.oauthServer,
|
|
72
|
-
this.endpoints!, // clean up types here to avoid the ! operator
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
await storeTokens(this.storage, tokens);
|
|
76
|
-
|
|
77
|
-
return tokens;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async getSessionData(): Promise<SessionData | null> {
|
|
81
|
-
const storageData = await retrieveTokens(this.storage);
|
|
82
|
-
|
|
83
|
-
if (!storageData) return null;
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
authenticated: !!storageData.id_token,
|
|
87
|
-
idToken: storageData.id_token,
|
|
88
|
-
accessToken: storageData.access_token,
|
|
89
|
-
refreshToken: storageData.refresh_token,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
static async build(
|
|
94
|
-
authConfig: AuthConfig,
|
|
95
|
-
storage: AuthStorage,
|
|
96
|
-
endpointOverrides?: Partial<Endpoints>,
|
|
97
|
-
): Promise<AuthenticationResolver> {
|
|
98
|
-
const resolver = new ServerAuthenticationResolver(
|
|
99
|
-
authConfig,
|
|
100
|
-
storage,
|
|
101
|
-
endpointOverrides,
|
|
102
|
-
);
|
|
103
|
-
await resolver.init();
|
|
104
|
-
|
|
105
|
-
return resolver;
|
|
106
|
-
}
|
|
107
|
-
}
|
package/src/server/config.ts
DELETED
package/src/server/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { CookieStorage } from "@/shared/lib/storage.js";
|
|
2
|
-
export type {
|
|
3
|
-
SessionStorage,
|
|
4
|
-
CookieStorageSettings,
|
|
5
|
-
} from "@/shared/lib/storage.js";
|
|
6
|
-
export {
|
|
7
|
-
resolveOAuthAccessCode,
|
|
8
|
-
isLoggedIn,
|
|
9
|
-
buildLoginUrl,
|
|
10
|
-
} from "@/server/login.js";
|
|
11
|
-
export type { AuthConfig } from "@/server/config.js";
|
|
12
|
-
export { getUser } from "@/shared/lib/session.js";
|
|
13
|
-
export { refreshTokens } from "@/server/refresh.js";
|
package/src/server/login.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { AuthStorage, OIDCTokenResponseBody } from "@/types.js";
|
|
2
|
-
import { DEFAULT_AUTH_SERVER, DEFAULT_SCOPES } from "@/constants.js";
|
|
3
|
-
import { GenericAuthenticationInitiator } from "@/services/AuthenticationService.js";
|
|
4
|
-
import { GenericPublicClientPKCEProducer } from "@/services/PKCE.js";
|
|
5
|
-
import { ServerAuthenticationResolver } from "@/server/ServerAuthenticationResolver.js";
|
|
6
|
-
import type { AuthConfig } from "@/server/config.ts";
|
|
7
|
-
/**
|
|
8
|
-
* Resolve an OAuth access code to a set of OIDC tokens
|
|
9
|
-
* @param code The access code, typically from a query parameter in the redirect url
|
|
10
|
-
* @param state The oauth random state string, used to distinguish between requests. Typically also passed in the redirect url
|
|
11
|
-
* @param storage The place that this server uses to store session data (e.g. a cookie store)
|
|
12
|
-
* @param config Oauth Server configuration
|
|
13
|
-
*/
|
|
14
|
-
export async function resolveOAuthAccessCode(
|
|
15
|
-
code: string,
|
|
16
|
-
state: string,
|
|
17
|
-
storage: AuthStorage,
|
|
18
|
-
config: AuthConfig,
|
|
19
|
-
): Promise<OIDCTokenResponseBody> {
|
|
20
|
-
const authSessionService = await ServerAuthenticationResolver.build(
|
|
21
|
-
{
|
|
22
|
-
...config,
|
|
23
|
-
oauthServer: config.oauthServer ?? DEFAULT_AUTH_SERVER,
|
|
24
|
-
},
|
|
25
|
-
storage,
|
|
26
|
-
config.endpointOverrides,
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
return authSessionService.tokenExchange(code, state);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function isLoggedIn(storage: AuthStorage): Promise<boolean> {
|
|
33
|
-
return !!(await storage.get("id_token"));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export async function buildLoginUrl(
|
|
37
|
-
config: Pick<AuthConfig, "clientId" | "redirectUrl"> &
|
|
38
|
-
Partial<Pick<AuthConfig, "oauthServer">> & {
|
|
39
|
-
scopes?: string[];
|
|
40
|
-
state?: string;
|
|
41
|
-
nonce?: string;
|
|
42
|
-
},
|
|
43
|
-
storage: AuthStorage,
|
|
44
|
-
): Promise<URL> {
|
|
45
|
-
// generate a random state if not provided
|
|
46
|
-
const state = config.state ?? Math.random().toString(36).substring(2);
|
|
47
|
-
const scopes = config.scopes ?? DEFAULT_SCOPES;
|
|
48
|
-
const pkceProducer = new GenericPublicClientPKCEProducer(storage);
|
|
49
|
-
const authInitiator = new GenericAuthenticationInitiator({
|
|
50
|
-
...config,
|
|
51
|
-
state,
|
|
52
|
-
scopes,
|
|
53
|
-
oauthServer: config.oauthServer ?? DEFAULT_AUTH_SERVER,
|
|
54
|
-
// When retrieving the PKCE challenge on the server-side, we produce it and store it in the session
|
|
55
|
-
pkceConsumer: pkceProducer,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
return authInitiator.signIn();
|
|
59
|
-
}
|
package/src/server/refresh.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { AuthStorage, OIDCTokenResponseBody } from "@/types.js";
|
|
2
|
-
import { DEFAULT_AUTH_SERVER } from "@/constants.js";
|
|
3
|
-
import { GenericAuthenticationRefresher } from "@/shared/lib/GenericAuthenticationRefresher.js";
|
|
4
|
-
import type { AuthConfig } from "@/server/config.ts";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Refresh the current set of OIDC tokens
|
|
8
|
-
*/
|
|
9
|
-
export async function refreshTokens(
|
|
10
|
-
storage: AuthStorage,
|
|
11
|
-
config: AuthConfig,
|
|
12
|
-
): Promise<OIDCTokenResponseBody> {
|
|
13
|
-
const refresher = await GenericAuthenticationRefresher.build(
|
|
14
|
-
{
|
|
15
|
-
...config,
|
|
16
|
-
oauthServer: config.oauthServer ?? DEFAULT_AUTH_SERVER,
|
|
17
|
-
},
|
|
18
|
-
storage,
|
|
19
|
-
config.endpointOverrides,
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
return refresher.refreshTokens();
|
|
23
|
-
}
|
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
// Proposals for revised versions of the SessionService AKA AuthSessionService
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
DisplayMode,
|
|
5
|
-
Endpoints,
|
|
6
|
-
LoginPostMessage,
|
|
7
|
-
OIDCTokenResponseBody,
|
|
8
|
-
SessionData,
|
|
9
|
-
} from "@/types.js";
|
|
10
|
-
import { BrowserPublicClientPKCEProducer } from "@/services/PKCE.js";
|
|
11
|
-
import {
|
|
12
|
-
clearTokens,
|
|
13
|
-
clearUser,
|
|
14
|
-
exchangeTokens,
|
|
15
|
-
generateOauthLoginUrl,
|
|
16
|
-
generateOauthLogoutUrl,
|
|
17
|
-
getEndpointsWithOverrides,
|
|
18
|
-
retrieveTokens,
|
|
19
|
-
storeTokens,
|
|
20
|
-
validateOauth2Tokens,
|
|
21
|
-
} from "@/shared/lib/util.js";
|
|
22
|
-
import { displayModeFromState, generateState } from "@/lib/oauth.js";
|
|
23
|
-
import { OAuth2Client } from "oslo/oauth2";
|
|
24
|
-
import { LocalStorageAdapter } from "@/browser/storage.js";
|
|
25
|
-
import type {
|
|
26
|
-
AuthenticationInitiator,
|
|
27
|
-
AuthenticationResolver,
|
|
28
|
-
PKCEConsumer,
|
|
29
|
-
} from "@/services/types.js";
|
|
30
|
-
import { PopupError } from "@/services/types.js";
|
|
31
|
-
import { removeParamsWithoutReload } from "@/lib/windowUtil.js";
|
|
32
|
-
import { DEFAULT_OAUTH_GET_PARAMS } from "@/constants.js";
|
|
33
|
-
import { validateLoginAppPostMessage } from "@/lib/postMessage.js";
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* An authentication initiator that works on a browser. Since this is just triggering
|
|
37
|
-
* login and logout, session data is not stored here.
|
|
38
|
-
* An associated AuthenticationResolver would be needed to get the session data.
|
|
39
|
-
* Storage is needed for the code verifier, this is the domain of the PKCEConsumer
|
|
40
|
-
* The storage used by the PKCEConsumer should be available to the AuthenticationResolver.
|
|
41
|
-
*
|
|
42
|
-
* Example usage:
|
|
43
|
-
*
|
|
44
|
-
* 1) Client-only SPA -eg a react app with no server:
|
|
45
|
-
* new BrowserAuthenticationInitiator({
|
|
46
|
-
* pkceConsumer: new BrowserPublicClientPKCEProducer(), // generate and retrieve the challenge client-side
|
|
47
|
-
* ... other config
|
|
48
|
-
* })
|
|
49
|
-
*
|
|
50
|
-
* 2) Client-side of a client/server app - eg a react app with a backend:
|
|
51
|
-
* new BrowserAuthenticationInitiator({
|
|
52
|
-
* pkceConsumer: new ConfidentialClientPKCEConsumer("https://myserver.com/pkce"), // get the challenge from the server
|
|
53
|
-
* ... other config
|
|
54
|
-
* })
|
|
55
|
-
*/
|
|
56
|
-
export class BrowserAuthenticationInitiator implements AuthenticationInitiator {
|
|
57
|
-
private postMessageHandler: null | ((event: MessageEvent) => void) = null;
|
|
58
|
-
|
|
59
|
-
protected config: {
|
|
60
|
-
clientId: string;
|
|
61
|
-
redirectUrl: string;
|
|
62
|
-
state: string;
|
|
63
|
-
scopes: string[];
|
|
64
|
-
// determines whether to trigger the login/logout in an iframe, a new browser window, or redirect the current one.
|
|
65
|
-
displayMode: DisplayMode;
|
|
66
|
-
oauthServer: string;
|
|
67
|
-
// the endpoints to use for the login (if not obtained from the auth server
|
|
68
|
-
endpointOverrides?: Partial<Endpoints>;
|
|
69
|
-
// used to get the PKCE challenge
|
|
70
|
-
pkceConsumer: PKCEConsumer;
|
|
71
|
-
// the nonce to use for the login
|
|
72
|
-
nonce?: string;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
constructor(config: typeof this.config) {
|
|
76
|
-
this.config = config;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async handleLoginAppPopupFailed(redirectUrl: string) {
|
|
80
|
-
console.warn(
|
|
81
|
-
"Login app popup failed open a popup, using redirect mode instead...",
|
|
82
|
-
redirectUrl,
|
|
83
|
-
);
|
|
84
|
-
window.location.href = redirectUrl;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Use the config (Client ID, scopes OAuth Server, Endpoints, PKCEConsumer) to generate a new login url
|
|
88
|
-
// and then use the display mode to decide how to send the user there
|
|
89
|
-
async signIn(iframeRef: HTMLIFrameElement | null): Promise<URL> {
|
|
90
|
-
const url = await generateOauthLoginUrl(this.config);
|
|
91
|
-
|
|
92
|
-
this.postMessageHandler = (event: MessageEvent) => {
|
|
93
|
-
const thisURL = new URL(window.location.href);
|
|
94
|
-
if (
|
|
95
|
-
event.origin.endsWith("civic.com") ||
|
|
96
|
-
thisURL.hostname === "localhost"
|
|
97
|
-
) {
|
|
98
|
-
if (!validateLoginAppPostMessage(event.data, this.config.clientId)) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const loginMessage = event.data as LoginPostMessage;
|
|
102
|
-
this.handleLoginAppPopupFailed(loginMessage.data.url);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
window.addEventListener("message", this.postMessageHandler);
|
|
107
|
-
|
|
108
|
-
if (this.config.displayMode === "iframe") {
|
|
109
|
-
if (!iframeRef)
|
|
110
|
-
throw new Error("iframeRef is required for displayMode 'iframe'");
|
|
111
|
-
iframeRef.setAttribute("src", url.toString());
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (this.config.displayMode === "redirect") {
|
|
115
|
-
window.location.href = url.toString();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (this.config.displayMode === "new_tab") {
|
|
119
|
-
try {
|
|
120
|
-
const popupWindow = window.open(url.toString(), "_blank");
|
|
121
|
-
if (!popupWindow) {
|
|
122
|
-
throw new PopupError("Failed to open popup window");
|
|
123
|
-
}
|
|
124
|
-
} catch (error) {
|
|
125
|
-
console.error("popupWindow", error);
|
|
126
|
-
throw new PopupError(
|
|
127
|
-
"window.open has thrown: Failed to open popup window",
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return url;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async signOut(): Promise<URL> {
|
|
136
|
-
const localStorage = new LocalStorageAdapter();
|
|
137
|
-
await clearTokens(localStorage);
|
|
138
|
-
await clearUser(localStorage);
|
|
139
|
-
// TODO open the iframe or new tab etc: the logout URL is not currently
|
|
140
|
-
// supported by on the oauth, so just clear state until then
|
|
141
|
-
const url = await generateOauthLogoutUrl(this.config);
|
|
142
|
-
return url;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
cleanup() {
|
|
146
|
-
if (this.postMessageHandler) {
|
|
147
|
-
window.removeEventListener("message", this.postMessageHandler);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/** A general-purpose authentication initiator, that just generates urls, but lets
|
|
153
|
-
* the caller decide how to use them. This is useful for server-side applications
|
|
154
|
-
* that may serve this URL to their front-ends or just call them directly
|
|
155
|
-
*/
|
|
156
|
-
export class GenericAuthenticationInitiator implements AuthenticationInitiator {
|
|
157
|
-
protected config: {
|
|
158
|
-
clientId: string;
|
|
159
|
-
redirectUrl: string;
|
|
160
|
-
state: string;
|
|
161
|
-
scopes: string[];
|
|
162
|
-
oauthServer: string;
|
|
163
|
-
nonce?: string;
|
|
164
|
-
// the endpoints to use for the login (if not obtained from the auth server)
|
|
165
|
-
endpointOverrides?: Partial<Endpoints>;
|
|
166
|
-
// used to get the PKCE challenge
|
|
167
|
-
pkceConsumer: PKCEConsumer;
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
constructor(config: typeof this.config) {
|
|
171
|
-
this.config = config;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Use the config (Client ID, scopes OAuth Server, Endpoints, PKCEConsumer) to generate a new login url
|
|
175
|
-
// and simply return the url
|
|
176
|
-
async signIn(): Promise<URL> {
|
|
177
|
-
return generateOauthLoginUrl(this.config);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
async signOut(): Promise<URL> {
|
|
181
|
-
return generateOauthLogoutUrl(this.config);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
type BrowserAuthenticationConfig = {
|
|
186
|
-
clientId: string;
|
|
187
|
-
redirectUrl: string;
|
|
188
|
-
scopes: string[];
|
|
189
|
-
oauthServer: string;
|
|
190
|
-
endpointOverrides?: Partial<Endpoints>;
|
|
191
|
-
displayMode: DisplayMode;
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* An authentication resolver that can run on the browser (i.e. a public client)
|
|
196
|
-
* It uses PKCE for security. PKCE and Session data are stored in local storage
|
|
197
|
-
*/
|
|
198
|
-
export class BrowserAuthenticationService extends BrowserAuthenticationInitiator {
|
|
199
|
-
private oauth2client: OAuth2Client | undefined;
|
|
200
|
-
private endpoints: Endpoints | undefined;
|
|
201
|
-
|
|
202
|
-
// TODO WIP - perhaps we want to keep resolver and initiator separate here
|
|
203
|
-
constructor(
|
|
204
|
-
config: BrowserAuthenticationConfig,
|
|
205
|
-
// Since we are running fully on the client, we produce as well as consume the PKCE challenge
|
|
206
|
-
protected pkceProducer = new BrowserPublicClientPKCEProducer(),
|
|
207
|
-
) {
|
|
208
|
-
super({
|
|
209
|
-
...config,
|
|
210
|
-
state: generateState(config.displayMode),
|
|
211
|
-
// Store and retrieve the PKCE challenge in local storage
|
|
212
|
-
pkceConsumer: pkceProducer,
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// TODO too much code duplication here between the browser and the server variant.
|
|
217
|
-
// Suggestion for refactor: Standardise the config for AuthenticationResolvers and create a one-shot
|
|
218
|
-
// function for generating an oauth2client from it
|
|
219
|
-
async init(): Promise<this> {
|
|
220
|
-
// resolve oauth config
|
|
221
|
-
this.endpoints = await getEndpointsWithOverrides(
|
|
222
|
-
this.config.oauthServer,
|
|
223
|
-
this.config.endpointOverrides,
|
|
224
|
-
);
|
|
225
|
-
this.oauth2client = new OAuth2Client(
|
|
226
|
-
this.config.clientId,
|
|
227
|
-
this.endpoints.auth,
|
|
228
|
-
this.endpoints.token,
|
|
229
|
-
{
|
|
230
|
-
redirectURI: this.config.redirectUrl,
|
|
231
|
-
},
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
return this;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Two responsibilities:
|
|
238
|
-
// 1. resolve the auth code to get the tokens (should use library code)
|
|
239
|
-
// 2. store the tokens in local storage
|
|
240
|
-
async tokenExchange(
|
|
241
|
-
code: string,
|
|
242
|
-
state: string,
|
|
243
|
-
): Promise<OIDCTokenResponseBody> {
|
|
244
|
-
if (!this.oauth2client) await this.init();
|
|
245
|
-
const codeVerifier = await this.pkceProducer.getCodeVerifier();
|
|
246
|
-
if (!codeVerifier) throw new Error("Code verifier not found in storage");
|
|
247
|
-
|
|
248
|
-
// exchange auth code for tokens
|
|
249
|
-
const tokens = await exchangeTokens(
|
|
250
|
-
code,
|
|
251
|
-
state,
|
|
252
|
-
this.pkceProducer,
|
|
253
|
-
this.oauth2client!, // clean up types here to avoid the ! operator
|
|
254
|
-
this.config.oauthServer,
|
|
255
|
-
this.endpoints!, // clean up types here to avoid the ! operator
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
await storeTokens(new LocalStorageAdapter(), tokens);
|
|
259
|
-
|
|
260
|
-
// cleanup the browser window if needed
|
|
261
|
-
const parsedDisplayMode = displayModeFromState(
|
|
262
|
-
state,
|
|
263
|
-
this.config.displayMode,
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
if (parsedDisplayMode === "new_tab") {
|
|
267
|
-
// Close the popup window
|
|
268
|
-
window.close();
|
|
269
|
-
}
|
|
270
|
-
// these are the default oAuth params that get added to the URL in redirect which we want to remove if present
|
|
271
|
-
removeParamsWithoutReload(DEFAULT_OAUTH_GET_PARAMS);
|
|
272
|
-
return tokens;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// Get the session data from local storage
|
|
276
|
-
async getSessionData(): Promise<SessionData | null> {
|
|
277
|
-
const storageData = await retrieveTokens(new LocalStorageAdapter());
|
|
278
|
-
|
|
279
|
-
if (!storageData) return null;
|
|
280
|
-
|
|
281
|
-
return {
|
|
282
|
-
authenticated: !!storageData.id_token,
|
|
283
|
-
idToken: storageData.id_token,
|
|
284
|
-
accessToken: storageData.access_token,
|
|
285
|
-
refreshToken: storageData.refresh_token,
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
async validateExistingSession(): Promise<SessionData> {
|
|
290
|
-
try {
|
|
291
|
-
const sessionData = await this.getSessionData();
|
|
292
|
-
if (!sessionData?.idToken || !sessionData.accessToken) {
|
|
293
|
-
const unAuthenticatedSession = { ...sessionData, authenticated: false };
|
|
294
|
-
await clearTokens(new LocalStorageAdapter());
|
|
295
|
-
return unAuthenticatedSession;
|
|
296
|
-
}
|
|
297
|
-
if (!this.endpoints || !this.oauth2client) await this.init();
|
|
298
|
-
|
|
299
|
-
// this function will throw if any of the tokens are invalid
|
|
300
|
-
await validateOauth2Tokens(
|
|
301
|
-
{
|
|
302
|
-
access_token: sessionData.accessToken,
|
|
303
|
-
id_token: sessionData.idToken,
|
|
304
|
-
refresh_token: sessionData.refreshToken,
|
|
305
|
-
},
|
|
306
|
-
this.endpoints!,
|
|
307
|
-
this.oauth2client!,
|
|
308
|
-
this.config.oauthServer,
|
|
309
|
-
);
|
|
310
|
-
return sessionData;
|
|
311
|
-
} catch (error) {
|
|
312
|
-
console.warn("Failed to validate existing tokens", error);
|
|
313
|
-
const unAuthenticatedSession = {
|
|
314
|
-
authenticated: false,
|
|
315
|
-
};
|
|
316
|
-
await clearTokens(new LocalStorageAdapter());
|
|
317
|
-
return unAuthenticatedSession;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
static async build(
|
|
322
|
-
config: BrowserAuthenticationConfig,
|
|
323
|
-
): Promise<AuthenticationResolver> {
|
|
324
|
-
const resolver = new BrowserAuthenticationService(config);
|
|
325
|
-
await resolver.init();
|
|
326
|
-
|
|
327
|
-
return resolver;
|
|
328
|
-
}
|
|
329
|
-
}
|
package/src/services/PKCE.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { deriveCodeChallenge } from "@/shared/lib/util.js";
|
|
2
|
-
import { generateCodeVerifier } from "oslo/oauth2";
|
|
3
|
-
import { LocalStorageAdapter } from "@/browser/storage.js";
|
|
4
|
-
import type { PKCEConsumer, PKCEProducer } from "@/services/types.js";
|
|
5
|
-
import type { AuthStorage } from "@/types.js";
|
|
6
|
-
import { CodeVerifier } from "@/shared/lib/types.js";
|
|
7
|
-
|
|
8
|
-
/** A PKCE consumer that retrieves the challenge from a server endpoint */
|
|
9
|
-
export class ConfidentialClientPKCEConsumer implements PKCEConsumer {
|
|
10
|
-
constructor(private pkceChallengeEndpoint: string) {}
|
|
11
|
-
async getCodeChallenge(): Promise<string> {
|
|
12
|
-
const response = await fetch(
|
|
13
|
-
`${this.pkceChallengeEndpoint}?appUrl=${window.location.origin}`,
|
|
14
|
-
);
|
|
15
|
-
const data = (await response.json()) as { challenge: string };
|
|
16
|
-
return data.challenge;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** A PKCE Producer that can generate and store a code verifier, but is agnostic as to the storage location */
|
|
21
|
-
export class GenericPublicClientPKCEProducer implements PKCEProducer {
|
|
22
|
-
constructor(private storage: AuthStorage) {}
|
|
23
|
-
|
|
24
|
-
// if there is already a verifier, return it,
|
|
25
|
-
// If not, create a new one and store it
|
|
26
|
-
async getCodeChallenge(): Promise<string> {
|
|
27
|
-
// let verifier = await this.getCodeVerifier();
|
|
28
|
-
// if (!verifier) {
|
|
29
|
-
const verifier = generateCodeVerifier();
|
|
30
|
-
this.storage.set(CodeVerifier.COOKIE_NAME, verifier);
|
|
31
|
-
// }
|
|
32
|
-
return deriveCodeChallenge(verifier);
|
|
33
|
-
}
|
|
34
|
-
// if there is already a verifier, return it,
|
|
35
|
-
async getCodeVerifier(): Promise<string | null> {
|
|
36
|
-
return this.storage.get(CodeVerifier.COOKIE_NAME);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** A PKCE Producer that is expected to run on a browser, and does not need a backend */
|
|
41
|
-
export class BrowserPublicClientPKCEProducer extends GenericPublicClientPKCEProducer {
|
|
42
|
-
constructor() {
|
|
43
|
-
super(new LocalStorageAdapter());
|
|
44
|
-
}
|
|
45
|
-
}
|
package/src/services/types.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { OIDCTokenResponseBody, SessionData } from "@/types.js";
|
|
2
|
-
|
|
3
|
-
// A PKCEConsumer can get a code challenge to use in the login process
|
|
4
|
-
// A PKCEProducer can also generate and store verifiers. The producer must also be a consumer in order to get the challenge from an existing flow
|
|
5
|
-
// Examples:
|
|
6
|
-
// - Client-only SPA: The SPA generates the code challenge and verifier, stores the verifier in state and returns the code challenge
|
|
7
|
-
// Note - The SPA should use PKCEProducer instead to do both
|
|
8
|
-
// - Client-side of a client/server app: The client calls the backend to get the challenge.
|
|
9
|
-
// - Server-side: The server should generate a new stored verifier and derive the challenge from it.
|
|
10
|
-
export interface PKCEConsumer {
|
|
11
|
-
// Retrieve a new PKCE challenge
|
|
12
|
-
getCodeChallenge(): Promise<string>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// All producers are consumers, because the producer can get its own challenge
|
|
16
|
-
export interface PKCEProducer extends PKCEConsumer {
|
|
17
|
-
// Retrieve the PKCE challenge from the session if one exists
|
|
18
|
-
getCodeVerifier(): Promise<string | null>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// A service that can initiate requests to login or log out
|
|
22
|
-
export interface AuthenticationInitiator {
|
|
23
|
-
// trigger a new login
|
|
24
|
-
signIn(iframeRef: HTMLIFrameElement | null): Promise<URL>;
|
|
25
|
-
|
|
26
|
-
// trigger a new logout
|
|
27
|
-
signOut(): Promise<URL>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// A service that can resolve an authentication request according to the OAuth Auth Code grant types
|
|
31
|
-
export interface AuthenticationResolver {
|
|
32
|
-
// Given an auth code, get the tokens from the auth server and store them. works in PKCE and non-PKCE environments
|
|
33
|
-
// Note, if we choose later to implement other grants, this method would move into a subinterface specifically
|
|
34
|
-
// for the authorization code grant type.
|
|
35
|
-
// The return type is just for convenience and can be ignored, as the same data would be provided by getSessionData
|
|
36
|
-
tokenExchange(code: string, state: string): Promise<OIDCTokenResponseBody>;
|
|
37
|
-
|
|
38
|
-
// If the tokens have already been retrieved, return them
|
|
39
|
-
getSessionData(): Promise<SessionData | null>;
|
|
40
|
-
|
|
41
|
-
// If an existing session is found, validate it and return the session data
|
|
42
|
-
validateExistingSession(): Promise<SessionData>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface AuthenticationRefresher {
|
|
46
|
-
refreshTokens: () => Promise<OIDCTokenResponseBody>;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export class PopupError extends Error {
|
|
50
|
-
constructor(message: string) {
|
|
51
|
-
super(message);
|
|
52
|
-
Object.setPrototypeOf(this, PopupError.prototype);
|
|
53
|
-
}
|
|
54
|
-
}
|