@strivacity/sdk-nuxt 3.0.2 → 4.0.0-beta.0
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/.nuxt/app-component.mjs +1 -1
- package/.nuxt/app.config.mjs +21 -0
- package/.nuxt/component-names.mjs +1 -1
- package/.nuxt/components.d.ts +48 -48
- package/.nuxt/components.islands.mjs +6 -2
- package/.nuxt/error-component.mjs +1 -1
- package/.nuxt/fetch.d.ts +1 -0
- package/.nuxt/fetch.mjs +4 -3
- package/.nuxt/imports.d.ts +15 -5
- package/.nuxt/imports.mjs +15 -5
- package/.nuxt/island-renderer.mjs +2 -0
- package/.nuxt/middleware.mjs +3 -1
- package/.nuxt/nuxt.config.mjs +103 -0
- package/.nuxt/nuxt.d.ts +3 -4
- package/.nuxt/nuxt.node.d.ts +4 -4
- package/.nuxt/nuxt.shared.d.ts +3 -1
- package/.nuxt/plugins.client.mjs +10 -14
- package/.nuxt/plugins.server.mjs +6 -6
- package/.nuxt/root-component.mjs +1 -1
- package/.nuxt/route-rules.mjs +22 -0
- package/.nuxt/test-component-wrapper.mjs +1 -1
- package/.nuxt/tsconfig.app.json +211 -0
- package/.nuxt/tsconfig.json +212 -0
- package/.nuxt/tsconfig.node.json +117 -0
- package/.nuxt/tsconfig.server.json +161 -0
- package/.nuxt/tsconfig.shared.json +165 -0
- package/.nuxt/types/app.config.d.ts +35 -0
- package/.nuxt/types/components.d.ts +48 -48
- package/.nuxt/types/imports.d.ts +1 -1
- package/.nuxt/types/layouts.d.ts +16 -0
- package/.nuxt/types/modules.d.ts +20 -20
- package/.nuxt/types/nitro-imports.d.ts +9 -4
- package/.nuxt/types/nitro-layouts.d.ts +17 -0
- package/.nuxt/types/nitro-nuxt.d.ts +19 -5
- package/.nuxt/types/nitro-routes.d.ts +25 -1
- package/.nuxt/types/plugins.d.ts +8 -9
- package/.nuxt/types/runtime-config.d.ts +6 -12
- package/.nuxt/types/shared-app.config.d.ts +28 -0
- package/.nuxt/types/shared-imports.d.ts +2 -0
- package/.nuxt/unhead-options.mjs +2 -1
- package/.nuxt/unhead.config.mjs +1 -0
- package/CHANGELOG.md +16 -14
- package/README.md +1577 -406
- package/build.config.ts +5 -0
- package/dist/module.d.mts +3 -193
- package/dist/module.json +2 -2
- package/dist/module.mjs +78 -57
- package/dist/module.mjs.map +1 -1
- package/dist/runtime/composables/use-native-login-context.d.ts +10 -0
- package/dist/runtime/composables/use-native-login-context.js +9 -0
- package/dist/runtime/composables/use-native-login.d.ts +10 -0
- package/dist/runtime/composables/use-native-login.js +143 -0
- package/dist/runtime/composables/use-session.d.ts +8 -0
- package/dist/runtime/composables/use-session.js +2 -0
- package/dist/runtime/composables/use-strivacity.d.ts +9 -0
- package/dist/runtime/composables/use-strivacity.js +77 -0
- package/dist/runtime/middleware/auth.server.d.ts +2 -0
- package/dist/runtime/middleware/auth.server.js +12 -0
- package/dist/runtime/server/api/auth/backchannel-logout.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/backchannel-logout.get.js +2 -0
- package/dist/runtime/server/api/auth/callback.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/callback.get.js +2 -0
- package/dist/runtime/server/api/auth/entry.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/entry.get.js +2 -0
- package/dist/runtime/server/api/auth/login.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/login.get.js +2 -0
- package/dist/runtime/server/api/auth/logout.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/logout.get.js +2 -0
- package/dist/runtime/server/api/auth/refresh.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/refresh.get.js +2 -0
- package/dist/runtime/server/api/auth/register.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/register.get.js +2 -0
- package/dist/runtime/server/api/auth/revoke.get.d.ts +2 -0
- package/dist/runtime/server/api/auth/revoke.get.js +2 -0
- package/dist/runtime/server/composables/use-strivacity.d.ts +2 -0
- package/dist/runtime/server/composables/use-strivacity.js +9 -0
- package/dist/runtime/server/plugins/auth.server.d.ts +10 -0
- package/dist/runtime/server/plugins/auth.server.js +66 -0
- package/dist/runtime/server/utils/helpers.d.ts +18 -0
- package/dist/runtime/server/utils/helpers.js +39 -0
- package/dist/runtime/storages/core.d.ts +1 -0
- package/dist/runtime/storages/core.js +13 -0
- package/dist/runtime/storages/default.d.ts +21 -0
- package/dist/runtime/storages/default.js +71 -0
- package/dist/runtime/types.d.ts +219 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/utils/core.d.ts +1 -0
- package/dist/runtime/utils/core.js +64 -0
- package/dist/runtime/utils/noop.d.ts +1 -0
- package/dist/runtime/utils/noop.js +3 -0
- package/dist/types.d.mts +4 -16
- package/eslint.config.mjs +5 -0
- package/nuxt.config.ts +5 -0
- package/package.json +31 -5
- package/project.json +44 -0
- package/src/module.ts +107 -0
- package/src/runtime/composables/use-native-login-context.ts +20 -0
- package/src/runtime/composables/use-native-login.ts +182 -0
- package/src/runtime/composables/use-session.ts +10 -0
- package/src/runtime/composables/use-strivacity.ts +95 -0
- package/src/runtime/middleware/auth.server.ts +16 -0
- package/src/runtime/server/api/auth/backchannel-logout.get.ts +3 -0
- package/src/runtime/server/api/auth/callback.get.ts +3 -0
- package/src/runtime/server/api/auth/entry.get.ts +3 -0
- package/src/runtime/server/api/auth/login.get.ts +3 -0
- package/src/runtime/server/api/auth/logout.get.ts +3 -0
- package/src/runtime/server/api/auth/refresh.get.ts +3 -0
- package/src/runtime/server/api/auth/register.get.ts +3 -0
- package/src/runtime/server/api/auth/revoke.get.ts +3 -0
- package/src/runtime/server/composables/use-strivacity.ts +13 -0
- package/src/runtime/server/plugins/auth.server.ts +84 -0
- package/src/runtime/server/utils/helpers.ts +67 -0
- package/src/runtime/storages/core.ts +13 -0
- package/src/runtime/storages/default.ts +111 -0
- package/src/runtime/types.ts +289 -0
- package/src/runtime/utils/core.ts +64 -0
- package/src/runtime/utils/noop.ts +3 -0
- package/testing/stubs/app.ts +6 -0
- package/testing/stubs/imports.ts +19 -0
- package/testing/stubs/options-httpClient.ts +8 -0
- package/testing/stubs/options-logging.ts +8 -0
- package/testing/stubs/options-stateStorage.ts +8 -0
- package/testing/stubs/options-storage.ts +8 -0
- package/testing/tests/composables.spec.ts +512 -0
- package/testing/tests/server/helpers.spec.ts +86 -0
- package/testing/tests/server/plugin.spec.ts +138 -0
- package/testing/tests/server/routes.spec.ts +34 -0
- package/testing/tests/server/use-strivacity.spec.ts +22 -0
- package/testing/tests/storages-default.spec.ts +151 -0
- package/testing/tests/storages.spec.ts +16 -0
- package/testing/tests/utils.spec.ts +10 -0
- package/testing/utils/common.ts +33 -0
- package/testing/utils/http.ts +58 -0
- package/tsconfig.json +3 -0
- package/vite.config.mts +20 -0
- package/.nuxt/strivacity-sdk-logging.d.ts +0 -13
- package/.nuxt/strivacity-sdk-logging.mjs +0 -1
- package/.nuxt/strivacity-sdk-storage.d.ts +0 -10
- package/.nuxt/strivacity-sdk-storage.mjs +0 -1
- package/dist/runtime/composables.d.ts +0 -12
- package/dist/runtime/composables.js +0 -83
- package/dist/runtime/login-renderer.vue +0 -174
- package/dist/runtime/login-renderer.vue.d.ts +0 -39
- /package/.nuxt/manifest/meta/{b47927c0-b36b-4d2c-b650-8d55c5ec676a.json → cb11df97-b0c9-4a91-9d4b-60c25c918599.json} +0 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ref } from "vue";
|
|
2
|
+
import { initFlow } from "@strivacity/sdk-core";
|
|
3
|
+
import { useRuntimeConfig } from "#app";
|
|
4
|
+
import { useSession } from "./use-session.js";
|
|
5
|
+
import createLogging from "#strivacity-options-logging";
|
|
6
|
+
import createHttpClient from "#strivacity-options-httpClient";
|
|
7
|
+
let sdk;
|
|
8
|
+
const loadingRef = ref(true);
|
|
9
|
+
const languageRef = ref(globalThis.navigator?.language ?? "en-US");
|
|
10
|
+
const isAuthenticatedRef = ref(false);
|
|
11
|
+
const idTokenClaimsRef = ref(null);
|
|
12
|
+
const accessTokenRef = ref(null);
|
|
13
|
+
const refreshTokenRef = ref(null);
|
|
14
|
+
const accessTokenExpiredRef = ref(true);
|
|
15
|
+
const accessTokenExpirationDateRef = ref(null);
|
|
16
|
+
const updateSession = async () => {
|
|
17
|
+
const authenticated = await sdk.isAuthenticated;
|
|
18
|
+
if (loadingRef.value) {
|
|
19
|
+
loadingRef.value = false;
|
|
20
|
+
}
|
|
21
|
+
if (sdk.language !== languageRef.value) {
|
|
22
|
+
languageRef.value = sdk.language;
|
|
23
|
+
}
|
|
24
|
+
if (authenticated !== isAuthenticatedRef.value) {
|
|
25
|
+
isAuthenticatedRef.value = authenticated;
|
|
26
|
+
}
|
|
27
|
+
if (sdk.idTokenClaims !== idTokenClaimsRef.value) {
|
|
28
|
+
idTokenClaimsRef.value = sdk.idTokenClaims || null;
|
|
29
|
+
}
|
|
30
|
+
if (sdk.accessToken !== accessTokenRef.value) {
|
|
31
|
+
accessTokenRef.value = sdk.accessToken || null;
|
|
32
|
+
}
|
|
33
|
+
if (sdk.refreshToken !== refreshTokenRef.value) {
|
|
34
|
+
refreshTokenRef.value = sdk.refreshToken || null;
|
|
35
|
+
}
|
|
36
|
+
if (sdk.accessTokenExpired !== accessTokenExpiredRef.value) {
|
|
37
|
+
accessTokenExpiredRef.value = sdk.accessTokenExpired;
|
|
38
|
+
}
|
|
39
|
+
if (sdk.accessTokenExpirationDate !== accessTokenExpirationDateRef.value) {
|
|
40
|
+
accessTokenExpirationDateRef.value = sdk.accessTokenExpirationDate || null;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export const useStrivacity = () => {
|
|
44
|
+
if (!sdk) {
|
|
45
|
+
sdk = initFlow({
|
|
46
|
+
...useRuntimeConfig().public.strivacity,
|
|
47
|
+
logging: createLogging ? createLogging() : void 0,
|
|
48
|
+
httpClient: createHttpClient ? createHttpClient() : void 0
|
|
49
|
+
});
|
|
50
|
+
sdk.subscribeToAllEvents(updateSession);
|
|
51
|
+
sdk.session = useSession().value;
|
|
52
|
+
void updateSession();
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
sdk,
|
|
56
|
+
loading: loadingRef,
|
|
57
|
+
language: languageRef,
|
|
58
|
+
isAuthenticated: isAuthenticatedRef,
|
|
59
|
+
idTokenClaims: idTokenClaimsRef,
|
|
60
|
+
accessToken: accessTokenRef,
|
|
61
|
+
refreshToken: refreshTokenRef,
|
|
62
|
+
accessTokenExpired: accessTokenExpiredRef,
|
|
63
|
+
accessTokenExpirationDate: accessTokenExpirationDateRef,
|
|
64
|
+
init: () => sdk.init(),
|
|
65
|
+
subscribeToEvent: ((...args) => sdk.subscribeToEvent(...args)),
|
|
66
|
+
subscribeToAllEvents: (...args) => sdk.subscribeToAllEvents(...args),
|
|
67
|
+
checkAuthentication: (...args) => sdk.checkAuthentication(...args),
|
|
68
|
+
tokenExchange: (...args) => sdk.tokenExchange(...args),
|
|
69
|
+
handleCallback: (...args) => sdk.handleCallback(...args),
|
|
70
|
+
refresh: () => sdk.refresh(),
|
|
71
|
+
revoke: () => sdk.revoke(),
|
|
72
|
+
logout: (...args) => sdk.logout(...args),
|
|
73
|
+
login: (...args) => sdk.login(...args),
|
|
74
|
+
register: (...args) => sdk.register(...args),
|
|
75
|
+
entry: (...args) => sdk.entry(...args)
|
|
76
|
+
};
|
|
77
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineNuxtRouteMiddleware, useNuxtApp } from "#imports";
|
|
2
|
+
import { useSession } from "../composables/use-session.js";
|
|
3
|
+
export default defineNuxtRouteMiddleware(async () => {
|
|
4
|
+
if (!import.meta.server) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const app = useNuxtApp();
|
|
8
|
+
const h3Event = app.ssrContext.event;
|
|
9
|
+
const { useStrivacity } = await import("../server/composables/use-strivacity.js");
|
|
10
|
+
const sdk = useStrivacity(h3Event);
|
|
11
|
+
useSession().value = await sdk.getSession() ?? void 0;
|
|
12
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const useStrivacity = (event) => {
|
|
2
|
+
if (import.meta.client) {
|
|
3
|
+
throw new Error('The "useStrivacity" composable should only be used on the server.');
|
|
4
|
+
}
|
|
5
|
+
if (!event) {
|
|
6
|
+
throw new Error("useStrivacity() can not be called without passing an H3Event instance.");
|
|
7
|
+
}
|
|
8
|
+
return event.context.strivacity.sdk;
|
|
9
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { toWebRequest } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
import { defineNitroPlugin } from "nitropack/dist/runtime/plugin";
|
|
4
|
+
import { createBaseServerSDK } from "@strivacity/sdk-core/server";
|
|
5
|
+
import { ConfigurationError } from "@strivacity/sdk-core/utils";
|
|
6
|
+
import { createEncryptedCookieStorage } from "../../storages/default.js";
|
|
7
|
+
export default defineNitroPlugin((nitroApp) => {
|
|
8
|
+
void setupAuthPlugin(nitroApp);
|
|
9
|
+
});
|
|
10
|
+
async function setupAuthPlugin(nitroApp) {
|
|
11
|
+
const config = useRuntimeConfig();
|
|
12
|
+
const initConfig = { ...config.strivacity };
|
|
13
|
+
const customStorage = (await import("#strivacity-options-storage")).default();
|
|
14
|
+
const customStateStorage = (await import("#strivacity-options-stateStorage")).default();
|
|
15
|
+
const customLogging = (await import("#strivacity-options-logging")).default();
|
|
16
|
+
const customHttpClient = (await import("#strivacity-options-httpClient")).default();
|
|
17
|
+
if (customStorage) {
|
|
18
|
+
initConfig.storage = customStorage;
|
|
19
|
+
}
|
|
20
|
+
if (customStateStorage) {
|
|
21
|
+
initConfig.stateStorage = customStateStorage;
|
|
22
|
+
}
|
|
23
|
+
if (customLogging) {
|
|
24
|
+
initConfig.logging = customLogging;
|
|
25
|
+
}
|
|
26
|
+
if (customHttpClient) {
|
|
27
|
+
initConfig.httpClient = customHttpClient;
|
|
28
|
+
}
|
|
29
|
+
if (!initConfig.storage) {
|
|
30
|
+
if (!initConfig.secret) {
|
|
31
|
+
throw new ConfigurationError("Secret is required for encrypted cookie storage");
|
|
32
|
+
}
|
|
33
|
+
initConfig.cookieMaxAge ??= 30 * 24 * 60 * 60;
|
|
34
|
+
initConfig.storage = createEncryptedCookieStorage(initConfig.secret, { defaultCookieOptions: { maxAge: initConfig.cookieMaxAge } });
|
|
35
|
+
}
|
|
36
|
+
const base = createBaseServerSDK(
|
|
37
|
+
{
|
|
38
|
+
toRequest: (event) => toWebRequest(event)
|
|
39
|
+
},
|
|
40
|
+
initConfig
|
|
41
|
+
);
|
|
42
|
+
nitroApp.hooks.hook("request", (event) => {
|
|
43
|
+
event.context.strivacity ??= {};
|
|
44
|
+
event.context.strivacity.sdk ??= {
|
|
45
|
+
get options() {
|
|
46
|
+
return base.options;
|
|
47
|
+
},
|
|
48
|
+
getSession: () => base.getSession(event),
|
|
49
|
+
updateSession: (session) => base.updateSession(session, event),
|
|
50
|
+
refreshSession: () => base.refreshSession(event),
|
|
51
|
+
revokeSession: () => base.revokeSession(event),
|
|
52
|
+
getEntrySession: (entryUrl) => base.getEntrySession(entryUrl),
|
|
53
|
+
completeLogin: (params) => base.completeLogin(params, event),
|
|
54
|
+
logout: (postLogoutRedirectUri) => base.logout(postLogoutRedirectUri, event),
|
|
55
|
+
handleLogin: (evt) => base.handleLogin(evt),
|
|
56
|
+
handleRegister: (evt) => base.handleRegister(evt),
|
|
57
|
+
handleCallback: (evt) => base.handleCallback(evt),
|
|
58
|
+
handleRefresh: (evt) => base.handleRefresh(evt),
|
|
59
|
+
handleRevoke: (evt) => base.handleRevoke(evt),
|
|
60
|
+
handleEntry: (evt) => base.handleEntry(evt),
|
|
61
|
+
handleLogout: (evt) => base.handleLogout(evt),
|
|
62
|
+
handleBackChannelLogout: (evt) => base.handleBackChannelLogout(evt),
|
|
63
|
+
handler: (evt) => base.handler(evt)
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
import type { HttpClientResponse } from '@strivacity/sdk-core/types';
|
|
3
|
+
/**
|
|
4
|
+
* Proxies an HttpClientResponse to a Web Response, preserving headers and status code.
|
|
5
|
+
*/
|
|
6
|
+
export declare function proxyResponse<T = unknown>(response: HttpClientResponse<T>): Response;
|
|
7
|
+
/**
|
|
8
|
+
* Extracts the accept-language locale from the event's request headers.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getLocaleFromEvent(event: H3Event): string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Returns a safe absolute redirect URL only if it shares the same origin as safeBaseUrl, preventing open redirects.
|
|
13
|
+
*
|
|
14
|
+
* @param dangerousRedirect - The untrusted redirect path or URL.
|
|
15
|
+
* @param safeBaseUrl - The trusted base URL whose origin is used as the allowed origin.
|
|
16
|
+
* @returns The resolved URL string if safe, or undefined.
|
|
17
|
+
*/
|
|
18
|
+
export declare function toSafeRedirect(dangerousRedirect: string | undefined | null, safeBaseUrl: string): string | null;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DISALLOWED_PROXY_HEADERS } from "@strivacity/sdk-core/utils";
|
|
2
|
+
export function proxyResponse(response) {
|
|
3
|
+
const proxyHeaders = new Headers();
|
|
4
|
+
for (const [key, value] of response.headers.entries()) {
|
|
5
|
+
if (key.toLowerCase() === "set-cookie") continue;
|
|
6
|
+
if (!DISALLOWED_PROXY_HEADERS.has(key.toLowerCase())) {
|
|
7
|
+
proxyHeaders.set(key, value);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const setCookie = response.headers.get("set-cookie");
|
|
11
|
+
if (setCookie) {
|
|
12
|
+
proxyHeaders.set("set-cookie", setCookie);
|
|
13
|
+
}
|
|
14
|
+
return new Response(response.body ?? null, {
|
|
15
|
+
status: response.status,
|
|
16
|
+
headers: proxyHeaders
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export function getLocaleFromEvent(event) {
|
|
20
|
+
const acceptLanguage = event.headers.get("accept-language");
|
|
21
|
+
if (!acceptLanguage) return void 0;
|
|
22
|
+
return acceptLanguage.split(",")[0]?.split(";")[0]?.trim();
|
|
23
|
+
}
|
|
24
|
+
export function toSafeRedirect(dangerousRedirect, safeBaseUrl) {
|
|
25
|
+
let url;
|
|
26
|
+
if (!dangerousRedirect) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
safeBaseUrl = new URL(safeBaseUrl).origin;
|
|
31
|
+
url = new URL(dangerousRedirect?.startsWith("/") ? dangerousRedirect.slice(1) : dangerousRedirect, safeBaseUrl);
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (url.origin === new URL(safeBaseUrl).origin) {
|
|
36
|
+
return url.toString();
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { COOKIE_CONTEXT, COOKIE_CHUNK_SIZE, createCacheAPIStorage, createIndexedDBStorage, createLocalStorage, createMemoryStorage, createServerMemoryStorage, createSessionStorage, createWorkerStorage, handleWorkerStorageRequests, createServerStateStorage, } from '@strivacity/sdk-core/storages';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export {
|
|
2
|
+
COOKIE_CONTEXT,
|
|
3
|
+
COOKIE_CHUNK_SIZE,
|
|
4
|
+
createCacheAPIStorage,
|
|
5
|
+
createIndexedDBStorage,
|
|
6
|
+
createLocalStorage,
|
|
7
|
+
createMemoryStorage,
|
|
8
|
+
createServerMemoryStorage,
|
|
9
|
+
createSessionStorage,
|
|
10
|
+
createWorkerStorage,
|
|
11
|
+
handleWorkerStorageRequests,
|
|
12
|
+
createServerStateStorage
|
|
13
|
+
} from "@strivacity/sdk-core/storages";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
import type { EncryptedCookieStorageOptions, ServerStorage, SessionIdCookieStorageOptions } from '@strivacity/sdk-core/types';
|
|
3
|
+
import type { NuxtServerStorage } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a session storage that puts a random unique id value cookie on the client and keeping the actual session data in the given `storage`.
|
|
6
|
+
*
|
|
7
|
+
* @param {SDKStorage} storage - The storage used to persist session data, keyed by a randomly generated session id.
|
|
8
|
+
* @param {SessionIdCookieStorageOptions} [options] - Options for configuring the session-id cookie storage.
|
|
9
|
+
* @returns {ServerStorage} An object implementing the ServerStorage interface for managing sessions indexed by a session-id cookie.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createSessionIdCookieStorage(storage: ServerStorage, options?: SessionIdCookieStorageOptions): ServerStorage<H3Event<import("h3").EventHandlerRequest>>;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an encrypted cookie session storage.
|
|
14
|
+
* Only callable in server-side contexts.
|
|
15
|
+
*
|
|
16
|
+
* @param secret - The secret key used for encryption and decryption.
|
|
17
|
+
* @param {EncryptedCookieStorageOptions} [options] - Options for configuring the encrypted cookie storage.
|
|
18
|
+
* @param {Partial<ServerCookieOptions>} [options.defaultCookieOptions] - Default cookie attributes for the encrypted cookie.
|
|
19
|
+
* @returns An object implementing the NuxtServerStorage interface for managing encrypted cookies in Nuxt.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createEncryptedCookieStorage(secret: string, options?: EncryptedCookieStorageOptions): NuxtServerStorage;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { getCookie, setCookie, deleteCookie, toWebRequest } from "h3";
|
|
2
|
+
import { encryptString, decryptString } from "@strivacity/sdk-core/utils/crypto";
|
|
3
|
+
import { COOKIE_CONTEXT, COOKIE_CHUNK_SIZE } from "@strivacity/sdk-core/server";
|
|
4
|
+
import { createSessionIdCookieStorage as createSessionIdCookieStorageBase } from "@strivacity/sdk-core/storages/server";
|
|
5
|
+
export function createSessionIdCookieStorage(storage, options) {
|
|
6
|
+
return createSessionIdCookieStorageBase(
|
|
7
|
+
{
|
|
8
|
+
toRequest: (event) => toWebRequest(event)
|
|
9
|
+
},
|
|
10
|
+
storage,
|
|
11
|
+
options
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
export function createEncryptedCookieStorage(secret, options) {
|
|
15
|
+
const defaultCookieOptions = {
|
|
16
|
+
httpOnly: true,
|
|
17
|
+
secure: true,
|
|
18
|
+
path: "/",
|
|
19
|
+
sameSite: "lax",
|
|
20
|
+
...options?.defaultCookieOptions
|
|
21
|
+
};
|
|
22
|
+
const storage = {
|
|
23
|
+
async get(key, event) {
|
|
24
|
+
if (!event) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const cookie = getCookie(event, key) ?? null;
|
|
28
|
+
if (cookie) {
|
|
29
|
+
return await decryptString(cookie, secret, COOKIE_CONTEXT);
|
|
30
|
+
}
|
|
31
|
+
const cookieChunks = [];
|
|
32
|
+
for (let i = 0; ; i++) {
|
|
33
|
+
const chunk = getCookie(event, `${key}.${i}`);
|
|
34
|
+
if (!chunk) {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
cookieChunks.push(chunk);
|
|
38
|
+
}
|
|
39
|
+
if (cookieChunks.length === 0) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return await decryptString(cookieChunks.join(""), secret, COOKIE_CONTEXT);
|
|
43
|
+
},
|
|
44
|
+
async set(key, value, event, cookieOptions = {}) {
|
|
45
|
+
if (!event) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
cookieOptions = { ...defaultCookieOptions, ...cookieOptions };
|
|
49
|
+
await storage.delete(key, event, cookieOptions);
|
|
50
|
+
const encrypted = await encryptString(value, secret, COOKIE_CONTEXT);
|
|
51
|
+
if (encrypted.length <= COOKIE_CHUNK_SIZE) {
|
|
52
|
+
setCookie(event, key, encrypted, cookieOptions);
|
|
53
|
+
} else {
|
|
54
|
+
for (let i = 0; i * COOKIE_CHUNK_SIZE < encrypted.length; i++) {
|
|
55
|
+
setCookie(event, `${key}.${i}`, encrypted.slice(i * COOKIE_CHUNK_SIZE, (i + 1) * COOKIE_CHUNK_SIZE), cookieOptions);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
async delete(key, event, cookieOptions = {}) {
|
|
60
|
+
if (!event) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
deleteCookie(event, key, cookieOptions);
|
|
64
|
+
for (let i = 0; getCookie(event, `${key}.${i}`); i++) {
|
|
65
|
+
deleteCookie(event, `${key}.${i}`, cookieOptions);
|
|
66
|
+
}
|
|
67
|
+
return Promise.resolve();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
return storage;
|
|
71
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
import type { Ref } from 'vue';
|
|
3
|
+
import type { ServerSDKOptions, ServerSDKInitConfig, SDKStorage, CookieOptions, IdTokenClaims, RedirectFlow, PopupFlow, NativeFlow, EmbeddedFlow, NativeFlowMessage, initFlow, FallbackError, NativeParams, NativeFlowState, SessionData, LogoutTokenClaims, BaseServerSDK } from '@strivacity/sdk-core';
|
|
4
|
+
declare module '@nuxt/schema' {
|
|
5
|
+
interface RuntimeConfig {
|
|
6
|
+
strivacity: StrivacityRuntimeConfig;
|
|
7
|
+
}
|
|
8
|
+
interface PublicRuntimeConfig {
|
|
9
|
+
strivacity: StrivacityPublicRuntimeConfig;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export * from '@strivacity/sdk-core/types';
|
|
13
|
+
export type StrivacityRuntimeConfig = NuxtServerSDKInitConfig;
|
|
14
|
+
export type StrivacityPublicRuntimeConfig = Omit<NuxtServerSDKInitConfig, 'secret' | 'storageFactoryPath' | 'stateStorageFactoryPath' | 'loggingFactoryPath' | 'httpClientFactoryPath'>;
|
|
15
|
+
export type SDKContext<Flow extends RedirectFlow | PopupFlow | NativeFlow | EmbeddedFlow> = {
|
|
16
|
+
/**
|
|
17
|
+
* The underlying Strivacity SDK flow instance.
|
|
18
|
+
*/
|
|
19
|
+
readonly sdk: Flow;
|
|
20
|
+
/**
|
|
21
|
+
* A boolean indicating whether the SDK is still loading.
|
|
22
|
+
*/
|
|
23
|
+
readonly loading: Ref<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* BCP 47 language code representing the current language of the SDK.
|
|
26
|
+
*/
|
|
27
|
+
readonly language: Ref<string>;
|
|
28
|
+
/**
|
|
29
|
+
* A boolean ref indicating whether the user is authenticated.
|
|
30
|
+
*/
|
|
31
|
+
readonly isAuthenticated: Ref<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* The claims from the ID token, if available.
|
|
34
|
+
*/
|
|
35
|
+
readonly idTokenClaims: Ref<IdTokenClaims | null>;
|
|
36
|
+
/**
|
|
37
|
+
* The access token, if available.
|
|
38
|
+
*/
|
|
39
|
+
readonly accessToken: Ref<string | null>;
|
|
40
|
+
/**
|
|
41
|
+
* The refresh token, if available.
|
|
42
|
+
*/
|
|
43
|
+
readonly refreshToken: Ref<string | null>;
|
|
44
|
+
/**
|
|
45
|
+
* A boolean ref indicating whether the access token has expired.
|
|
46
|
+
*/
|
|
47
|
+
readonly accessTokenExpired: Ref<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* The expiration date of the access token, if available.
|
|
50
|
+
*/
|
|
51
|
+
readonly accessTokenExpirationDate: Ref<number | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Subscribes to a specific SDK event.
|
|
54
|
+
*/
|
|
55
|
+
subscribeToEvent: Flow['subscribeToEvent'];
|
|
56
|
+
/**
|
|
57
|
+
* Subscribes to all SDK events.
|
|
58
|
+
*/
|
|
59
|
+
subscribeToAllEvents: Flow['subscribeToAllEvents'];
|
|
60
|
+
/**
|
|
61
|
+
* Checks whether the user is currently authenticated, optionally triggering a token refresh.
|
|
62
|
+
*/
|
|
63
|
+
checkAuthentication: Flow['checkAuthentication'];
|
|
64
|
+
/**
|
|
65
|
+
* Initializes the SDK, loading metadata and restoring any persisted session.
|
|
66
|
+
*/
|
|
67
|
+
init: Flow['init'];
|
|
68
|
+
/**
|
|
69
|
+
* Performs a token exchange using the provided parameters.
|
|
70
|
+
*/
|
|
71
|
+
tokenExchange: Flow['tokenExchange'];
|
|
72
|
+
/**
|
|
73
|
+
* Handles the authentication callback by parsing the response from the given URL.
|
|
74
|
+
*/
|
|
75
|
+
handleCallback: Flow['handleCallback'];
|
|
76
|
+
/**
|
|
77
|
+
* Refreshes the current access token using the refresh token.
|
|
78
|
+
*/
|
|
79
|
+
refresh: Flow['refresh'];
|
|
80
|
+
/**
|
|
81
|
+
* Revokes the current tokens.
|
|
82
|
+
*/
|
|
83
|
+
revoke: Flow['revoke'];
|
|
84
|
+
/**
|
|
85
|
+
* Logs the user out and optionally redirects to a post-logout URI.
|
|
86
|
+
*/
|
|
87
|
+
logout: Flow['logout'];
|
|
88
|
+
/**
|
|
89
|
+
* Initiates the login flow.
|
|
90
|
+
*/
|
|
91
|
+
login: Flow['login'];
|
|
92
|
+
/**
|
|
93
|
+
* Initiates the registration flow.
|
|
94
|
+
*/
|
|
95
|
+
register: Flow['register'];
|
|
96
|
+
/**
|
|
97
|
+
* Handles the entry point URL of the authentication flow, typically used for embedded or native modes.
|
|
98
|
+
*/
|
|
99
|
+
entry: Flow['entry'];
|
|
100
|
+
};
|
|
101
|
+
export type SDKInstance = ReturnType<typeof initFlow>;
|
|
102
|
+
export type LoginContext = {
|
|
103
|
+
/**
|
|
104
|
+
* Whether a form submission or session initialization is in progress.
|
|
105
|
+
*/
|
|
106
|
+
loading: Ref<boolean>;
|
|
107
|
+
/**
|
|
108
|
+
* Current form field values, keyed by form ID then widget ID.
|
|
109
|
+
*/
|
|
110
|
+
forms: Ref<Record<string, Record<string, unknown>>>;
|
|
111
|
+
/**
|
|
112
|
+
* Current validation and info messages, keyed by form ID then widget ID.
|
|
113
|
+
*/
|
|
114
|
+
messages: Ref<Record<string, Record<string, NativeFlowMessage>>>;
|
|
115
|
+
/**
|
|
116
|
+
* The current login flow state returned by the backend.
|
|
117
|
+
*/
|
|
118
|
+
state: Ref<Partial<NativeFlowState>>;
|
|
119
|
+
/**
|
|
120
|
+
* Submits the form with the given ID and advances the login flow.
|
|
121
|
+
*
|
|
122
|
+
* @param formId - The ID of the form to submit.
|
|
123
|
+
* @param customBody - Optional custom body to send with the form submission. If not provided, the current form values will be used.
|
|
124
|
+
* @returns A promise that resolves when the form submission is complete.
|
|
125
|
+
*/
|
|
126
|
+
submitForm: (formId: string, customBody?: Record<string, unknown>) => Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Redirects to the hosted login UI.
|
|
129
|
+
*
|
|
130
|
+
* @param message - Optional message to log before redirecting.
|
|
131
|
+
* @returns A promise that resolves when the redirect is initiated.
|
|
132
|
+
*/
|
|
133
|
+
triggerFallback: (message?: string) => void;
|
|
134
|
+
/**
|
|
135
|
+
* Signals that the login flow was closed by the user.
|
|
136
|
+
*/
|
|
137
|
+
triggerClose: () => void;
|
|
138
|
+
/**
|
|
139
|
+
* Updates a single field value within a form before submission.
|
|
140
|
+
*
|
|
141
|
+
* @param formId - The ID of the form containing the field.
|
|
142
|
+
* @param widgetId - The ID of the widget (field) to update.
|
|
143
|
+
* @param value - The new value to set for the field.
|
|
144
|
+
*/
|
|
145
|
+
setFormValue: (formId: string, widgetId: string, value: unknown) => void;
|
|
146
|
+
/**
|
|
147
|
+
* Sets a validation or info message on a specific widget.
|
|
148
|
+
*
|
|
149
|
+
* @param formId - The ID of the form containing the widget.
|
|
150
|
+
* @param widgetId - The ID of the widget to set the message for.
|
|
151
|
+
* @param value - The message to set, which can be a string or a structured NativeFlowMessage.
|
|
152
|
+
*/
|
|
153
|
+
setMessage: (formId: string, widgetId: string, value: NativeFlowMessage) => void;
|
|
154
|
+
};
|
|
155
|
+
export type UseNativeLoginOptions = {
|
|
156
|
+
/**
|
|
157
|
+
* Optional parameters to be passed to the login session request. These parameters will be sent to the `authorizationUri` endpoint.
|
|
158
|
+
*/
|
|
159
|
+
params?: NativeParams;
|
|
160
|
+
/**
|
|
161
|
+
* A render function called when the user successfully completes the login flow.
|
|
162
|
+
* This can be used to perform any necessary actions after a successful login, such as redirecting the user or updating the application state. Defaults to `null`.
|
|
163
|
+
*/
|
|
164
|
+
onLogin?: (session: SessionData) => void | Promise<void>;
|
|
165
|
+
/**
|
|
166
|
+
* Called when the fallback flow is triggered, typically due to an error or unsupported environment. Receives a `FallbackError` object containing the hosted URL to redirect to.
|
|
167
|
+
*/
|
|
168
|
+
onFallback?: (error: FallbackError) => void | Promise<void>;
|
|
169
|
+
/**
|
|
170
|
+
* Called when the login flow is closed by the user. This can be used to perform any necessary cleanup or state updates in the application. Defaults to `null`.
|
|
171
|
+
*/
|
|
172
|
+
onClose?: () => void | Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Called when an error occurs during the login session initialization or flow. Receives an `Error` object describing the issue.
|
|
175
|
+
*/
|
|
176
|
+
onError?: (error: Error) => void | Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Called when a global message is received during the login flow. This can be used to display messages to the user or log them for debugging purposes.
|
|
179
|
+
*/
|
|
180
|
+
onGlobalMessage?: (message: NativeFlowMessage) => void | Promise<void>;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Extends the base SDKStorage interface with optional back-channel logout support.
|
|
184
|
+
*/
|
|
185
|
+
export type NuxtServerStorage = SDKStorage<[
|
|
186
|
+
event?: H3Event
|
|
187
|
+
], [
|
|
188
|
+
event?: H3Event,
|
|
189
|
+
cookieOptions?: CookieOptions
|
|
190
|
+
], [
|
|
191
|
+
event?: H3Event,
|
|
192
|
+
cookieOptions?: CookieOptions
|
|
193
|
+
]> & {
|
|
194
|
+
deleteByLogoutToken?(token: LogoutTokenClaims): Promise<void>;
|
|
195
|
+
};
|
|
196
|
+
export type NuxtServerSDKOptions<Storage extends NuxtServerStorage = NuxtServerStorage, StateStorage extends SDKStorage = SDKStorage> = ServerSDKOptions<Storage, StateStorage>;
|
|
197
|
+
export type NuxtServerSDKInitConfig = ServerSDKInitConfig & Partial<Omit<NuxtServerSDKOptions, 'storage' | 'stateStorage' | 'logging' | 'httpClient'>> & {
|
|
198
|
+
/**
|
|
199
|
+
* Optional path to a custom storage factory module.
|
|
200
|
+
* The factory should export a function that returns an object implementing the SDKStorage interface.
|
|
201
|
+
*/
|
|
202
|
+
storageFactoryPath?: string;
|
|
203
|
+
/**
|
|
204
|
+
* Optional path to a custom state storage factory module.
|
|
205
|
+
* The factory should export a function that returns an object implementing the SDKStorage interface.
|
|
206
|
+
*/
|
|
207
|
+
stateStorageFactoryPath?: string;
|
|
208
|
+
/**
|
|
209
|
+
* Optional path to a custom logging factory module.
|
|
210
|
+
* The factory should export a function that returns an object implementing the SDKLogging interface.
|
|
211
|
+
*/
|
|
212
|
+
loggingFactoryPath?: string;
|
|
213
|
+
/**
|
|
214
|
+
* Optional path to a custom HTTP client factory module.
|
|
215
|
+
* The factory should export a function that returns an object implementing the SDKHttpClient interface.
|
|
216
|
+
*/
|
|
217
|
+
httpClientFactoryPath?: string;
|
|
218
|
+
};
|
|
219
|
+
export type NuxtServerSDK<TEvent extends H3Event = H3Event> = BaseServerSDK<TEvent>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@strivacity/sdk-core/types";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FallbackError, PopupBlockedError, PopupClosedError, UnsupportedFlowError, SessionExpiredError, NetworkError, ServerError, OidcError, ProtocolError, ConfigurationError, InternalError, throwTokenEndpointError, throwHttpError, assertWebAuthnCredential, buildAuthorizationUrl, buildCookieString, buildEndSessionUrl, createDefaultLogging, createHttpClient, createSession, createState, createWebAuthnCredential, decodeBase64URL, decodeJwt, decryptString, defaultOptions, encodeBase64URL, encryptString, exchangeCode, fetchFlowEntry, finalizeLoginSession, generateCodeChallenge, generateCodeVerifier, generateJwt, generateRandomHex, getDefaultFlowState, getDiscoveryDocument, getSDKOptions, getServerSDKOptions, injectScript, isSessionExpired, loadSession, parseCookieHeader, parseState, proxyResponse, pushSetCookie, flushSetCookies, refreshToken, revokeToken, serializeCookie, serializeSession, serializeState, submitLoginForm, timestamp, toSafeRedirect, unflattenObject, verifyIdToken, verifyJwt, DISALLOWED_PROXY_HEADERS, RETURN_TO_COOKIE, BACKCHANNEL_LOGOUT_EVENT, DEFAULT_COOKIE_MAX_AGE, } from '@strivacity/sdk-core/utils';
|