@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
|
@@ -3,23 +3,23 @@ import { UserStorage } from "@/shared/lib/types.js";
|
|
|
3
3
|
import { convertForwardedTokenFormat } from "@/lib/jwt.js";
|
|
4
4
|
|
|
5
5
|
export interface UserSession {
|
|
6
|
-
get(): User | null
|
|
7
|
-
set(user: User): void
|
|
6
|
+
get(): Promise<User | null>;
|
|
7
|
+
set(user: User): Promise<void>;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export class GenericUserSession implements UserSession {
|
|
11
11
|
constructor(readonly storage: AuthStorage) {}
|
|
12
12
|
|
|
13
|
-
get(): User | null {
|
|
14
|
-
const user = this.storage.get(UserStorage.USER);
|
|
13
|
+
async get(): Promise<User | null> {
|
|
14
|
+
const user = await this.storage.get(UserStorage.USER);
|
|
15
15
|
return user ? JSON.parse(user) : null;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
set(user: User | null): void {
|
|
18
|
+
async set(user: User | null): Promise<void> {
|
|
19
19
|
const forwardedTokens = user?.forwardedTokens
|
|
20
20
|
? convertForwardedTokenFormat(user?.forwardedTokens as ForwardedTokensJWT)
|
|
21
21
|
: null;
|
|
22
22
|
const value = user ? JSON.stringify({ ...user, forwardedTokens }) : "";
|
|
23
|
-
this.storage.set(UserStorage.USER, value);
|
|
23
|
+
await this.storage.set(UserStorage.USER, value);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -3,7 +3,7 @@ import { parseJWT } from "oslo/jwt";
|
|
|
3
3
|
import type { AuthStorage, User } from "@/types.js";
|
|
4
4
|
|
|
5
5
|
export async function getUser(storage: AuthStorage): Promise<User | null> {
|
|
6
|
-
const tokens = retrieveTokens(storage);
|
|
6
|
+
const tokens = await retrieveTokens(storage);
|
|
7
7
|
if (!tokens) return null;
|
|
8
8
|
|
|
9
9
|
// Assumes all information is in the ID token
|
|
@@ -35,6 +35,6 @@ export abstract class CookieStorage implements AuthStorage {
|
|
|
35
35
|
path: settings.path ?? "/",
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
abstract get(key: string): string | null
|
|
39
|
-
abstract set(key: string, value: string): void
|
|
38
|
+
abstract get(key: string): Promise<string | null>;
|
|
39
|
+
abstract set(key: string, value: string): Promise<void>;
|
|
40
40
|
}
|
package/src/shared/lib/util.ts
CHANGED
|
@@ -83,7 +83,6 @@ export async function generateOauthLoginUrl(config: {
|
|
|
83
83
|
// Required by the auth server for offline_access scope
|
|
84
84
|
oAuthUrl.searchParams.append("prompt", "consent");
|
|
85
85
|
|
|
86
|
-
console.log("Generated OAuth URL", oAuthUrl.toString());
|
|
87
86
|
return oAuthUrl;
|
|
88
87
|
}
|
|
89
88
|
|
|
@@ -139,36 +138,40 @@ export async function exchangeTokens(
|
|
|
139
138
|
return tokens;
|
|
140
139
|
}
|
|
141
140
|
|
|
142
|
-
export function storeTokens(
|
|
141
|
+
export async function storeTokens(
|
|
143
142
|
storage: AuthStorage,
|
|
144
143
|
tokens: OIDCTokenResponseBody,
|
|
145
144
|
) {
|
|
146
145
|
// store tokens in storage ( TODO we should probably store them against the state to allow multiple logins )
|
|
147
|
-
storage.set(OAuthTokens.ID_TOKEN, tokens.id_token);
|
|
148
|
-
storage.set(OAuthTokens.ACCESS_TOKEN, tokens.access_token);
|
|
149
|
-
if (tokens.refresh_token)
|
|
150
|
-
storage.set(OAuthTokens.REFRESH_TOKEN, tokens.refresh_token);
|
|
146
|
+
await storage.set(OAuthTokens.ID_TOKEN, tokens.id_token);
|
|
147
|
+
await storage.set(OAuthTokens.ACCESS_TOKEN, tokens.access_token);
|
|
148
|
+
if (tokens.refresh_token) {
|
|
149
|
+
await storage.set(OAuthTokens.REFRESH_TOKEN, tokens.refresh_token);
|
|
150
|
+
}
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
export function clearTokens(storage: AuthStorage) {
|
|
154
|
-
Object.values(OAuthTokens).
|
|
155
|
-
storage.set(cookie, "");
|
|
156
|
-
});
|
|
157
|
-
Object.values(CodeVerifier.COOKIE_NAME).forEach((cookie) => {
|
|
153
|
+
export async function clearTokens(storage: AuthStorage) {
|
|
154
|
+
const clearOAuthPromises = Object.values(OAuthTokens).map((cookie) => {
|
|
158
155
|
storage.set(cookie, "");
|
|
159
156
|
});
|
|
157
|
+
const clearCodeVerifierPromises = Object.values(CodeVerifier.COOKIE_NAME).map(
|
|
158
|
+
(cookie) => {
|
|
159
|
+
storage.set(cookie, "");
|
|
160
|
+
},
|
|
161
|
+
);
|
|
162
|
+
await Promise.all([...clearOAuthPromises, ...clearCodeVerifierPromises]);
|
|
160
163
|
}
|
|
161
|
-
export function clearUser(storage: AuthStorage) {
|
|
164
|
+
export async function clearUser(storage: AuthStorage) {
|
|
162
165
|
const userSession = new GenericUserSession(storage);
|
|
163
|
-
userSession.set(null);
|
|
166
|
+
await userSession.set(null);
|
|
164
167
|
}
|
|
165
168
|
|
|
166
|
-
export function retrieveTokens(
|
|
169
|
+
export async function retrieveTokens(
|
|
167
170
|
storage: AuthStorage,
|
|
168
|
-
): OIDCTokenResponseBody | null {
|
|
169
|
-
const idToken = storage.get(OAuthTokens.ID_TOKEN);
|
|
170
|
-
const accessToken = storage.get(OAuthTokens.ACCESS_TOKEN);
|
|
171
|
-
const refreshToken = storage.get(OAuthTokens.REFRESH_TOKEN);
|
|
171
|
+
): Promise<OIDCTokenResponseBody | null> {
|
|
172
|
+
const idToken = await storage.get(OAuthTokens.ID_TOKEN);
|
|
173
|
+
const accessToken = await storage.get(OAuthTokens.ACCESS_TOKEN);
|
|
174
|
+
const refreshToken = await storage.get(OAuthTokens.REFRESH_TOKEN);
|
|
172
175
|
|
|
173
176
|
if (!idToken || !accessToken) return null;
|
|
174
177
|
|
package/src/types.ts
CHANGED
|
@@ -17,25 +17,25 @@ const mockUser: User = {
|
|
|
17
17
|
describe("getUser", () => {
|
|
18
18
|
beforeEach(() => {
|
|
19
19
|
vi.clearAllMocks();
|
|
20
|
-
vi.spyOn(GenericUserSession.prototype, "get").
|
|
20
|
+
vi.spyOn(GenericUserSession.prototype, "get").mockResolvedValue(mockUser);
|
|
21
21
|
vi.spyOn(NextjsClientStorage.prototype, "get").mockImplementation(
|
|
22
|
-
(cookieName: string) => {
|
|
22
|
+
async (cookieName: string) => {
|
|
23
23
|
switch (cookieName) {
|
|
24
24
|
case "access_token":
|
|
25
|
-
return "test-access-token";
|
|
25
|
+
return Promise.resolve("test-access-token");
|
|
26
26
|
case "id_token":
|
|
27
|
-
return "test-id-token";
|
|
27
|
+
return Promise.resolve("test-id-token");
|
|
28
28
|
case "refresh_token":
|
|
29
|
-
return "test-refresh-token";
|
|
29
|
+
return Promise.resolve("test-refresh-token");
|
|
30
30
|
default:
|
|
31
|
-
return null;
|
|
31
|
+
return Promise.resolve(null);
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
it("should get the user from session", () => {
|
|
38
|
-
const user = getUser();
|
|
37
|
+
it("should get the user from session", async () => {
|
|
38
|
+
const user = await getUser();
|
|
39
39
|
expect(user).toEqual(mockUser);
|
|
40
40
|
});
|
|
41
41
|
});
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* IMPORTANT: If you modify this snapshot, it indicates changes to the public API of the auth SDK, which may impact consumers.
|
|
5
|
-
* Ensure such changes are discussed and agreed with the team and that the documentation is updated accordingly.
|
|
6
|
-
* Docmentation is managed on GitBook: https://app.gitbook.com/o/-MbHRfakrvYmMaAu3Awh/s/PrqdylKqzZDnu8FytHLf/
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
3
|
exports[`Auth Client Public API Snapshot > should match the previous API snapshot 1`] = `
|
|
10
4
|
{
|
|
11
5
|
"CivicAuthIframeContainer": [Function],
|
|
@@ -18,7 +12,6 @@ exports[`Auth Client Public API Snapshot > should match the previous API snapsho
|
|
|
18
12
|
"useIframe": [Function],
|
|
19
13
|
"useSession": [Function],
|
|
20
14
|
"useToken": [Function],
|
|
21
|
-
"useTokenCookie": [Function],
|
|
22
15
|
"useUser": [Function],
|
|
23
16
|
}
|
|
24
17
|
`;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { describe, it, expect, vi
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
2
|
import {
|
|
3
3
|
resolveOAuthAccessCode,
|
|
4
4
|
isLoggedIn,
|
|
5
5
|
buildLoginUrl,
|
|
6
|
-
} from "@/server/login
|
|
7
|
-
import { ServerAuthenticationResolver } from "@/server/ServerAuthenticationResolver
|
|
8
|
-
import { GenericAuthenticationInitiator } from "@/services/AuthenticationService
|
|
6
|
+
} from "@/server/login";
|
|
7
|
+
import { ServerAuthenticationResolver } from "@/server/ServerAuthenticationResolver";
|
|
8
|
+
import { GenericAuthenticationInitiator } from "@/services/AuthenticationService";
|
|
9
9
|
import { GenericPublicClientPKCEProducer } from "@/services/PKCE.js";
|
|
10
|
-
import { DEFAULT_AUTH_SERVER, DEFAULT_SCOPES } from "@/constants
|
|
11
|
-
import type {
|
|
12
|
-
import type { AuthConfig } from "@/server/config.
|
|
13
|
-
import type { PKCEProducer } from "@/services/types.
|
|
10
|
+
import { DEFAULT_AUTH_SERVER, DEFAULT_SCOPES } from "@/constants";
|
|
11
|
+
import type { AuthStorage, OIDCTokenResponseBody } from "@/types.js";
|
|
12
|
+
import type { AuthConfig } from "@/server/config.ts";
|
|
13
|
+
import type { PKCEProducer } from "@/services/types.ts";
|
|
14
14
|
|
|
15
15
|
vi.mock("@/server/ServerAuthenticationResolver");
|
|
16
16
|
vi.mock("@/services/AuthenticationService");
|
|
17
|
-
vi.mock("@/services/PKCE");
|
|
17
|
+
vi.mock("@/services/PKCE.js");
|
|
18
18
|
|
|
19
19
|
class StubPKCEProducer implements PKCEProducer {
|
|
20
20
|
constructor() {}
|
|
@@ -70,18 +70,18 @@ describe("Login Utilities", () => {
|
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
describe("isLoggedIn", () => {
|
|
73
|
-
it("should return true if id_token is in storage", () => {
|
|
74
|
-
vi.mocked(mockStorage.get).
|
|
73
|
+
it("should return true if id_token is in storage", async () => {
|
|
74
|
+
vi.mocked(mockStorage.get).mockResolvedValue("mockIdToken");
|
|
75
75
|
|
|
76
|
-
const result = isLoggedIn(mockStorage);
|
|
76
|
+
const result = await isLoggedIn(mockStorage);
|
|
77
77
|
|
|
78
78
|
expect(result).toBe(true);
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
-
it("should return false if id_token is not in storage", () => {
|
|
82
|
-
vi.mocked(mockStorage.get).
|
|
81
|
+
it("should return false if id_token is not in storage", async () => {
|
|
82
|
+
vi.mocked(mockStorage.get).mockResolvedValue(null);
|
|
83
83
|
|
|
84
|
-
const result = isLoggedIn(mockStorage);
|
|
84
|
+
const result = await isLoggedIn(mockStorage);
|
|
85
85
|
|
|
86
86
|
expect(result).toBe(false);
|
|
87
87
|
});
|
|
@@ -171,9 +171,11 @@ describe("Login Utilities", () => {
|
|
|
171
171
|
mockStorage,
|
|
172
172
|
);
|
|
173
173
|
|
|
174
|
-
expect(GenericAuthenticationInitiator).toHaveBeenCalledWith(
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
expect(GenericAuthenticationInitiator).toHaveBeenCalledWith(
|
|
175
|
+
expect.objectContaining({
|
|
176
|
+
nonce,
|
|
177
|
+
}),
|
|
178
|
+
);
|
|
177
179
|
});
|
|
178
180
|
});
|
|
179
181
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, it, expect, vi
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
2
|
import type { JWT } from "oslo/jwt";
|
|
3
3
|
import { parseJWT } from "oslo/jwt";
|
|
4
4
|
import { getUser } from "@/shared/lib/session.js";
|
|
@@ -20,7 +20,7 @@ describe("getUser", () => {
|
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
it("should return null if no tokens are retrieved", async () => {
|
|
23
|
-
vi.mocked(retrieveTokens).
|
|
23
|
+
vi.mocked(retrieveTokens).mockResolvedValue(null);
|
|
24
24
|
|
|
25
25
|
const result = await getUser(mockStorage);
|
|
26
26
|
expect(result).toBeNull();
|
|
@@ -29,7 +29,7 @@ describe("getUser", () => {
|
|
|
29
29
|
|
|
30
30
|
it("should return a User if tokens are retrieved and parsed successfully", async () => {
|
|
31
31
|
const mockTokens = { id_token: "mockIdToken" } as OIDCTokenResponseBody;
|
|
32
|
-
vi.mocked(retrieveTokens).
|
|
32
|
+
vi.mocked(retrieveTokens).mockResolvedValue(mockTokens);
|
|
33
33
|
vi.mocked(parseJWT).mockReturnValue({ payload: mockUser } as JWT);
|
|
34
34
|
|
|
35
35
|
const result = await getUser(mockStorage);
|
|
@@ -40,7 +40,7 @@ describe("getUser", () => {
|
|
|
40
40
|
|
|
41
41
|
it("should return null if parsing the ID token fails", async () => {
|
|
42
42
|
const mockTokens = { id_token: "mockIdToken" } as OIDCTokenResponseBody;
|
|
43
|
-
vi.mocked(retrieveTokens).
|
|
43
|
+
vi.mocked(retrieveTokens).mockResolvedValue(mockTokens);
|
|
44
44
|
vi.mocked(parseJWT).mockReturnValue(null); // Simulate parse failure
|
|
45
45
|
|
|
46
46
|
const result = await getUser(mockStorage);
|
|
@@ -29,7 +29,7 @@ vi.mock("@/shared/lib/util.js", () => ({
|
|
|
29
29
|
clearUser: vi.fn(),
|
|
30
30
|
}));
|
|
31
31
|
vi.mock("@/browser/storage");
|
|
32
|
-
vi.mock("@/services/PKCE");
|
|
32
|
+
vi.mock("@/services/PKCE.js");
|
|
33
33
|
|
|
34
34
|
describe("Authentication Services", () => {
|
|
35
35
|
const mockConfig = {
|
|
@@ -51,7 +51,7 @@ describe("Authentication Services", () => {
|
|
|
51
51
|
new URL("http://mockLoginUrl"),
|
|
52
52
|
);
|
|
53
53
|
|
|
54
|
-
const url = await initiator.signIn(
|
|
54
|
+
const url = await initiator.signIn({} as HTMLIFrameElement);
|
|
55
55
|
|
|
56
56
|
expect(url.toString()).toBe("http://mockloginurl/");
|
|
57
57
|
});
|
|
@@ -114,7 +114,7 @@ describe("Authentication Services", () => {
|
|
|
114
114
|
...mockConfig,
|
|
115
115
|
});
|
|
116
116
|
vi.mocked(exchangeTokens).mockResolvedValue(mockTokens);
|
|
117
|
-
vi.mocked(retrieveTokens).
|
|
117
|
+
vi.mocked(retrieveTokens).mockResolvedValue(mockTokens);
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
it("should exchange auth code for tokens and store them", async () => {
|
|
@@ -6,13 +6,18 @@ import {
|
|
|
6
6
|
retrieveTokens,
|
|
7
7
|
storeTokens,
|
|
8
8
|
} from "@/shared/lib/util.js";
|
|
9
|
-
import type {
|
|
10
|
-
|
|
9
|
+
import type {
|
|
10
|
+
AuthStorage,
|
|
11
|
+
Endpoints,
|
|
12
|
+
OIDCTokenResponseBody,
|
|
13
|
+
SessionData,
|
|
14
|
+
} from "@/types.js";
|
|
15
|
+
import type { AuthConfig } from "@/server/config.ts";
|
|
11
16
|
import { GenericPublicClientPKCEProducer } from "@/services/PKCE.js";
|
|
12
|
-
import type { AuthenticationResolver } from
|
|
17
|
+
import type { AuthenticationResolver } from "@/services/types.ts";
|
|
13
18
|
|
|
14
19
|
vi.mock("oslo/oauth2");
|
|
15
|
-
vi.mock("@/services/PKCE");
|
|
20
|
+
vi.mock("@/services/PKCE.js");
|
|
16
21
|
vi.mock("@/shared/lib/util.js");
|
|
17
22
|
|
|
18
23
|
describe("ServerAuthenticationResolver", () => {
|
|
@@ -84,7 +89,7 @@ describe("ServerAuthenticationResolver", () => {
|
|
|
84
89
|
|
|
85
90
|
describe("getSessionData", () => {
|
|
86
91
|
it("should retrieve session data from storage", async () => {
|
|
87
|
-
vi.mocked(retrieveTokens).
|
|
92
|
+
vi.mocked(retrieveTokens).mockResolvedValue(mockTokens);
|
|
88
93
|
|
|
89
94
|
const sessionData: SessionData = {
|
|
90
95
|
authenticated: true,
|
|
@@ -100,7 +105,7 @@ describe("ServerAuthenticationResolver", () => {
|
|
|
100
105
|
});
|
|
101
106
|
|
|
102
107
|
it("should return null if no tokens are found in storage", async () => {
|
|
103
|
-
vi.mocked(retrieveTokens).
|
|
108
|
+
vi.mocked(retrieveTokens).mockResolvedValue(null);
|
|
104
109
|
|
|
105
110
|
const result = await resolver.getSessionData();
|
|
106
111
|
|
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
retrieveTokens,
|
|
6
6
|
storeTokens,
|
|
7
7
|
} from "@/shared/lib/util.js";
|
|
8
|
-
import type { Endpoints, OIDCTokenResponseBody
|
|
8
|
+
import type { AuthStorage, Endpoints, OIDCTokenResponseBody } from "@/types.js";
|
|
9
9
|
import { OAuth2Client } from "oslo/oauth2";
|
|
10
|
-
import type { AuthConfig } from "@/server/config.
|
|
10
|
+
import type { AuthConfig } from "@/server/config.ts";
|
|
11
11
|
|
|
12
12
|
vi.mock("@/shared/lib/util.js");
|
|
13
13
|
vi.mock("oslo/oauth2");
|
|
@@ -55,7 +55,7 @@ describe("GenericAuthenticationRefresher", () => {
|
|
|
55
55
|
|
|
56
56
|
describe("refreshTokens", () => {
|
|
57
57
|
it("should refresh tokens and store them", async () => {
|
|
58
|
-
vi.mocked(retrieveTokens).
|
|
58
|
+
vi.mocked(retrieveTokens).mockResolvedValue(mockTokens);
|
|
59
59
|
const refreshedTokens: OIDCTokenResponseBody = {
|
|
60
60
|
id_token: "newIdToken",
|
|
61
61
|
access_token: "newAccessToken",
|
|
@@ -76,7 +76,7 @@ describe("GenericAuthenticationRefresher", () => {
|
|
|
76
76
|
});
|
|
77
77
|
|
|
78
78
|
it("should throw an error if no refresh token is available", async () => {
|
|
79
|
-
vi.mocked(retrieveTokens).
|
|
79
|
+
vi.mocked(retrieveTokens).mockResolvedValue({
|
|
80
80
|
...mockTokens,
|
|
81
81
|
refresh_token: undefined,
|
|
82
82
|
});
|
|
@@ -12,10 +12,10 @@ const mockUser: User = {
|
|
|
12
12
|
|
|
13
13
|
let storage: Record<string, string> = {};
|
|
14
14
|
class TestStorage implements AuthStorage {
|
|
15
|
-
get(key: string): string | null {
|
|
15
|
+
async get(key: string): Promise<string | null> {
|
|
16
16
|
return storage[key] ?? null;
|
|
17
17
|
}
|
|
18
|
-
set(key: string, value: string): void {
|
|
18
|
+
async set(key: string, value: string): Promise<void> {
|
|
19
19
|
storage[key] = value;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -26,16 +26,16 @@ describe("UserSession", () => {
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
describe("GenericUserSession", () => {
|
|
29
|
-
it("should get the user from session", () => {
|
|
29
|
+
it("should get the user from session", async () => {
|
|
30
30
|
const userSession = new GenericUserSession(new TestStorage());
|
|
31
31
|
userSession.set(mockUser);
|
|
32
|
-
const user = userSession.get();
|
|
32
|
+
const user = await userSession.get();
|
|
33
33
|
expect(user).toEqual(mockUser);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
it("should return null if user it not found", () => {
|
|
36
|
+
it("should return null if user it not found", async () => {
|
|
37
37
|
const userSession = new GenericUserSession(new TestStorage());
|
|
38
|
-
const user = userSession.get();
|
|
38
|
+
const user = await userSession.get();
|
|
39
39
|
expect(user).toBeNull();
|
|
40
40
|
});
|
|
41
41
|
});
|
|
@@ -13,10 +13,10 @@ describe("CookieStorage", () => {
|
|
|
13
13
|
super(settings);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
get(key: string): string | null {
|
|
16
|
+
async get(key: string): Promise<string | null> {
|
|
17
17
|
return this.storage[key] ?? null;
|
|
18
18
|
}
|
|
19
|
-
set(key: string, value: string): void {
|
|
19
|
+
async set(key: string, value: string): Promise<void> {
|
|
20
20
|
this.storage[key] = value;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -57,11 +57,11 @@ describe("CookieStorage", () => {
|
|
|
57
57
|
expect(storage["settings"]).toMatchObject(customSettings);
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
it("should set and get values correctly", () => {
|
|
60
|
+
it("should set and get values correctly", async () => {
|
|
61
61
|
const storage = new MockCookieStorage({});
|
|
62
62
|
|
|
63
|
-
storage.set("testKey", "testValue");
|
|
64
|
-
expect(storage.get("testKey")).toBe("testValue");
|
|
65
|
-
expect(storage.get("nonExistentKey")).toBe(null);
|
|
63
|
+
await storage.set("testKey", "testValue");
|
|
64
|
+
expect(await storage.get("testKey")).toBe("testValue");
|
|
65
|
+
expect(await storage.get("nonExistentKey")).toBe(null);
|
|
66
66
|
});
|
|
67
67
|
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/nextjs/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,IAAI,iBAAiB,EAC1C,KAAK,0BAA0B,IAAI,iBAAiB,GACrD,MAAM,yCAAyC,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CivicAuthProvider = void 0;
|
|
4
|
-
var NextAuthProvider_jsx_1 = require("@/nextjs/providers/NextAuthProvider.jsx");
|
|
5
|
-
Object.defineProperty(exports, "CivicAuthProvider", { enumerable: true, get: function () { return NextAuthProvider_jsx_1.CivicNextAuthProvider; } });
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/nextjs/client/index.ts"],"names":[],"mappings":";;;AAAA,gFAGiD;AAF/C,yHAAA,qBAAqB,OAAqB","sourcesContent":["export {\n CivicNextAuthProvider as CivicAuthProvider,\n type NextCivicAuthProviderProps as AuthProviderProps,\n} from \"@/nextjs/providers/NextAuthProvider.jsx\";\n"]}
|