nuxt-auth-utils 0.5.33 → 0.6.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/README.md +91 -16
- package/dist/module.d.mts +3 -3
- package/dist/module.json +5 -2
- package/dist/module.mjs +28 -31
- package/dist/runtime/app/components/AuthState.d.vue.ts +20 -0
- package/dist/runtime/app/composables/session.js +3 -2
- package/dist/runtime/server/api/session.delete.d.ts +1 -1
- package/dist/runtime/server/api/session.delete.js +2 -2
- package/dist/runtime/server/api/session.get.d.ts +1 -1
- package/dist/runtime/server/api/session.get.js +2 -2
- package/dist/runtime/server/lib/atproto/bluesky.d.ts +3 -3
- package/dist/runtime/server/lib/atproto/bluesky.js +6 -6
- package/dist/runtime/server/lib/oauth/apple.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/apple.js +3 -4
- package/dist/runtime/server/lib/oauth/atlassian.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/atlassian.js +8 -8
- package/dist/runtime/server/lib/oauth/auth0.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/auth0.js +4 -4
- package/dist/runtime/server/lib/oauth/authentik.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/authentik.js +6 -6
- package/dist/runtime/server/lib/oauth/azureb2c.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/azureb2c.js +5 -5
- package/dist/runtime/server/lib/oauth/battledotnet.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/battledotnet.js +6 -6
- package/dist/runtime/server/lib/oauth/box.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/box.js +5 -5
- package/dist/runtime/server/lib/oauth/cloudflare.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/cloudflare.js +5 -5
- package/dist/runtime/server/lib/oauth/cognito.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/cognito.js +4 -4
- package/dist/runtime/server/lib/oauth/discord.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/discord.js +4 -4
- package/dist/runtime/server/lib/oauth/dropbox.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/dropbox.js +5 -5
- package/dist/runtime/server/lib/oauth/facebook.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/facebook.js +7 -7
- package/dist/runtime/server/lib/oauth/gitea.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/gitea.js +5 -5
- package/dist/runtime/server/lib/oauth/github.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/github.js +6 -6
- package/dist/runtime/server/lib/oauth/gitlab.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/gitlab.js +5 -5
- package/dist/runtime/server/lib/oauth/google.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/google.js +4 -4
- package/dist/runtime/server/lib/oauth/heroku.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/heroku.js +5 -5
- package/dist/runtime/server/lib/oauth/hubspot.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/hubspot.js +4 -4
- package/dist/runtime/server/lib/oauth/instagram.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/instagram.js +6 -6
- package/dist/runtime/server/lib/oauth/keycloak.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/keycloak.js +6 -6
- package/dist/runtime/server/lib/oauth/kick.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/kick.js +5 -5
- package/dist/runtime/server/lib/oauth/line.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/line.js +6 -6
- package/dist/runtime/server/lib/oauth/linear.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/linear.js +6 -6
- package/dist/runtime/server/lib/oauth/linkedin.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/linkedin.js +4 -4
- package/dist/runtime/server/lib/oauth/livechat.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/livechat.js +4 -4
- package/dist/runtime/server/lib/oauth/mastodon.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/mastodon.js +8 -9
- package/dist/runtime/server/lib/oauth/microsoft.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/microsoft.js +5 -5
- package/dist/runtime/server/lib/oauth/oidc.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/oidc.js +6 -6
- package/dist/runtime/server/lib/oauth/okta.d.ts +4 -4
- package/dist/runtime/server/lib/oauth/okta.js +9 -9
- package/dist/runtime/server/lib/oauth/ory.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/ory.js +6 -6
- package/dist/runtime/server/lib/oauth/osu.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/osu.js +4 -4
- package/dist/runtime/server/lib/oauth/paypal.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/paypal.js +5 -5
- package/dist/runtime/server/lib/oauth/polar.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/polar.js +5 -5
- package/dist/runtime/server/lib/oauth/riotgames.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/riotgames.js +5 -5
- package/dist/runtime/server/lib/oauth/roblox.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/roblox.js +4 -4
- package/dist/runtime/server/lib/oauth/salesforce.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/salesforce.js +5 -5
- package/dist/runtime/server/lib/oauth/seznam.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/seznam.js +4 -4
- package/dist/runtime/server/lib/oauth/shopifyCustomer.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/shopifyCustomer.js +7 -7
- package/dist/runtime/server/lib/oauth/slack.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/slack.js +5 -5
- package/dist/runtime/server/lib/oauth/spotify.d.ts +49 -2
- package/dist/runtime/server/lib/oauth/spotify.js +4 -4
- package/dist/runtime/server/lib/oauth/steam.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/steam.js +7 -7
- package/dist/runtime/server/lib/oauth/strava.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/strava.js +5 -5
- package/dist/runtime/server/lib/oauth/tiktok.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/tiktok.js +5 -5
- package/dist/runtime/server/lib/oauth/twitch.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/twitch.js +5 -5
- package/dist/runtime/server/lib/oauth/vk.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/vk.js +5 -5
- package/dist/runtime/server/lib/oauth/wechat.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/wechat.js +7 -7
- package/dist/runtime/server/lib/oauth/workos.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/workos.js +3 -4
- package/dist/runtime/server/lib/oauth/x.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/x.js +4 -4
- package/dist/runtime/server/lib/oauth/xsuaa.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/xsuaa.js +4 -4
- package/dist/runtime/server/lib/oauth/yandex.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/yandex.js +4 -4
- package/dist/runtime/server/lib/oauth/zendesk.d.ts +110 -0
- package/dist/runtime/server/lib/oauth/zendesk.js +109 -0
- package/dist/runtime/server/lib/oauth/zitadel.d.ts +1 -1
- package/dist/runtime/server/lib/oauth/zitadel.js +6 -6
- package/dist/runtime/server/lib/utils.d.ts +8 -8
- package/dist/runtime/server/lib/utils.js +5 -7
- package/dist/runtime/server/lib/webauthn/authenticate.d.ts +1 -1
- package/dist/runtime/server/lib/webauthn/authenticate.js +7 -8
- package/dist/runtime/server/lib/webauthn/register.d.ts +2 -2
- package/dist/runtime/server/lib/webauthn/register.js +9 -10
- package/dist/runtime/server/plugins/oauth-hash.d.ts +2 -0
- package/dist/runtime/server/plugins/oauth-hash.js +8 -0
- package/dist/runtime/server/routes/atproto/client-metadata.json.get.d.ts +1 -1
- package/dist/runtime/server/routes/atproto/client-metadata.json.get.js +5 -5
- package/dist/runtime/server/utils/atproto.d.ts +2 -2
- package/dist/runtime/server/utils/atproto.js +2 -3
- package/dist/runtime/server/utils/password.js +1 -1
- package/dist/runtime/server/utils/session.d.ts +29 -16
- package/dist/runtime/server/utils/session.js +72 -29
- package/dist/runtime/types/event.d.ts +27 -3
- package/dist/runtime/types/index.d.ts +1 -1
- package/dist/runtime/types/oauth-config.d.ts +4 -4
- package/dist/runtime/types/webauthn.d.ts +14 -15
- package/package.json +12 -9
- package/dist/runtime/server/plugins/oauth.d.ts +0 -2
- package/dist/runtime/server/plugins/oauth.js +0 -16
- package/dist/runtime/server/plugins/ws.d.ts +0 -2
- package/dist/runtime/server/plugins/ws.js +0 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createError, defineEventHandler, useRuntimeConfig, useSession } from "nuxt/server";
|
|
2
2
|
import { defu } from "defu";
|
|
3
3
|
import { createHooks } from "hookable";
|
|
4
|
-
|
|
4
|
+
export const USER_SESSION_COOKIE_NAME = "nuxt-auth-session";
|
|
5
5
|
export const sessionHooks = createHooks();
|
|
6
6
|
export async function getUserSession(event) {
|
|
7
7
|
const session = await _useSession(event);
|
|
@@ -11,53 +11,96 @@ export async function getUserSession(event) {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
export async function setUserSession(event, data, config) {
|
|
14
|
-
const session = await _useSession(event, config);
|
|
15
|
-
await session.update(defu(data, session.data));
|
|
14
|
+
const session = await _useSession(event, config, true);
|
|
15
|
+
await session.update(defu(toJSONData(data), session.data));
|
|
16
16
|
return session.data;
|
|
17
17
|
}
|
|
18
18
|
export async function replaceUserSession(event, data, config) {
|
|
19
|
-
const session = await _useSession(event, config);
|
|
20
|
-
await session.clear();
|
|
19
|
+
const session = await _useSession(event, config, true);
|
|
21
20
|
await session.update((oldData) => {
|
|
22
21
|
for (const key of Object.keys(oldData)) {
|
|
23
22
|
Reflect.deleteProperty(oldData, key);
|
|
24
23
|
}
|
|
25
|
-
return data;
|
|
24
|
+
return toJSONData(data);
|
|
26
25
|
});
|
|
27
26
|
return session.data;
|
|
28
27
|
}
|
|
29
28
|
export async function clearUserSession(event, config) {
|
|
30
|
-
const session = await _useSession(event, config);
|
|
31
|
-
await sessionHooks.callHookParallel("clear", session.data, event);
|
|
29
|
+
const session = await _useSession(event, config, true);
|
|
30
|
+
await sessionHooks.callHookParallel("clear", session.data, toSessionEvent(event).event);
|
|
32
31
|
await session.clear();
|
|
33
32
|
return true;
|
|
34
33
|
}
|
|
35
34
|
export async function requireUserSession(event, opts = {}) {
|
|
36
35
|
const userSession = await getUserSession(event);
|
|
37
36
|
if (!userSession.user) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
} else {
|
|
44
|
-
throw new Response(opts.message || "Unauthorized", {
|
|
45
|
-
status: opts.statusCode || 401
|
|
46
|
-
});
|
|
37
|
+
const status = opts.status || opts.statusCode || 401;
|
|
38
|
+
const message = opts.message || "Unauthorized";
|
|
39
|
+
if (toSessionEvent(event).webSocket) {
|
|
40
|
+
throw new Response(message, { status });
|
|
47
41
|
}
|
|
42
|
+
throw createError({ status, message });
|
|
48
43
|
}
|
|
49
44
|
return userSession;
|
|
50
45
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
46
|
+
async function _useSession(event, config = {}, write = false) {
|
|
47
|
+
const { event: sessionEvent, webSocket } = toSessionEvent(event);
|
|
48
|
+
if (write && webSocket) {
|
|
49
|
+
throw createError({
|
|
50
|
+
status: 500,
|
|
51
|
+
message: "[nuxt-auth-utils] The user session is read-only in WebSocket handlers: `setUserSession`, `replaceUserSession` and `clearUserSession` need the event of an HTTP request."
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const runtimeConfig = useRuntimeConfig();
|
|
55
|
+
warnLegacySessionPassword(runtimeConfig);
|
|
56
|
+
const { password: _password, ...finalConfig } = defu(config, runtimeConfig.session, { name: USER_SESSION_COOKIE_NAME });
|
|
57
|
+
if (finalConfig.name === APP_SESSION_COOKIE_NAME) {
|
|
58
|
+
warnAppSessionName();
|
|
59
|
+
finalConfig.name = USER_SESSION_COOKIE_NAME;
|
|
60
|
+
}
|
|
61
|
+
return useSession(sessionEvent, finalConfig);
|
|
62
|
+
}
|
|
63
|
+
function toJSONData(data) {
|
|
64
|
+
return JSON.parse(JSON.stringify(data));
|
|
65
|
+
}
|
|
66
|
+
const APP_SESSION_COOKIE_NAME = "nuxt-session";
|
|
67
|
+
let warnedAppSessionName = false;
|
|
68
|
+
function warnAppSessionName() {
|
|
69
|
+
if (warnedAppSessionName) return;
|
|
70
|
+
warnedAppSessionName = true;
|
|
71
|
+
console.warn(`[nuxt-auth-utils] The session name \`${APP_SESSION_COOKIE_NAME}\` is the cookie of \`useSession()\` from \`nuxt/server\`, using \`${USER_SESSION_COOKIE_NAME}\` instead. Set another \`runtimeConfig.session.name\` (\`NUXT_SESSION_NAME\`) to rename the user session cookie.`);
|
|
72
|
+
}
|
|
73
|
+
const toPortableEvent = defineEventHandler((event) => event);
|
|
74
|
+
function toSessionEvent(event) {
|
|
75
|
+
const input = event;
|
|
76
|
+
if (input["~portable"] === true || typeof input.res?.headers?.append === "function") {
|
|
77
|
+
return { event: input, webSocket: false };
|
|
78
|
+
}
|
|
79
|
+
if (input.node?.req) {
|
|
80
|
+
return { event: toPortableEvent(input), webSocket: false };
|
|
81
|
+
}
|
|
82
|
+
const headers = input.request?.headers || input.headers;
|
|
83
|
+
if (headers && typeof headers.get === "function") {
|
|
84
|
+
return {
|
|
85
|
+
event: {
|
|
86
|
+
req: { headers },
|
|
87
|
+
res: { status: 200, statusText: "", headers: new Headers() }
|
|
88
|
+
},
|
|
89
|
+
webSocket: true
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
throw createError({
|
|
93
|
+
status: 500,
|
|
94
|
+
message: "[nuxt-auth-utils] The session utils need a request event, a WebSocket peer or a WebSocket upgrade request."
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
let checkedLegacySessionPassword = false;
|
|
98
|
+
function warnLegacySessionPassword(runtimeConfig) {
|
|
99
|
+
if (checkedLegacySessionPassword) return;
|
|
100
|
+
checkedLegacySessionPassword = true;
|
|
101
|
+
const envPrefix = runtimeConfig.nitro?.envPrefix || "NUXT_";
|
|
102
|
+
const envKey = `${envPrefix}SESSION_PASSWORD`;
|
|
103
|
+
if (globalThis.process?.env?.[envKey] || runtimeConfig.session?.password) {
|
|
104
|
+
console.warn(`[nuxt-auth-utils] \`${envKey}\` (\`runtimeConfig.session.password\`) is not used anymore. Set \`NUXT_APP_SECRET\` instead, for example with \`openssl rand -base64 32\`. Sessions are now sealed with a secret derived from \`appSecret\`.`);
|
|
60
105
|
}
|
|
61
|
-
const finalConfig = defu(config, sessionConfig);
|
|
62
|
-
return useSession(event, finalConfig);
|
|
63
106
|
}
|
|
@@ -1,4 +1,28 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { RequestEvent } from 'nuxt/server';
|
|
2
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
3
|
export type { RequestEvent };
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The h3 v1 event a handler defined with `defineEventHandler` from `h3` (or its auto-import) receives on Nuxt 4.
|
|
6
|
+
* @deprecated Use `defineEventHandler` from `nuxt/server`. Removed with Nuxt 5 support.
|
|
7
|
+
*/
|
|
8
|
+
export interface LegacyH3Event {
|
|
9
|
+
node: {
|
|
10
|
+
req: IncomingMessage;
|
|
11
|
+
res: ServerResponse;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A WebSocket peer or upgrade request, from `defineWebSocketHandler`.
|
|
16
|
+
* The session is read-only: changes are not sent back to the client.
|
|
17
|
+
*/
|
|
18
|
+
export type WebSocketSessionEvent = {
|
|
19
|
+
request: {
|
|
20
|
+
headers: Headers;
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
headers: Headers;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Any event the session utils accept.
|
|
27
|
+
*/
|
|
28
|
+
export type SessionEvent = RequestEvent | LegacyH3Event | WebSocketSessionEvent;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { User, UserSession, UserSessionRequired, UserSessionComposable, SecureSessionData } from './session.js';
|
|
2
|
-
export type { RequestEvent, SessionEvent } from './event.js';
|
|
2
|
+
export type { RequestEvent, SessionEvent, LegacyH3Event, WebSocketSessionEvent } from './event.js';
|
|
3
3
|
export type { OAuthConfig, OAuthProvider, ATProtoProvider, OnError } from './oauth-config.js';
|
|
4
4
|
export type { WebAuthnCredential, WebAuthnRegisterEventHandlerOptions, WebAuthnAuthenticateEventHandlerOptions, WebAuthnComposable, WebAuthnUser, } from './webauthn.js';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NuxtError, RequestEvent } from 'nuxt/server';
|
|
2
2
|
export type ATProtoProvider = 'bluesky';
|
|
3
|
-
export type OAuthProvider = ATProtoProvider | 'atlassian' | 'auth0' | 'authentik' | 'azureb2c' | 'battledotnet' | 'cloudflare' | 'cognito' | 'discord' | 'dropbox' | 'facebook' | 'gitea' | 'github' | 'gitlab' | 'google' | 'hubspot' | 'instagram' | 'kick' | 'keycloak' | 'line' | 'linear' | 'linkedin' | 'mastodon' | 'microsoft' | 'paypal' | 'polar' | 'spotify' | 'seznam' | 'steam' | 'strava' | 'tiktok' | 'twitch' | 'vk' | 'wechat' | 'workos' | 'x' | 'xsuaa' | 'yandex' | 'zitadel' | 'apple' | 'livechat' | 'salesforce' | 'slack' | 'heroku' | 'roblox' | 'okta' | 'ory' | 'shopifyCustomer' | 'oidc' | 'osu' | 'riotgames' | 'box' | (string & {});
|
|
4
|
-
export type OnError = (event:
|
|
3
|
+
export type OAuthProvider = ATProtoProvider | 'atlassian' | 'auth0' | 'authentik' | 'azureb2c' | 'battledotnet' | 'cloudflare' | 'cognito' | 'discord' | 'dropbox' | 'facebook' | 'gitea' | 'github' | 'gitlab' | 'google' | 'hubspot' | 'instagram' | 'kick' | 'keycloak' | 'line' | 'linear' | 'linkedin' | 'mastodon' | 'microsoft' | 'paypal' | 'polar' | 'spotify' | 'seznam' | 'steam' | 'strava' | 'tiktok' | 'twitch' | 'vk' | 'wechat' | 'workos' | 'x' | 'xsuaa' | 'yandex' | 'zitadel' | 'apple' | 'livechat' | 'salesforce' | 'slack' | 'heroku' | 'roblox' | 'okta' | 'ory' | 'shopifyCustomer' | 'oidc' | 'osu' | 'riotgames' | 'box' | 'zendesk' | (string & {});
|
|
4
|
+
export type OnError = (event: RequestEvent, error: NuxtError) => unknown;
|
|
5
5
|
export interface OAuthConfig<TConfig, TResult = {
|
|
6
6
|
user: any;
|
|
7
7
|
tokens: any;
|
|
8
8
|
}> {
|
|
9
9
|
config?: TConfig;
|
|
10
|
-
onSuccess: (event:
|
|
10
|
+
onSuccess: (event: RequestEvent, result: TResult) => unknown;
|
|
11
11
|
onError?: OnError;
|
|
12
12
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { AuthenticationResponseJSON, AuthenticatorTransportFuture, RegistrationResponseJSON } from '@simplewebauthn/types';
|
|
2
1
|
import type { Ref } from 'vue';
|
|
3
|
-
import type {
|
|
4
|
-
import type { GenerateAuthenticationOptionsOpts, GenerateRegistrationOptionsOpts, VerifiedAuthenticationResponse, VerifiedRegistrationResponse } from '@simplewebauthn/server';
|
|
2
|
+
import type { NuxtError, RequestEvent, ValidateResult } from 'nuxt/server';
|
|
3
|
+
import type { AuthenticationResponseJSON, AuthenticatorTransportFuture, GenerateAuthenticationOptionsOpts, GenerateRegistrationOptionsOpts, RegistrationResponseJSON, VerifiedAuthenticationResponse, VerifiedRegistrationResponse } from '@simplewebauthn/server';
|
|
5
4
|
export interface WebAuthnCredential {
|
|
6
5
|
id: string;
|
|
7
6
|
publicKey: string;
|
|
@@ -18,15 +17,15 @@ export interface WebAuthnUser {
|
|
|
18
17
|
}
|
|
19
18
|
type CredentialsList = NonNullable<GenerateAuthenticationOptionsOpts['allowCredentials']>;
|
|
20
19
|
type WebAuthnEventHandlerBase<T extends Record<PropertyKey, unknown>> = {
|
|
21
|
-
storeChallenge: (event:
|
|
22
|
-
getChallenge: (event:
|
|
23
|
-
onSuccess: (event:
|
|
24
|
-
onError?: (event:
|
|
20
|
+
storeChallenge: (event: RequestEvent, challenge: string, attemptId: string) => void | Promise<void>;
|
|
21
|
+
getChallenge: (event: RequestEvent, attemptId: string) => string | Promise<string>;
|
|
22
|
+
onSuccess: (event: RequestEvent, data: T) => unknown;
|
|
23
|
+
onError?: (event: RequestEvent, error: NuxtError) => unknown;
|
|
25
24
|
} | {
|
|
26
25
|
storeChallenge?: undefined;
|
|
27
26
|
getChallenge?: undefined;
|
|
28
|
-
onSuccess: (event:
|
|
29
|
-
onError?: (event:
|
|
27
|
+
onSuccess: (event: RequestEvent, data: T) => unknown;
|
|
28
|
+
onError?: (event: RequestEvent, error: NuxtError) => unknown;
|
|
30
29
|
};
|
|
31
30
|
export type RegistrationBody<T extends WebAuthnUser> = {
|
|
32
31
|
user: T;
|
|
@@ -37,15 +36,15 @@ export type RegistrationBody<T extends WebAuthnUser> = {
|
|
|
37
36
|
attemptId: string;
|
|
38
37
|
response: RegistrationResponseJSON;
|
|
39
38
|
};
|
|
40
|
-
export type ValidateUserFunction<T> = (userBody: WebAuthnUser, event:
|
|
39
|
+
export type ValidateUserFunction<T> = (userBody: WebAuthnUser, event: RequestEvent) => ValidateResult<T> | Promise<ValidateResult<T>>;
|
|
41
40
|
export type WebAuthnRegisterEventHandlerOptions<T extends WebAuthnUser> = WebAuthnEventHandlerBase<{
|
|
42
41
|
user: T;
|
|
43
42
|
credential: WebAuthnCredential;
|
|
44
43
|
registrationInfo: Exclude<VerifiedRegistrationResponse['registrationInfo'], undefined>;
|
|
45
44
|
}> & {
|
|
46
|
-
getOptions?: (event:
|
|
45
|
+
getOptions?: (event: RequestEvent, body: RegistrationBody<T>) => Partial<GenerateRegistrationOptionsOpts> | Promise<Partial<GenerateRegistrationOptionsOpts>>;
|
|
47
46
|
validateUser?: ValidateUserFunction<T>;
|
|
48
|
-
excludeCredentials?: (event:
|
|
47
|
+
excludeCredentials?: (event: RequestEvent, userName: string) => CredentialsList | Promise<CredentialsList>;
|
|
49
48
|
};
|
|
50
49
|
export type AuthenticationBody = {
|
|
51
50
|
verify: false;
|
|
@@ -60,9 +59,9 @@ export type WebAuthnAuthenticateEventHandlerOptions<T extends WebAuthnCredential
|
|
|
60
59
|
credential: T;
|
|
61
60
|
authenticationInfo: Exclude<VerifiedAuthenticationResponse['authenticationInfo'], undefined>;
|
|
62
61
|
}> & {
|
|
63
|
-
getOptions?: (event:
|
|
64
|
-
getCredential: (event:
|
|
65
|
-
allowCredentials?: (event:
|
|
62
|
+
getOptions?: (event: RequestEvent, body: AuthenticationBody) => Partial<GenerateAuthenticationOptionsOpts> | Promise<Partial<GenerateAuthenticationOptionsOpts>>;
|
|
63
|
+
getCredential: (event: RequestEvent, credentialID: string) => T | Promise<T>;
|
|
64
|
+
allowCredentials?: (event: RequestEvent, userName: string) => CredentialsList | Promise<CredentialsList>;
|
|
66
65
|
};
|
|
67
66
|
export interface WebAuthnComposable {
|
|
68
67
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-auth-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Add Authentication to Nuxt applications with secured & sealed cookies sessions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,25 +25,27 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"dist"
|
|
27
27
|
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": "^22.22.3 || ^24.15.0 || >=26.0.0"
|
|
30
|
+
},
|
|
28
31
|
"dependencies": {
|
|
29
32
|
"@adonisjs/hash": "^9.1.1",
|
|
30
|
-
"@nuxt/kit": "^4.
|
|
33
|
+
"@nuxt/kit": "^4.6.0",
|
|
31
34
|
"@nuxt/schema": "^4.6.0",
|
|
32
|
-
"defu": "^6.1.
|
|
33
|
-
"h3": "^1.15.4",
|
|
35
|
+
"defu": "^6.1.5",
|
|
34
36
|
"hookable": "^6.0.1",
|
|
35
37
|
"jose": "^6.1.3",
|
|
36
38
|
"ofetch": "^1.5.1",
|
|
37
39
|
"openid-client": "^6.8.2",
|
|
38
|
-
"pathe": "^2.0.3",
|
|
39
40
|
"scule": "^1.3.0",
|
|
41
|
+
"ufo": "^1.6.4",
|
|
40
42
|
"uncrypto": "^0.1.3"
|
|
41
43
|
},
|
|
42
44
|
"peerDependencies": {
|
|
43
45
|
"@atproto/api": "^0.13.15",
|
|
44
46
|
"@atproto/oauth-client-node": "^0.2.0",
|
|
45
|
-
"@simplewebauthn/browser": "^
|
|
46
|
-
"@simplewebauthn/server": "^
|
|
47
|
+
"@simplewebauthn/browser": "^13.0.0",
|
|
48
|
+
"@simplewebauthn/server": "^13.3.2"
|
|
47
49
|
},
|
|
48
50
|
"peerDependenciesMeta": {
|
|
49
51
|
"@simplewebauthn/browser": {
|
|
@@ -61,12 +63,11 @@
|
|
|
61
63
|
},
|
|
62
64
|
"devDependencies": {
|
|
63
65
|
"@iconify-json/simple-icons": "^1.2.71",
|
|
64
|
-
"@nuxt/devtools": "3.
|
|
66
|
+
"@nuxt/devtools": "3.4.4",
|
|
65
67
|
"@nuxt/eslint-config": "^1.15.1",
|
|
66
68
|
"@nuxt/module-builder": "^1.0.2",
|
|
67
69
|
"@nuxt/test-utils": "^4.0.0",
|
|
68
70
|
"@nuxt/ui": "^4.4.0",
|
|
69
|
-
"@simplewebauthn/types": "^12.0.0",
|
|
70
71
|
"@types/node": "latest",
|
|
71
72
|
"eslint": "^10.0.0",
|
|
72
73
|
"nuxt": "^4.6.0",
|
|
@@ -78,6 +79,8 @@
|
|
|
78
79
|
"dev": "nuxi dev playground",
|
|
79
80
|
"dev:build": "nuxi build playground",
|
|
80
81
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
82
|
+
"dev:v5": "pnpm install:nuxt5 && nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground && nuxi dev playground",
|
|
83
|
+
"install:nuxt5": "pnpm install --config.pnpmfile=scripts/nuxt-nightly.cjs --config.lockfile=false --config.minimum-release-age-exclude=*-nightly",
|
|
81
84
|
"lint": "eslint .",
|
|
82
85
|
"lint:fix": "eslint . --fix",
|
|
83
86
|
"test": "vitest run",
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { defineNitroPlugin } from "nitropack/runtime";
|
|
2
|
-
export default defineNitroPlugin((nitroApp) => {
|
|
3
|
-
if (process.env.NUXT_OAUTH_FACEBOOK_CLIENT_ID && process.env.NUXT_OAUTH_FACEBOOK_CLIENT_SECRET || process.env.NUXT_OAUTH_INSTAGRAM_CLIENT_ID && process.env.NUXT_OAUTH_INSTAGRAM_CLIENT_SECRET) {
|
|
4
|
-
nitroApp.hooks.hook("render:html", (html) => {
|
|
5
|
-
html.head.unshift(`
|
|
6
|
-
<script>
|
|
7
|
-
if (window.location.hash === "#_=_"){
|
|
8
|
-
history.replaceState
|
|
9
|
-
? history.replaceState(null, null, window.location.href.split("#")[0])
|
|
10
|
-
: window.location.hash = "";
|
|
11
|
-
}
|
|
12
|
-
<\/script>
|
|
13
|
-
`);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
});
|