@civic/auth 0.0.1-beta.28 → 0.0.1-beta.29
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/.turbo/turbo-build.log +3 -3
- package/.turbo/turbo-lint.log +14 -0
- package/.turbo/turbo-test.log +1678 -0
- package/civic-auth-0.0.1-beta.15.tgz +0 -0
- package/civic-auth-0.0.1-beta.17.tgz +0 -0
- package/dist/AuthProvider-BYZ8w92b.d.mts +15 -0
- package/dist/AuthProvider-BgOwv9h8.d.ts +15 -0
- package/dist/AuthProvider-Bj_Prt1x.d.ts +21 -0
- package/dist/AuthProvider-DUAoX4G9.d.mts +21 -0
- package/dist/UserProvider-BA2uflVB.d.ts +16 -0
- package/dist/UserProvider-Bl3j1PUO.d.mts +16 -0
- package/dist/UserProvider-CMLaYOUD.d.ts +16 -0
- package/dist/UserProvider-Cbm8MZkJ.d.mts +16 -0
- package/dist/chunk-4PLCDPEN.mjs +599 -0
- package/dist/chunk-4PLCDPEN.mjs.map +1 -0
- package/dist/chunk-5UQQYXCX.js +1 -0
- package/dist/chunk-5UQQYXCX.js.map +1 -0
- package/dist/chunk-63YGK3A7.mjs +223 -0
- package/dist/chunk-63YGK3A7.mjs.map +1 -0
- package/dist/chunk-6RFRDWIP.js +223 -0
- package/dist/chunk-6RFRDWIP.js.map +1 -0
- package/dist/chunk-7K3QN2AT.js +599 -0
- package/dist/chunk-7K3QN2AT.js.map +1 -0
- package/dist/chunk-AM2Y662I.js +601 -0
- package/dist/chunk-AM2Y662I.js.map +1 -0
- package/dist/chunk-AP4627CS.mjs +223 -0
- package/dist/chunk-AP4627CS.mjs.map +1 -0
- package/dist/chunk-CRTRMMJ7.js +59 -0
- package/dist/chunk-CRTRMMJ7.js.map +1 -0
- package/dist/chunk-CTVJJBBA.js +118 -0
- package/dist/chunk-CTVJJBBA.js.map +1 -0
- package/dist/chunk-EKLYHP2D.mjs +711 -0
- package/dist/chunk-EKLYHP2D.mjs.map +1 -0
- package/dist/chunk-FHRZSX3C.js +710 -0
- package/dist/chunk-FHRZSX3C.js.map +1 -0
- package/dist/chunk-GB3H3I47.js +711 -0
- package/dist/chunk-GB3H3I47.js.map +1 -0
- package/dist/chunk-JDZPCA3P.js +173 -0
- package/dist/chunk-JDZPCA3P.js.map +1 -0
- package/dist/chunk-JEOPLLWO.js +223 -0
- package/dist/chunk-JEOPLLWO.js.map +1 -0
- package/dist/chunk-MK7557NR.mjs +118 -0
- package/dist/chunk-MK7557NR.mjs.map +1 -0
- package/dist/chunk-NLRREFOX.mjs +710 -0
- package/dist/chunk-NLRREFOX.mjs.map +1 -0
- package/dist/chunk-O3WGNLRO.mjs +173 -0
- package/dist/chunk-O3WGNLRO.mjs.map +1 -0
- package/dist/chunk-OXXUQ36U.mjs +283 -0
- package/dist/chunk-OXXUQ36U.mjs.map +1 -0
- package/dist/chunk-PMJAV4JJ.mjs +1 -0
- package/dist/chunk-PMJAV4JJ.mjs.map +1 -0
- package/dist/chunk-Q7DSPTUG.mjs +601 -0
- package/dist/chunk-Q7DSPTUG.mjs.map +1 -0
- package/dist/chunk-RGHW4PYM.mjs +59 -0
- package/dist/chunk-RGHW4PYM.mjs.map +1 -0
- package/dist/chunk-TH6FI2XI.js +283 -0
- package/dist/chunk-TH6FI2XI.js.map +1 -0
- package/dist/cjs/src/browser/storage.d.ts +2 -2
- package/dist/cjs/src/browser/storage.d.ts.map +1 -1
- package/dist/cjs/src/browser/storage.js +3 -3
- package/dist/cjs/src/browser/storage.js.map +1 -1
- package/dist/cjs/src/nextjs/GetUser.d.ts +1 -1
- package/dist/cjs/src/nextjs/GetUser.d.ts.map +1 -1
- package/dist/cjs/src/nextjs/GetUser.js +3 -3
- package/dist/cjs/src/nextjs/GetUser.js.map +1 -1
- package/dist/cjs/src/nextjs/config.d.ts.map +1 -1
- package/dist/cjs/src/nextjs/config.js +0 -2
- package/dist/cjs/src/nextjs/config.js.map +1 -1
- package/dist/cjs/src/nextjs/cookies.d.ts +4 -4
- package/dist/cjs/src/nextjs/cookies.d.ts.map +1 -1
- package/dist/cjs/src/nextjs/cookies.js +14 -11
- package/dist/cjs/src/nextjs/cookies.js.map +1 -1
- package/dist/cjs/src/nextjs/routeHandler.d.ts.map +1 -1
- package/dist/cjs/src/nextjs/routeHandler.js +1 -5
- package/dist/cjs/src/nextjs/routeHandler.js.map +1 -1
- package/dist/cjs/src/reactjs/hooks/index.d.ts +0 -1
- package/dist/cjs/src/reactjs/hooks/index.d.ts.map +1 -1
- package/dist/cjs/src/reactjs/hooks/index.js +1 -3
- package/dist/cjs/src/reactjs/hooks/index.js.map +1 -1
- package/dist/cjs/src/server/ServerAuthenticationResolver.d.ts.map +1 -1
- package/dist/cjs/src/server/ServerAuthenticationResolver.js +2 -7
- package/dist/cjs/src/server/ServerAuthenticationResolver.js.map +1 -1
- package/dist/cjs/src/server/login.d.ts +1 -1
- package/dist/cjs/src/server/login.d.ts.map +1 -1
- package/dist/cjs/src/server/login.js +2 -2
- package/dist/cjs/src/server/login.js.map +1 -1
- package/dist/cjs/src/services/AuthenticationService.d.ts.map +1 -1
- package/dist/cjs/src/services/AuthenticationService.js +6 -16
- package/dist/cjs/src/services/AuthenticationService.js.map +1 -1
- package/dist/cjs/src/shared/components/CivicAuthIframeContainer.d.ts.map +1 -1
- package/dist/cjs/src/shared/components/CivicAuthIframeContainer.js +0 -2
- package/dist/cjs/src/shared/components/CivicAuthIframeContainer.js.map +1 -1
- package/dist/cjs/src/shared/lib/GenericAuthenticationRefresher.d.ts.map +1 -1
- package/dist/cjs/src/shared/lib/GenericAuthenticationRefresher.js +2 -6
- package/dist/cjs/src/shared/lib/GenericAuthenticationRefresher.js.map +1 -1
- package/dist/cjs/src/shared/lib/UserSession.d.ts +4 -4
- package/dist/cjs/src/shared/lib/UserSession.d.ts.map +1 -1
- package/dist/cjs/src/shared/lib/UserSession.js +4 -4
- package/dist/cjs/src/shared/lib/UserSession.js.map +1 -1
- package/dist/cjs/src/shared/lib/session.js +1 -1
- package/dist/cjs/src/shared/lib/session.js.map +1 -1
- package/dist/cjs/src/shared/lib/storage.d.ts +2 -2
- package/dist/cjs/src/shared/lib/storage.d.ts.map +1 -1
- package/dist/cjs/src/shared/lib/storage.js.map +1 -1
- package/dist/cjs/src/shared/lib/util.d.ts +4 -4
- package/dist/cjs/src/shared/lib/util.d.ts.map +1 -1
- package/dist/cjs/src/shared/lib/util.js +16 -15
- package/dist/cjs/src/shared/lib/util.js.map +1 -1
- package/dist/cjs/src/types.d.ts +2 -2
- package/dist/cjs/src/types.d.ts.map +1 -1
- package/dist/cjs/src/types.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/browser/storage.d.ts +2 -2
- package/dist/esm/src/browser/storage.d.ts.map +1 -1
- package/dist/esm/src/browser/storage.js +3 -3
- package/dist/esm/src/browser/storage.js.map +1 -1
- package/dist/esm/src/nextjs/GetUser.d.ts +1 -1
- package/dist/esm/src/nextjs/GetUser.d.ts.map +1 -1
- package/dist/esm/src/nextjs/GetUser.js +3 -3
- package/dist/esm/src/nextjs/GetUser.js.map +1 -1
- package/dist/esm/src/nextjs/config.d.ts.map +1 -1
- package/dist/esm/src/nextjs/config.js +0 -2
- package/dist/esm/src/nextjs/config.js.map +1 -1
- package/dist/esm/src/nextjs/cookies.d.ts +4 -4
- package/dist/esm/src/nextjs/cookies.d.ts.map +1 -1
- package/dist/esm/src/nextjs/cookies.js +14 -11
- package/dist/esm/src/nextjs/cookies.js.map +1 -1
- package/dist/esm/src/nextjs/routeHandler.d.ts.map +1 -1
- package/dist/esm/src/nextjs/routeHandler.js +1 -5
- package/dist/esm/src/nextjs/routeHandler.js.map +1 -1
- package/dist/esm/src/reactjs/hooks/index.d.ts +0 -1
- package/dist/esm/src/reactjs/hooks/index.d.ts.map +1 -1
- package/dist/esm/src/reactjs/hooks/index.js +0 -1
- package/dist/esm/src/reactjs/hooks/index.js.map +1 -1
- package/dist/esm/src/server/ServerAuthenticationResolver.d.ts.map +1 -1
- package/dist/esm/src/server/ServerAuthenticationResolver.js +2 -7
- package/dist/esm/src/server/ServerAuthenticationResolver.js.map +1 -1
- package/dist/esm/src/server/login.d.ts +1 -1
- package/dist/esm/src/server/login.d.ts.map +1 -1
- package/dist/esm/src/server/login.js +2 -2
- package/dist/esm/src/server/login.js.map +1 -1
- package/dist/esm/src/services/AuthenticationService.d.ts.map +1 -1
- package/dist/esm/src/services/AuthenticationService.js +6 -16
- package/dist/esm/src/services/AuthenticationService.js.map +1 -1
- package/dist/esm/src/shared/components/CivicAuthIframeContainer.d.ts.map +1 -1
- package/dist/esm/src/shared/components/CivicAuthIframeContainer.js +0 -2
- package/dist/esm/src/shared/components/CivicAuthIframeContainer.js.map +1 -1
- package/dist/esm/src/shared/lib/GenericAuthenticationRefresher.d.ts.map +1 -1
- package/dist/esm/src/shared/lib/GenericAuthenticationRefresher.js +2 -6
- package/dist/esm/src/shared/lib/GenericAuthenticationRefresher.js.map +1 -1
- package/dist/esm/src/shared/lib/UserSession.d.ts +4 -4
- package/dist/esm/src/shared/lib/UserSession.d.ts.map +1 -1
- package/dist/esm/src/shared/lib/UserSession.js +4 -4
- package/dist/esm/src/shared/lib/UserSession.js.map +1 -1
- package/dist/esm/src/shared/lib/session.js +1 -1
- package/dist/esm/src/shared/lib/session.js.map +1 -1
- package/dist/esm/src/shared/lib/storage.d.ts +2 -2
- package/dist/esm/src/shared/lib/storage.d.ts.map +1 -1
- package/dist/esm/src/shared/lib/storage.js.map +1 -1
- package/dist/esm/src/shared/lib/util.d.ts +4 -4
- package/dist/esm/src/shared/lib/util.d.ts.map +1 -1
- package/dist/esm/src/shared/lib/util.js +16 -15
- package/dist/esm/src/shared/lib/util.js.map +1 -1
- package/dist/esm/src/types.d.ts +2 -2
- package/dist/esm/src/types.d.ts.map +1 -1
- package/dist/esm/src/types.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/index.css +340 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/dist/nextjs/client.css +340 -0
- package/dist/nextjs/client.css.map +1 -0
- package/dist/nextjs/client.d.mts +10 -0
- package/dist/nextjs/client.d.ts +10 -0
- package/dist/nextjs/client.js +185 -0
- package/dist/nextjs/client.js.map +1 -0
- package/dist/nextjs/client.mjs +185 -0
- package/dist/nextjs/client.mjs.map +1 -0
- package/dist/nextjs.d.mts +267 -0
- package/dist/nextjs.d.ts +267 -0
- package/dist/nextjs.js +315 -0
- package/dist/nextjs.js.map +1 -0
- package/dist/nextjs.mjs +315 -0
- package/dist/nextjs.mjs.map +1 -0
- package/dist/react.d.mts +65 -0
- package/dist/react.d.ts +65 -0
- package/dist/react.js +226 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +226 -0
- package/dist/react.mjs.map +1 -0
- package/dist/server.d.mts +35 -0
- package/dist/server.d.ts +35 -0
- package/dist/server.js +20 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +20 -0
- package/dist/server.mjs.map +1 -0
- package/dist/src/shared/components/LoadingIcon.d.ts.map +1 -1
- package/dist/src/shared/components/LoadingIcon.js +0 -6
- package/dist/src/shared/components/LoadingIcon.js.map +1 -1
- package/dist/storage-ANmRwpZ3.d.ts +25 -0
- package/dist/storage-B2eAQNdv.d.ts +25 -0
- package/dist/storage-BJPUpxhm.d.mts +25 -0
- package/dist/storage-BJyqsZwC.d.mts +25 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types-Bqm9OCZN.d.mts +22 -0
- package/dist/types-Bqm9OCZN.d.ts +22 -0
- package/dist/types-BxAubCqO.d.mts +58 -0
- package/dist/types-BxAubCqO.d.ts +58 -0
- package/dist/types-DOfl9w7j.d.mts +23 -0
- package/dist/types-DOfl9w7j.d.ts +23 -0
- package/dist/types-HdCjGldB.d.mts +58 -0
- package/dist/types-HdCjGldB.d.ts +58 -0
- package/package.json +1 -1
- package/src/browser/storage.ts +3 -3
- package/src/nextjs/GetUser.ts +3 -3
- package/src/nextjs/config.ts +0 -2
- package/src/nextjs/cookies.ts +14 -18
- package/src/nextjs/routeHandler.ts +1 -5
- package/src/reactjs/hooks/index.ts +0 -1
- package/src/server/ServerAuthenticationResolver.ts +2 -7
- package/src/server/login.ts +2 -2
- package/src/services/AuthenticationService.ts +6 -16
- package/src/shared/components/CivicAuthIframeContainer.tsx +0 -4
- package/src/shared/lib/GenericAuthenticationRefresher.ts +3 -8
- package/src/shared/lib/UserSession.ts +6 -6
- package/src/shared/lib/session.ts +1 -1
- package/src/shared/lib/storage.ts +2 -2
- package/src/shared/lib/util.ts +21 -18
- package/src/types.ts +2 -2
- package/test/unit/nextjs/getUser.test.ts +8 -8
- package/test/unit/publicApi/__snapshots__/apiSnapshot.test.ts.snap +0 -7
- package/test/unit/server/login.test.ts +20 -18
- package/test/unit/server/session.test.ts +4 -4
- package/test/unit/services/AuthenticationService.test.ts +3 -3
- package/test/unit/services/ServerAuthenticationResolver.test.ts +11 -6
- package/test/unit/shared/GenericAuthenticationRefresher.test.ts +4 -4
- package/test/unit/shared/UserSession.test.ts +6 -6
- package/test/unit/shared/storage.test.ts +6 -6
- package/dist/cjs/src/nextjs/client/index.d.ts +0 -2
- package/dist/cjs/src/nextjs/client/index.d.ts.map +0 -1
- package/dist/cjs/src/nextjs/client/index.js +0 -6
- package/dist/cjs/src/nextjs/client/index.js.map +0 -1
- package/dist/cjs/src/styles.css +0 -387
- package/dist/esm/src/nextjs/client/index.d.ts +0 -2
- package/dist/esm/src/nextjs/client/index.d.ts.map +0 -1
- package/dist/esm/src/nextjs/client/index.js +0 -2
- package/dist/esm/src/nextjs/client/index.js.map +0 -1
- package/dist/esm/src/styles.css +0 -387
- package/dist/src/nextjs/client/index.d.ts +0 -2
- package/dist/src/nextjs/client/index.d.ts.map +0 -1
- package/dist/src/nextjs/client/index.js +0 -2
- package/dist/src/nextjs/client/index.js.map +0 -1
- package/dist/test/unit/nextjs/routeHandler.test.d.ts +0 -2
- package/dist/test/unit/nextjs/routeHandler.test.d.ts.map +0 -1
- package/dist/test/unit/nextjs/routeHandler.test.js +0 -271
- package/dist/test/unit/nextjs/routeHandler.test.js.map +0 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare enum OAuthTokens {
|
|
2
|
+
ID_TOKEN = "id_token",
|
|
3
|
+
ACCESS_TOKEN = "access_token",
|
|
4
|
+
REFRESH_TOKEN = "refresh_token"
|
|
5
|
+
}
|
|
6
|
+
declare enum CodeVerifier {
|
|
7
|
+
COOKIE_NAME = "code_verifier"
|
|
8
|
+
}
|
|
9
|
+
declare enum UserStorage {
|
|
10
|
+
USER = "user"
|
|
11
|
+
}
|
|
12
|
+
interface CookieConfig {
|
|
13
|
+
secure?: boolean;
|
|
14
|
+
sameSite?: "strict" | "lax" | "none";
|
|
15
|
+
domain?: string;
|
|
16
|
+
path?: string;
|
|
17
|
+
maxAge?: number;
|
|
18
|
+
httpOnly?: boolean;
|
|
19
|
+
}
|
|
20
|
+
type TokensCookieConfig = Record<OAuthTokens | CodeVerifier, CookieConfig>;
|
|
21
|
+
|
|
22
|
+
export { CodeVerifier as C, OAuthTokens as O, type TokensCookieConfig as T, UserStorage as U, type CookieConfig as a };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare enum OAuthTokens {
|
|
2
|
+
ID_TOKEN = "id_token",
|
|
3
|
+
ACCESS_TOKEN = "access_token",
|
|
4
|
+
REFRESH_TOKEN = "refresh_token"
|
|
5
|
+
}
|
|
6
|
+
declare enum CodeVerifier {
|
|
7
|
+
COOKIE_NAME = "code_verifier"
|
|
8
|
+
}
|
|
9
|
+
declare enum UserStorage {
|
|
10
|
+
USER = "user"
|
|
11
|
+
}
|
|
12
|
+
interface CookieConfig {
|
|
13
|
+
secure?: boolean;
|
|
14
|
+
sameSite?: "strict" | "lax" | "none";
|
|
15
|
+
domain?: string;
|
|
16
|
+
path?: string;
|
|
17
|
+
maxAge?: number;
|
|
18
|
+
httpOnly?: boolean;
|
|
19
|
+
}
|
|
20
|
+
type TokensCookieConfig = Record<OAuthTokens | CodeVerifier, CookieConfig>;
|
|
21
|
+
|
|
22
|
+
export { CodeVerifier as C, OAuthTokens as O, type TokensCookieConfig as T, UserStorage as U, type CookieConfig as a };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { TokenResponseBody } from 'oslo/oauth2';
|
|
2
|
+
|
|
3
|
+
type UnknownObject = Record<string, unknown>;
|
|
4
|
+
type EmptyObject = Record<string, never>;
|
|
5
|
+
type DisplayMode = "iframe" | "redirect" | "new_tab" | "custom_tab";
|
|
6
|
+
type Endpoints = {
|
|
7
|
+
jwks: string;
|
|
8
|
+
auth: string;
|
|
9
|
+
token: string;
|
|
10
|
+
userinfo: string;
|
|
11
|
+
challenge?: string;
|
|
12
|
+
};
|
|
13
|
+
type Config = {
|
|
14
|
+
oauthServer: string;
|
|
15
|
+
endpoints?: Endpoints;
|
|
16
|
+
};
|
|
17
|
+
type SessionData = {
|
|
18
|
+
authenticated: boolean;
|
|
19
|
+
state?: string;
|
|
20
|
+
accessToken?: string;
|
|
21
|
+
refreshToken?: string;
|
|
22
|
+
idToken?: string;
|
|
23
|
+
timestamp?: number;
|
|
24
|
+
expiresIn?: number;
|
|
25
|
+
codeVerifier?: string;
|
|
26
|
+
displayMode?: DisplayMode;
|
|
27
|
+
openerUrl?: string;
|
|
28
|
+
};
|
|
29
|
+
type OIDCTokenResponseBody = TokenResponseBody & {
|
|
30
|
+
id_token: string;
|
|
31
|
+
};
|
|
32
|
+
type ForwardedTokens = Record<string, {
|
|
33
|
+
idToken?: string;
|
|
34
|
+
accessToken?: string;
|
|
35
|
+
refreshToken?: string;
|
|
36
|
+
}>;
|
|
37
|
+
type Tokens = {
|
|
38
|
+
idToken: string;
|
|
39
|
+
accessToken: string;
|
|
40
|
+
refreshToken: string;
|
|
41
|
+
forwardedTokens: ForwardedTokens;
|
|
42
|
+
};
|
|
43
|
+
type BaseUser = {
|
|
44
|
+
id: string;
|
|
45
|
+
email?: string;
|
|
46
|
+
name?: string;
|
|
47
|
+
given_name?: string;
|
|
48
|
+
family_name?: string;
|
|
49
|
+
picture?: string;
|
|
50
|
+
updated_at?: Date;
|
|
51
|
+
};
|
|
52
|
+
type User<T extends UnknownObject = EmptyObject> = BaseUser & Partial<Tokens> & T;
|
|
53
|
+
interface AuthStorage {
|
|
54
|
+
get(key: string): string | null;
|
|
55
|
+
set(key: string, value: string): void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type { AuthStorage as A, Config as C, DisplayMode as D, Endpoints as E, ForwardedTokens as F, OIDCTokenResponseBody as O, SessionData as S, Tokens as T, User as U, UnknownObject as a };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { TokenResponseBody } from 'oslo/oauth2';
|
|
2
|
+
|
|
3
|
+
type UnknownObject = Record<string, unknown>;
|
|
4
|
+
type EmptyObject = Record<string, never>;
|
|
5
|
+
type DisplayMode = "iframe" | "redirect" | "new_tab" | "custom_tab";
|
|
6
|
+
type Endpoints = {
|
|
7
|
+
jwks: string;
|
|
8
|
+
auth: string;
|
|
9
|
+
token: string;
|
|
10
|
+
userinfo: string;
|
|
11
|
+
challenge?: string;
|
|
12
|
+
};
|
|
13
|
+
type Config = {
|
|
14
|
+
oauthServer: string;
|
|
15
|
+
endpoints?: Endpoints;
|
|
16
|
+
};
|
|
17
|
+
type SessionData = {
|
|
18
|
+
authenticated: boolean;
|
|
19
|
+
state?: string;
|
|
20
|
+
accessToken?: string;
|
|
21
|
+
refreshToken?: string;
|
|
22
|
+
idToken?: string;
|
|
23
|
+
timestamp?: number;
|
|
24
|
+
expiresIn?: number;
|
|
25
|
+
codeVerifier?: string;
|
|
26
|
+
displayMode?: DisplayMode;
|
|
27
|
+
openerUrl?: string;
|
|
28
|
+
};
|
|
29
|
+
type OIDCTokenResponseBody = TokenResponseBody & {
|
|
30
|
+
id_token: string;
|
|
31
|
+
};
|
|
32
|
+
type ForwardedTokens = Record<string, {
|
|
33
|
+
idToken?: string;
|
|
34
|
+
accessToken?: string;
|
|
35
|
+
refreshToken?: string;
|
|
36
|
+
}>;
|
|
37
|
+
type Tokens = {
|
|
38
|
+
idToken: string;
|
|
39
|
+
accessToken: string;
|
|
40
|
+
refreshToken: string;
|
|
41
|
+
forwardedTokens: ForwardedTokens;
|
|
42
|
+
};
|
|
43
|
+
type BaseUser = {
|
|
44
|
+
id: string;
|
|
45
|
+
email?: string;
|
|
46
|
+
name?: string;
|
|
47
|
+
given_name?: string;
|
|
48
|
+
family_name?: string;
|
|
49
|
+
picture?: string;
|
|
50
|
+
updated_at?: Date;
|
|
51
|
+
};
|
|
52
|
+
type User<T extends UnknownObject = EmptyObject> = BaseUser & Partial<Tokens> & T;
|
|
53
|
+
interface AuthStorage {
|
|
54
|
+
get(key: string): string | null;
|
|
55
|
+
set(key: string, value: string): void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type { AuthStorage as A, Config as C, DisplayMode as D, Endpoints as E, ForwardedTokens as F, OIDCTokenResponseBody as O, SessionData as S, Tokens as T, User as U, UnknownObject as a };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare enum OAuthTokens {
|
|
2
|
+
ID_TOKEN = "id_token",
|
|
3
|
+
ACCESS_TOKEN = "access_token",
|
|
4
|
+
REFRESH_TOKEN = "refresh_token"
|
|
5
|
+
}
|
|
6
|
+
declare enum CodeVerifier {
|
|
7
|
+
COOKIE_NAME = "code_verifier",
|
|
8
|
+
APP_URL = "app_url"
|
|
9
|
+
}
|
|
10
|
+
declare enum UserStorage {
|
|
11
|
+
USER = "user"
|
|
12
|
+
}
|
|
13
|
+
interface CookieConfig {
|
|
14
|
+
secure?: boolean;
|
|
15
|
+
sameSite?: "strict" | "lax" | "none";
|
|
16
|
+
domain?: string;
|
|
17
|
+
path?: string;
|
|
18
|
+
maxAge?: number;
|
|
19
|
+
httpOnly?: boolean;
|
|
20
|
+
}
|
|
21
|
+
type TokensCookieConfig = Record<OAuthTokens | CodeVerifier, CookieConfig>;
|
|
22
|
+
|
|
23
|
+
export { CodeVerifier as C, OAuthTokens as O, type TokensCookieConfig as T, UserStorage as U, type CookieConfig as a };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare enum OAuthTokens {
|
|
2
|
+
ID_TOKEN = "id_token",
|
|
3
|
+
ACCESS_TOKEN = "access_token",
|
|
4
|
+
REFRESH_TOKEN = "refresh_token"
|
|
5
|
+
}
|
|
6
|
+
declare enum CodeVerifier {
|
|
7
|
+
COOKIE_NAME = "code_verifier",
|
|
8
|
+
APP_URL = "app_url"
|
|
9
|
+
}
|
|
10
|
+
declare enum UserStorage {
|
|
11
|
+
USER = "user"
|
|
12
|
+
}
|
|
13
|
+
interface CookieConfig {
|
|
14
|
+
secure?: boolean;
|
|
15
|
+
sameSite?: "strict" | "lax" | "none";
|
|
16
|
+
domain?: string;
|
|
17
|
+
path?: string;
|
|
18
|
+
maxAge?: number;
|
|
19
|
+
httpOnly?: boolean;
|
|
20
|
+
}
|
|
21
|
+
type TokensCookieConfig = Record<OAuthTokens | CodeVerifier, CookieConfig>;
|
|
22
|
+
|
|
23
|
+
export { CodeVerifier as C, OAuthTokens as O, type TokensCookieConfig as T, UserStorage as U, type CookieConfig as a };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { TokenResponseBody } from 'oslo/oauth2';
|
|
2
|
+
|
|
3
|
+
type UnknownObject = Record<string, unknown>;
|
|
4
|
+
type EmptyObject = Record<string, never>;
|
|
5
|
+
type DisplayMode = "iframe" | "redirect" | "new_tab" | "custom_tab";
|
|
6
|
+
type Endpoints = {
|
|
7
|
+
jwks: string;
|
|
8
|
+
auth: string;
|
|
9
|
+
token: string;
|
|
10
|
+
userinfo: string;
|
|
11
|
+
challenge?: string;
|
|
12
|
+
};
|
|
13
|
+
type Config = {
|
|
14
|
+
oauthServer: string;
|
|
15
|
+
endpoints?: Endpoints;
|
|
16
|
+
};
|
|
17
|
+
type SessionData = {
|
|
18
|
+
authenticated: boolean;
|
|
19
|
+
state?: string;
|
|
20
|
+
accessToken?: string;
|
|
21
|
+
refreshToken?: string;
|
|
22
|
+
idToken?: string;
|
|
23
|
+
timestamp?: number;
|
|
24
|
+
expiresIn?: number;
|
|
25
|
+
codeVerifier?: string;
|
|
26
|
+
displayMode?: DisplayMode;
|
|
27
|
+
openerUrl?: string;
|
|
28
|
+
};
|
|
29
|
+
type OIDCTokenResponseBody = TokenResponseBody & {
|
|
30
|
+
id_token: string;
|
|
31
|
+
};
|
|
32
|
+
type ForwardedTokens = Record<string, {
|
|
33
|
+
idToken?: string;
|
|
34
|
+
accessToken?: string;
|
|
35
|
+
refreshToken?: string;
|
|
36
|
+
}>;
|
|
37
|
+
type Tokens = {
|
|
38
|
+
idToken: string;
|
|
39
|
+
accessToken: string;
|
|
40
|
+
refreshToken: string;
|
|
41
|
+
forwardedTokens: ForwardedTokens;
|
|
42
|
+
};
|
|
43
|
+
type BaseUser = {
|
|
44
|
+
id: string;
|
|
45
|
+
email?: string;
|
|
46
|
+
name?: string;
|
|
47
|
+
given_name?: string;
|
|
48
|
+
family_name?: string;
|
|
49
|
+
picture?: string;
|
|
50
|
+
updated_at?: Date;
|
|
51
|
+
};
|
|
52
|
+
type User<T extends UnknownObject = EmptyObject> = BaseUser & Partial<Tokens> & T;
|
|
53
|
+
interface AuthStorage {
|
|
54
|
+
get(key: string): string | null;
|
|
55
|
+
set(key: string, value: string): void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type { AuthStorage as A, Config as C, DisplayMode as D, Endpoints as E, ForwardedTokens as F, OIDCTokenResponseBody as O, SessionData as S, Tokens as T, User as U, UnknownObject as a, EmptyObject as b };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { TokenResponseBody } from 'oslo/oauth2';
|
|
2
|
+
|
|
3
|
+
type UnknownObject = Record<string, unknown>;
|
|
4
|
+
type EmptyObject = Record<string, never>;
|
|
5
|
+
type DisplayMode = "iframe" | "redirect" | "new_tab" | "custom_tab";
|
|
6
|
+
type Endpoints = {
|
|
7
|
+
jwks: string;
|
|
8
|
+
auth: string;
|
|
9
|
+
token: string;
|
|
10
|
+
userinfo: string;
|
|
11
|
+
challenge?: string;
|
|
12
|
+
};
|
|
13
|
+
type Config = {
|
|
14
|
+
oauthServer: string;
|
|
15
|
+
endpoints?: Endpoints;
|
|
16
|
+
};
|
|
17
|
+
type SessionData = {
|
|
18
|
+
authenticated: boolean;
|
|
19
|
+
state?: string;
|
|
20
|
+
accessToken?: string;
|
|
21
|
+
refreshToken?: string;
|
|
22
|
+
idToken?: string;
|
|
23
|
+
timestamp?: number;
|
|
24
|
+
expiresIn?: number;
|
|
25
|
+
codeVerifier?: string;
|
|
26
|
+
displayMode?: DisplayMode;
|
|
27
|
+
openerUrl?: string;
|
|
28
|
+
};
|
|
29
|
+
type OIDCTokenResponseBody = TokenResponseBody & {
|
|
30
|
+
id_token: string;
|
|
31
|
+
};
|
|
32
|
+
type ForwardedTokens = Record<string, {
|
|
33
|
+
idToken?: string;
|
|
34
|
+
accessToken?: string;
|
|
35
|
+
refreshToken?: string;
|
|
36
|
+
}>;
|
|
37
|
+
type Tokens = {
|
|
38
|
+
idToken: string;
|
|
39
|
+
accessToken: string;
|
|
40
|
+
refreshToken: string;
|
|
41
|
+
forwardedTokens: ForwardedTokens;
|
|
42
|
+
};
|
|
43
|
+
type BaseUser = {
|
|
44
|
+
id: string;
|
|
45
|
+
email?: string;
|
|
46
|
+
name?: string;
|
|
47
|
+
given_name?: string;
|
|
48
|
+
family_name?: string;
|
|
49
|
+
picture?: string;
|
|
50
|
+
updated_at?: Date;
|
|
51
|
+
};
|
|
52
|
+
type User<T extends UnknownObject = EmptyObject> = BaseUser & Partial<Tokens> & T;
|
|
53
|
+
interface AuthStorage {
|
|
54
|
+
get(key: string): string | null;
|
|
55
|
+
set(key: string, value: string): void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type { AuthStorage as A, Config as C, DisplayMode as D, Endpoints as E, ForwardedTokens as F, OIDCTokenResponseBody as O, SessionData as S, Tokens as T, User as U, UnknownObject as a, EmptyObject as b };
|
package/package.json
CHANGED
package/src/browser/storage.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { AuthStorage } from "@/types.js";
|
|
2
2
|
|
|
3
3
|
export class LocalStorageAdapter implements AuthStorage {
|
|
4
|
-
get(key: string): string {
|
|
5
|
-
return localStorage.getItem(key) || "";
|
|
4
|
+
async get(key: string): Promise<string> {
|
|
5
|
+
return Promise.resolve(localStorage.getItem(key) || "");
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
set(key: string, value: string): void {
|
|
8
|
+
async set(key: string, value: string): Promise<void> {
|
|
9
9
|
localStorage.setItem(key, value);
|
|
10
10
|
}
|
|
11
11
|
}
|
package/src/nextjs/GetUser.ts
CHANGED
|
@@ -6,11 +6,11 @@ import { GenericUserSession } from "@/shared/lib/UserSession.js";
|
|
|
6
6
|
import { NextjsClientStorage } from "@/nextjs/cookies.js";
|
|
7
7
|
import { retrieveTokens } from "@/shared/lib/util.js";
|
|
8
8
|
|
|
9
|
-
export const getUser = (): User | null => {
|
|
9
|
+
export const getUser = async (): Promise<User | null> => {
|
|
10
10
|
const clientStorage = new NextjsClientStorage();
|
|
11
11
|
const userSession = new GenericUserSession(clientStorage);
|
|
12
|
-
const tokens = retrieveTokens(clientStorage);
|
|
13
|
-
const user = userSession.get();
|
|
12
|
+
const tokens = await retrieveTokens(clientStorage);
|
|
13
|
+
const user = await userSession.get();
|
|
14
14
|
if (!user || !tokens) return null;
|
|
15
15
|
|
|
16
16
|
return {
|
package/src/nextjs/config.ts
CHANGED
|
@@ -33,11 +33,9 @@ export type AuthConfig = Partial<AuthConfigWithDefaults>;
|
|
|
33
33
|
|
|
34
34
|
export type DefinedAuthConfig = AuthConfigWithDefaults;
|
|
35
35
|
|
|
36
|
-
console.log(`process.env.NODE_ENV: ${process.env.NODE_ENV}`);
|
|
37
36
|
const isDevelopment = process.env.NODE_ENV === "development";
|
|
38
37
|
|
|
39
38
|
const defaultServerSecure = isDevelopment ? false : true;
|
|
40
|
-
console.log(`defaultServerSecure: ${defaultServerSecure}`);
|
|
41
39
|
/**
|
|
42
40
|
* Default configuration values that will be used if not overridden
|
|
43
41
|
*/
|
package/src/nextjs/cookies.ts
CHANGED
|
@@ -102,12 +102,12 @@ const createUserInfoCookie = (
|
|
|
102
102
|
const clearAuthCookies = async (config: AuthConfig) => {
|
|
103
103
|
// clear session, and tokens
|
|
104
104
|
const cookieStorage = new NextjsCookieStorage(config.cookies?.tokens);
|
|
105
|
-
clearTokens(cookieStorage);
|
|
105
|
+
await clearTokens(cookieStorage);
|
|
106
106
|
|
|
107
107
|
// clear user
|
|
108
108
|
const clientStorage = new NextjsClientStorage();
|
|
109
109
|
const userSession = new GenericUserSession(clientStorage);
|
|
110
|
-
userSession.set(null);
|
|
110
|
+
await userSession.set(null);
|
|
111
111
|
};
|
|
112
112
|
|
|
113
113
|
type KeySetter = OAuthTokens | CodeVerifier;
|
|
@@ -119,23 +119,17 @@ class NextjsCookieStorage extends CookieStorage {
|
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
get(key: string): string | null {
|
|
123
|
-
|
|
122
|
+
async get(key: string): Promise<string | null> {
|
|
123
|
+
const cookieStore = await cookies();
|
|
124
|
+
return cookieStore.get(key)?.value || null;
|
|
124
125
|
}
|
|
125
126
|
|
|
126
|
-
set(key: KeySetter, value: string): void {
|
|
127
|
+
async set(key: KeySetter, value: string): Promise<void> {
|
|
128
|
+
const cookieStore = await cookies();
|
|
127
129
|
const cookieSettings = this.config?.[key as KeySetter] || {
|
|
128
130
|
...this.settings,
|
|
129
131
|
};
|
|
130
|
-
|
|
131
|
-
"NextjsCookieStorage.set",
|
|
132
|
-
JSON.stringify(
|
|
133
|
-
{ key, value, config: this.config, cookieSettings },
|
|
134
|
-
null,
|
|
135
|
-
2,
|
|
136
|
-
),
|
|
137
|
-
);
|
|
138
|
-
cookies().set(key, value, cookieSettings);
|
|
132
|
+
cookieStore.set(key, value, cookieSettings);
|
|
139
133
|
}
|
|
140
134
|
}
|
|
141
135
|
|
|
@@ -148,12 +142,14 @@ class NextjsClientStorage extends CookieStorage {
|
|
|
148
142
|
});
|
|
149
143
|
}
|
|
150
144
|
|
|
151
|
-
get(key: string): string | null {
|
|
152
|
-
|
|
145
|
+
async get(key: string): Promise<string | null> {
|
|
146
|
+
const cookieStore = await cookies();
|
|
147
|
+
return cookieStore.get(key)?.value || null;
|
|
153
148
|
}
|
|
154
149
|
|
|
155
|
-
set(key: string, value: string): void {
|
|
156
|
-
cookies()
|
|
150
|
+
async set(key: string, value: string): Promise<void> {
|
|
151
|
+
const cookieStore = await cookies();
|
|
152
|
+
cookieStore.set(key, value, this.settings);
|
|
157
153
|
}
|
|
158
154
|
}
|
|
159
155
|
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
TOKEN_EXCHANGE_TRIGGER_TEXT,
|
|
20
20
|
} from "@/constants.js";
|
|
21
21
|
import { serverTokenExchangeFromState } from "@/lib/oauth.js";
|
|
22
|
-
import { cookies } from "next/headers.js";
|
|
23
22
|
import { CodeVerifier } from "@/shared/lib/types.js";
|
|
24
23
|
|
|
25
24
|
const logger = loggers.nextjs.handlers.auth;
|
|
@@ -108,7 +107,6 @@ async function handleCallback(
|
|
|
108
107
|
console.log("handleCallback", {
|
|
109
108
|
code,
|
|
110
109
|
state,
|
|
111
|
-
cookies: cookies(),
|
|
112
110
|
appUrl,
|
|
113
111
|
});
|
|
114
112
|
|
|
@@ -148,9 +146,7 @@ async function handleCallback(
|
|
|
148
146
|
const appUrl = globalThis.window?.location?.origin;
|
|
149
147
|
fetch('${fetchUrl}&appUrl=' + appUrl).then((response) => {
|
|
150
148
|
response.json().then((jsonResponse) => {
|
|
151
|
-
console.log('fetch jsonResponse', jsonResponse);
|
|
152
149
|
if (jsonResponse.redirectUrl) {
|
|
153
|
-
console.log('handleCallback serverTokenExchangeFromState, redirecting');
|
|
154
150
|
window.location.href = jsonResponse.redirectUrl;
|
|
155
151
|
}
|
|
156
152
|
});
|
|
@@ -243,7 +239,7 @@ export async function handleLogout(
|
|
|
243
239
|
|
|
244
240
|
const response = NextResponse.redirect(finalRedirectUrl);
|
|
245
241
|
|
|
246
|
-
clearAuthCookies(config);
|
|
242
|
+
await clearAuthCookies(config);
|
|
247
243
|
|
|
248
244
|
try {
|
|
249
245
|
revalidatePath(isAbsoluteRedirect ? finalRedirectUrl : redirectTarget);
|
|
@@ -3,5 +3,4 @@ export { useToken } from "@/shared/hooks/useToken.js";
|
|
|
3
3
|
export { useAuth } from "@/shared/hooks/useAuth.js";
|
|
4
4
|
export { useSession } from "@/shared/hooks/useSession.js";
|
|
5
5
|
export { useConfig } from "@/shared/hooks/useConfig.js";
|
|
6
|
-
export { useTokenCookie } from "@/nextjs/hooks/useTokenCookie.js";
|
|
7
6
|
export { useIframe } from "@/shared/hooks/useIframe.js";
|
|
@@ -25,11 +25,6 @@ export class ServerAuthenticationResolver implements AuthenticationResolver {
|
|
|
25
25
|
readonly storage: AuthStorage,
|
|
26
26
|
readonly endpointOverrides?: Partial<Endpoints>,
|
|
27
27
|
) {
|
|
28
|
-
console.log("ServerAuthenticationResolver constructor", {
|
|
29
|
-
authConfig,
|
|
30
|
-
storage,
|
|
31
|
-
endpointOverrides,
|
|
32
|
-
});
|
|
33
28
|
this.pkceProducer = new GenericPublicClientPKCEProducer(storage);
|
|
34
29
|
}
|
|
35
30
|
validateExistingSession(): Promise<SessionData> {
|
|
@@ -72,13 +67,13 @@ export class ServerAuthenticationResolver implements AuthenticationResolver {
|
|
|
72
67
|
this.endpoints!, // clean up types here to avoid the ! operator
|
|
73
68
|
);
|
|
74
69
|
|
|
75
|
-
storeTokens(this.storage, tokens);
|
|
70
|
+
await storeTokens(this.storage, tokens);
|
|
76
71
|
|
|
77
72
|
return tokens;
|
|
78
73
|
}
|
|
79
74
|
|
|
80
75
|
async getSessionData(): Promise<SessionData | null> {
|
|
81
|
-
const storageData = retrieveTokens(this.storage);
|
|
76
|
+
const storageData = await retrieveTokens(this.storage);
|
|
82
77
|
|
|
83
78
|
if (!storageData) return null;
|
|
84
79
|
|
package/src/server/login.ts
CHANGED
|
@@ -29,8 +29,8 @@ export async function resolveOAuthAccessCode(
|
|
|
29
29
|
return authSessionService.tokenExchange(code, state);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export function isLoggedIn(storage: AuthStorage): boolean {
|
|
33
|
-
return !!storage.get("id_token");
|
|
32
|
+
export async function isLoggedIn(storage: AuthStorage): Promise<boolean> {
|
|
33
|
+
return !!(await storage.get("id_token"));
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export async function buildLoginUrl(
|
|
@@ -74,7 +74,6 @@ export class BrowserAuthenticationInitiator implements AuthenticationInitiator {
|
|
|
74
74
|
|
|
75
75
|
constructor(config: typeof this.config) {
|
|
76
76
|
this.config = config;
|
|
77
|
-
console.log("BrowserAuthenticationInitiator constructor", this.config);
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
async handleLoginAppPopupFailed(redirectUrl: string) {
|
|
@@ -97,11 +96,9 @@ export class BrowserAuthenticationInitiator implements AuthenticationInitiator {
|
|
|
97
96
|
thisURL.hostname === "localhost"
|
|
98
97
|
) {
|
|
99
98
|
if (!validateLoginAppPostMessage(event.data, this.config.clientId)) {
|
|
100
|
-
console.log("Received invalid message from login app", event.data);
|
|
101
99
|
return;
|
|
102
100
|
}
|
|
103
101
|
const loginMessage = event.data as LoginPostMessage;
|
|
104
|
-
console.log("Received message from login app", event.data);
|
|
105
102
|
this.handleLoginAppPopupFailed(loginMessage.data.url);
|
|
106
103
|
}
|
|
107
104
|
};
|
|
@@ -117,7 +114,6 @@ export class BrowserAuthenticationInitiator implements AuthenticationInitiator {
|
|
|
117
114
|
if (this.config.displayMode === "new_tab") {
|
|
118
115
|
try {
|
|
119
116
|
const popupWindow = window.open(url.toString(), "_blank");
|
|
120
|
-
console.log("signIn", popupWindow);
|
|
121
117
|
if (!popupWindow) {
|
|
122
118
|
throw new PopupError("Failed to open popup window");
|
|
123
119
|
}
|
|
@@ -133,8 +129,8 @@ export class BrowserAuthenticationInitiator implements AuthenticationInitiator {
|
|
|
133
129
|
|
|
134
130
|
async signOut(): Promise<URL> {
|
|
135
131
|
const localStorage = new LocalStorageAdapter();
|
|
136
|
-
clearTokens(localStorage);
|
|
137
|
-
clearUser(localStorage);
|
|
132
|
+
await clearTokens(localStorage);
|
|
133
|
+
await clearUser(localStorage);
|
|
138
134
|
// TODO open the iframe or new tab etc: the logout URL is not currently
|
|
139
135
|
// supported by on the oauth, so just clear state until then
|
|
140
136
|
const url = await generateOauthLogoutUrl(this.config);
|
|
@@ -168,9 +164,6 @@ export class GenericAuthenticationInitiator implements AuthenticationInitiator {
|
|
|
168
164
|
|
|
169
165
|
constructor(config: typeof this.config) {
|
|
170
166
|
this.config = config;
|
|
171
|
-
console.log("GenericAuthenticationInitiator constructor", {
|
|
172
|
-
config,
|
|
173
|
-
});
|
|
174
167
|
}
|
|
175
168
|
|
|
176
169
|
// Use the config (Client ID, scopes OAuth Server, Endpoints, PKCEConsumer) to generate a new login url
|
|
@@ -207,9 +200,6 @@ export class BrowserAuthenticationService extends BrowserAuthenticationInitiator
|
|
|
207
200
|
// Since we are running fully on the client, we produce as well as consume the PKCE challenge
|
|
208
201
|
protected pkceProducer = new BrowserPublicClientPKCEProducer(),
|
|
209
202
|
) {
|
|
210
|
-
console.log("BrowserAuthenticationService constructor", {
|
|
211
|
-
config,
|
|
212
|
-
});
|
|
213
203
|
super({
|
|
214
204
|
...config,
|
|
215
205
|
state: generateState(config.displayMode),
|
|
@@ -260,7 +250,7 @@ export class BrowserAuthenticationService extends BrowserAuthenticationInitiator
|
|
|
260
250
|
this.endpoints!, // clean up types here to avoid the ! operator
|
|
261
251
|
);
|
|
262
252
|
|
|
263
|
-
storeTokens(new LocalStorageAdapter(), tokens);
|
|
253
|
+
await storeTokens(new LocalStorageAdapter(), tokens);
|
|
264
254
|
|
|
265
255
|
// cleanup the browser window if needed
|
|
266
256
|
const parsedDisplayMode = displayModeFromState(
|
|
@@ -279,7 +269,7 @@ export class BrowserAuthenticationService extends BrowserAuthenticationInitiator
|
|
|
279
269
|
|
|
280
270
|
// Get the session data from local storage
|
|
281
271
|
async getSessionData(): Promise<SessionData | null> {
|
|
282
|
-
const storageData = retrieveTokens(new LocalStorageAdapter());
|
|
272
|
+
const storageData = await retrieveTokens(new LocalStorageAdapter());
|
|
283
273
|
|
|
284
274
|
if (!storageData) return null;
|
|
285
275
|
|
|
@@ -296,7 +286,7 @@ export class BrowserAuthenticationService extends BrowserAuthenticationInitiator
|
|
|
296
286
|
const sessionData = await this.getSessionData();
|
|
297
287
|
if (!sessionData?.idToken || !sessionData.accessToken) {
|
|
298
288
|
const unAuthenticatedSession = { ...sessionData, authenticated: false };
|
|
299
|
-
clearTokens(new LocalStorageAdapter());
|
|
289
|
+
await clearTokens(new LocalStorageAdapter());
|
|
300
290
|
return unAuthenticatedSession;
|
|
301
291
|
}
|
|
302
292
|
if (!this.endpoints || !this.oauth2client) await this.init();
|
|
@@ -318,7 +308,7 @@ export class BrowserAuthenticationService extends BrowserAuthenticationInitiator
|
|
|
318
308
|
const unAuthenticatedSession = {
|
|
319
309
|
authenticated: false,
|
|
320
310
|
};
|
|
321
|
-
clearTokens(new LocalStorageAdapter());
|
|
311
|
+
await clearTokens(new LocalStorageAdapter());
|
|
322
312
|
return unAuthenticatedSession;
|
|
323
313
|
}
|
|
324
314
|
}
|
|
@@ -106,9 +106,6 @@ const CivicAuthIframeContainer = ({
|
|
|
106
106
|
// On the initial (3rd party) redirect from the auth server, the cookie won't be sent, so the server-side callback route will just render a blank page,
|
|
107
107
|
// and we'll do the exchange request from here, which will include the cookies.
|
|
108
108
|
if (iframeBody.includes(TOKEN_EXCHANGE_TRIGGER_TEXT)) {
|
|
109
|
-
console.log(
|
|
110
|
-
`${TOKEN_EXCHANGE_TRIGGER_TEXT}, calling callback URL again...`,
|
|
111
|
-
);
|
|
112
109
|
const params = new URL(iframeUrl).searchParams;
|
|
113
110
|
const appUrl = globalThis.window?.location?.origin;
|
|
114
111
|
fetch(
|
|
@@ -157,7 +154,6 @@ const CivicAuthIframeContainer = ({
|
|
|
157
154
|
|
|
158
155
|
const handleIframeLoad = () => {
|
|
159
156
|
setIsLoading(false);
|
|
160
|
-
console.log("handleIframeLoad");
|
|
161
157
|
if (processIframeUrl() && intervalId.current) {
|
|
162
158
|
clearInterval(intervalId.current);
|
|
163
159
|
}
|
|
@@ -16,12 +16,7 @@ export class GenericAuthenticationRefresher implements AuthenticationRefresher {
|
|
|
16
16
|
private authConfig: AuthConfig,
|
|
17
17
|
private storage: AuthStorage,
|
|
18
18
|
private endpointOverrides?: Partial<Endpoints>,
|
|
19
|
-
) {
|
|
20
|
-
console.log("GenericAuthenticationRefresher constructor", {
|
|
21
|
-
authConfig,
|
|
22
|
-
endpointOverrides,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
19
|
+
) {}
|
|
25
20
|
|
|
26
21
|
async init(): Promise<this> {
|
|
27
22
|
// resolve oauth config
|
|
@@ -59,7 +54,7 @@ export class GenericAuthenticationRefresher implements AuthenticationRefresher {
|
|
|
59
54
|
async refreshTokens() {
|
|
60
55
|
if (!this.oauth2client) await this.init();
|
|
61
56
|
|
|
62
|
-
const tokens = retrieveTokens(this.storage);
|
|
57
|
+
const tokens = await retrieveTokens(this.storage);
|
|
63
58
|
if (!tokens?.refresh_token) throw new Error("No refresh token available");
|
|
64
59
|
|
|
65
60
|
const oauth2Client = this.oauth2client!;
|
|
@@ -68,7 +63,7 @@ export class GenericAuthenticationRefresher implements AuthenticationRefresher {
|
|
|
68
63
|
tokens.refresh_token,
|
|
69
64
|
);
|
|
70
65
|
|
|
71
|
-
storeTokens(this.storage, refreshedTokens);
|
|
66
|
+
await storeTokens(this.storage, refreshedTokens);
|
|
72
67
|
|
|
73
68
|
return tokens;
|
|
74
69
|
}
|