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.
Files changed (140) hide show
  1. package/README.md +91 -16
  2. package/dist/module.d.mts +3 -3
  3. package/dist/module.json +5 -2
  4. package/dist/module.mjs +28 -31
  5. package/dist/runtime/app/components/AuthState.d.vue.ts +20 -0
  6. package/dist/runtime/app/composables/session.js +3 -2
  7. package/dist/runtime/server/api/session.delete.d.ts +1 -1
  8. package/dist/runtime/server/api/session.delete.js +2 -2
  9. package/dist/runtime/server/api/session.get.d.ts +1 -1
  10. package/dist/runtime/server/api/session.get.js +2 -2
  11. package/dist/runtime/server/lib/atproto/bluesky.d.ts +3 -3
  12. package/dist/runtime/server/lib/atproto/bluesky.js +6 -6
  13. package/dist/runtime/server/lib/oauth/apple.d.ts +1 -1
  14. package/dist/runtime/server/lib/oauth/apple.js +3 -4
  15. package/dist/runtime/server/lib/oauth/atlassian.d.ts +1 -1
  16. package/dist/runtime/server/lib/oauth/atlassian.js +8 -8
  17. package/dist/runtime/server/lib/oauth/auth0.d.ts +1 -1
  18. package/dist/runtime/server/lib/oauth/auth0.js +4 -4
  19. package/dist/runtime/server/lib/oauth/authentik.d.ts +1 -1
  20. package/dist/runtime/server/lib/oauth/authentik.js +6 -6
  21. package/dist/runtime/server/lib/oauth/azureb2c.d.ts +1 -1
  22. package/dist/runtime/server/lib/oauth/azureb2c.js +5 -5
  23. package/dist/runtime/server/lib/oauth/battledotnet.d.ts +1 -1
  24. package/dist/runtime/server/lib/oauth/battledotnet.js +6 -6
  25. package/dist/runtime/server/lib/oauth/box.d.ts +1 -1
  26. package/dist/runtime/server/lib/oauth/box.js +5 -5
  27. package/dist/runtime/server/lib/oauth/cloudflare.d.ts +1 -1
  28. package/dist/runtime/server/lib/oauth/cloudflare.js +5 -5
  29. package/dist/runtime/server/lib/oauth/cognito.d.ts +1 -1
  30. package/dist/runtime/server/lib/oauth/cognito.js +4 -4
  31. package/dist/runtime/server/lib/oauth/discord.d.ts +1 -1
  32. package/dist/runtime/server/lib/oauth/discord.js +4 -4
  33. package/dist/runtime/server/lib/oauth/dropbox.d.ts +1 -1
  34. package/dist/runtime/server/lib/oauth/dropbox.js +5 -5
  35. package/dist/runtime/server/lib/oauth/facebook.d.ts +1 -1
  36. package/dist/runtime/server/lib/oauth/facebook.js +7 -7
  37. package/dist/runtime/server/lib/oauth/gitea.d.ts +1 -1
  38. package/dist/runtime/server/lib/oauth/gitea.js +5 -5
  39. package/dist/runtime/server/lib/oauth/github.d.ts +1 -1
  40. package/dist/runtime/server/lib/oauth/github.js +6 -6
  41. package/dist/runtime/server/lib/oauth/gitlab.d.ts +1 -1
  42. package/dist/runtime/server/lib/oauth/gitlab.js +5 -5
  43. package/dist/runtime/server/lib/oauth/google.d.ts +1 -1
  44. package/dist/runtime/server/lib/oauth/google.js +4 -4
  45. package/dist/runtime/server/lib/oauth/heroku.d.ts +1 -1
  46. package/dist/runtime/server/lib/oauth/heroku.js +5 -5
  47. package/dist/runtime/server/lib/oauth/hubspot.d.ts +1 -1
  48. package/dist/runtime/server/lib/oauth/hubspot.js +4 -4
  49. package/dist/runtime/server/lib/oauth/instagram.d.ts +1 -1
  50. package/dist/runtime/server/lib/oauth/instagram.js +6 -6
  51. package/dist/runtime/server/lib/oauth/keycloak.d.ts +1 -1
  52. package/dist/runtime/server/lib/oauth/keycloak.js +6 -6
  53. package/dist/runtime/server/lib/oauth/kick.d.ts +1 -1
  54. package/dist/runtime/server/lib/oauth/kick.js +5 -5
  55. package/dist/runtime/server/lib/oauth/line.d.ts +1 -1
  56. package/dist/runtime/server/lib/oauth/line.js +6 -6
  57. package/dist/runtime/server/lib/oauth/linear.d.ts +1 -1
  58. package/dist/runtime/server/lib/oauth/linear.js +6 -6
  59. package/dist/runtime/server/lib/oauth/linkedin.d.ts +1 -1
  60. package/dist/runtime/server/lib/oauth/linkedin.js +4 -4
  61. package/dist/runtime/server/lib/oauth/livechat.d.ts +1 -1
  62. package/dist/runtime/server/lib/oauth/livechat.js +4 -4
  63. package/dist/runtime/server/lib/oauth/mastodon.d.ts +1 -1
  64. package/dist/runtime/server/lib/oauth/mastodon.js +8 -9
  65. package/dist/runtime/server/lib/oauth/microsoft.d.ts +1 -1
  66. package/dist/runtime/server/lib/oauth/microsoft.js +5 -5
  67. package/dist/runtime/server/lib/oauth/oidc.d.ts +1 -1
  68. package/dist/runtime/server/lib/oauth/oidc.js +6 -6
  69. package/dist/runtime/server/lib/oauth/okta.d.ts +4 -4
  70. package/dist/runtime/server/lib/oauth/okta.js +9 -9
  71. package/dist/runtime/server/lib/oauth/ory.d.ts +1 -1
  72. package/dist/runtime/server/lib/oauth/ory.js +6 -6
  73. package/dist/runtime/server/lib/oauth/osu.d.ts +1 -1
  74. package/dist/runtime/server/lib/oauth/osu.js +4 -4
  75. package/dist/runtime/server/lib/oauth/paypal.d.ts +1 -1
  76. package/dist/runtime/server/lib/oauth/paypal.js +5 -5
  77. package/dist/runtime/server/lib/oauth/polar.d.ts +1 -1
  78. package/dist/runtime/server/lib/oauth/polar.js +5 -5
  79. package/dist/runtime/server/lib/oauth/riotgames.d.ts +1 -1
  80. package/dist/runtime/server/lib/oauth/riotgames.js +5 -5
  81. package/dist/runtime/server/lib/oauth/roblox.d.ts +1 -1
  82. package/dist/runtime/server/lib/oauth/roblox.js +4 -4
  83. package/dist/runtime/server/lib/oauth/salesforce.d.ts +1 -1
  84. package/dist/runtime/server/lib/oauth/salesforce.js +5 -5
  85. package/dist/runtime/server/lib/oauth/seznam.d.ts +1 -1
  86. package/dist/runtime/server/lib/oauth/seznam.js +4 -4
  87. package/dist/runtime/server/lib/oauth/shopifyCustomer.d.ts +1 -1
  88. package/dist/runtime/server/lib/oauth/shopifyCustomer.js +7 -7
  89. package/dist/runtime/server/lib/oauth/slack.d.ts +1 -1
  90. package/dist/runtime/server/lib/oauth/slack.js +5 -5
  91. package/dist/runtime/server/lib/oauth/spotify.d.ts +49 -2
  92. package/dist/runtime/server/lib/oauth/spotify.js +4 -4
  93. package/dist/runtime/server/lib/oauth/steam.d.ts +1 -1
  94. package/dist/runtime/server/lib/oauth/steam.js +7 -7
  95. package/dist/runtime/server/lib/oauth/strava.d.ts +1 -1
  96. package/dist/runtime/server/lib/oauth/strava.js +5 -5
  97. package/dist/runtime/server/lib/oauth/tiktok.d.ts +1 -1
  98. package/dist/runtime/server/lib/oauth/tiktok.js +5 -5
  99. package/dist/runtime/server/lib/oauth/twitch.d.ts +1 -1
  100. package/dist/runtime/server/lib/oauth/twitch.js +5 -5
  101. package/dist/runtime/server/lib/oauth/vk.d.ts +1 -1
  102. package/dist/runtime/server/lib/oauth/vk.js +5 -5
  103. package/dist/runtime/server/lib/oauth/wechat.d.ts +1 -1
  104. package/dist/runtime/server/lib/oauth/wechat.js +7 -7
  105. package/dist/runtime/server/lib/oauth/workos.d.ts +1 -1
  106. package/dist/runtime/server/lib/oauth/workos.js +3 -4
  107. package/dist/runtime/server/lib/oauth/x.d.ts +1 -1
  108. package/dist/runtime/server/lib/oauth/x.js +4 -4
  109. package/dist/runtime/server/lib/oauth/xsuaa.d.ts +1 -1
  110. package/dist/runtime/server/lib/oauth/xsuaa.js +4 -4
  111. package/dist/runtime/server/lib/oauth/yandex.d.ts +1 -1
  112. package/dist/runtime/server/lib/oauth/yandex.js +4 -4
  113. package/dist/runtime/server/lib/oauth/zendesk.d.ts +110 -0
  114. package/dist/runtime/server/lib/oauth/zendesk.js +109 -0
  115. package/dist/runtime/server/lib/oauth/zitadel.d.ts +1 -1
  116. package/dist/runtime/server/lib/oauth/zitadel.js +6 -6
  117. package/dist/runtime/server/lib/utils.d.ts +8 -8
  118. package/dist/runtime/server/lib/utils.js +5 -7
  119. package/dist/runtime/server/lib/webauthn/authenticate.d.ts +1 -1
  120. package/dist/runtime/server/lib/webauthn/authenticate.js +7 -8
  121. package/dist/runtime/server/lib/webauthn/register.d.ts +2 -2
  122. package/dist/runtime/server/lib/webauthn/register.js +9 -10
  123. package/dist/runtime/server/plugins/oauth-hash.d.ts +2 -0
  124. package/dist/runtime/server/plugins/oauth-hash.js +8 -0
  125. package/dist/runtime/server/routes/atproto/client-metadata.json.get.d.ts +1 -1
  126. package/dist/runtime/server/routes/atproto/client-metadata.json.get.js +5 -5
  127. package/dist/runtime/server/utils/atproto.d.ts +2 -2
  128. package/dist/runtime/server/utils/atproto.js +2 -3
  129. package/dist/runtime/server/utils/password.js +1 -1
  130. package/dist/runtime/server/utils/session.d.ts +29 -16
  131. package/dist/runtime/server/utils/session.js +72 -29
  132. package/dist/runtime/types/event.d.ts +27 -3
  133. package/dist/runtime/types/index.d.ts +1 -1
  134. package/dist/runtime/types/oauth-config.d.ts +4 -4
  135. package/dist/runtime/types/webauthn.d.ts +14 -15
  136. package/package.json +12 -9
  137. package/dist/runtime/server/plugins/oauth.d.ts +0 -2
  138. package/dist/runtime/server/plugins/oauth.js +0 -16
  139. package/dist/runtime/server/plugins/ws.d.ts +0 -2
  140. package/dist/runtime/server/plugins/ws.js +0 -7
@@ -0,0 +1,110 @@
1
+ import type { OAuthConfig } from '#auth-utils';
2
+ export interface OAuthZendeskConfig {
3
+ /**
4
+ * Zendesk OAuth Client ID
5
+ * @default process.env.NUXT_OAUTH_ZENDESK_CLIENT_ID
6
+ */
7
+ clientId?: string;
8
+ /**
9
+ * Zendesk OAuth Client Secret
10
+ * @default process.env.NUXT_OAUTH_ZENDESK_CLIENT_SECRET
11
+ */
12
+ clientSecret?: string;
13
+ /**
14
+ * Zendesk subdomain, for example `mycompany` for `mycompany.zendesk.com`
15
+ * @default process.env.NUXT_OAUTH_ZENDESK_SUBDOMAIN
16
+ */
17
+ subdomain?: string;
18
+ /**
19
+ * Zendesk OAuth Scope
20
+ * @default ['read']
21
+ * @see https://support.zendesk.com/hc/en-us/articles/4408845965210-Using-OAuth-authentication-with-your-application
22
+ * @example ['read', 'write']
23
+ */
24
+ scope?: string[];
25
+ /**
26
+ * Redirect URL to allow overriding for situations like prod failing to determine public hostname
27
+ * @default process.env.NUXT_OAUTH_ZENDESK_REDIRECT_URL
28
+ */
29
+ redirectURL?: string;
30
+ /**
31
+ * Zendesk Marketplace name header value.
32
+ * Only required for apps published in the Zendesk Marketplace.
33
+ * @default process.env.NUXT_OAUTH_ZENDESK_MARKETPLACE_NAME
34
+ */
35
+ marketplaceName?: string;
36
+ /**
37
+ * Zendesk Marketplace organization ID header value.
38
+ * Only required for apps published in the Zendesk Marketplace.
39
+ * @default process.env.NUXT_OAUTH_ZENDESK_MARKETPLACE_ORG_ID
40
+ */
41
+ marketplaceOrgId?: string;
42
+ /**
43
+ * Zendesk Marketplace bot ID header value.
44
+ * Only required for marketplace bot integrations.
45
+ * @default process.env.NUXT_OAUTH_ZENDESK_MARKETPLACE_BOT_ID
46
+ */
47
+ marketplaceBotId?: string;
48
+ /**
49
+ * Zendesk Marketplace app ID header value.
50
+ * Only required for apps published in the Zendesk Marketplace.
51
+ * @default process.env.NUXT_OAUTH_ZENDESK_MARKETPLACE_APP_ID
52
+ */
53
+ marketplaceAppId?: string;
54
+ }
55
+ export interface ZendeskUser {
56
+ id: number;
57
+ url: string;
58
+ name: string;
59
+ email: string;
60
+ created_at: string;
61
+ updated_at: string;
62
+ time_zone: string | null;
63
+ iana_time_zone: string | null;
64
+ phone: string | null;
65
+ shared_phone_number: boolean | null;
66
+ photo: {
67
+ url: string | null;
68
+ content_url: string | null;
69
+ } | null;
70
+ locale_id: number;
71
+ locale: string;
72
+ organization_id: number | null;
73
+ role: string;
74
+ verified: boolean;
75
+ external_id: string | null;
76
+ tags: string[];
77
+ alias: string | null;
78
+ active: boolean;
79
+ shared: boolean;
80
+ shared_agent: boolean;
81
+ last_login_at: string | null;
82
+ two_factor_auth_enabled: boolean;
83
+ signature: string | null;
84
+ details: string | null;
85
+ notes: string | null;
86
+ role_type: number | null;
87
+ custom_role_id: number | null;
88
+ is_billing_admin: boolean;
89
+ moderator: boolean;
90
+ ticket_restriction: string | null;
91
+ only_private_comments: boolean;
92
+ restricted_agent: boolean;
93
+ suspended: boolean;
94
+ default_group_id: number | null;
95
+ report_csv: boolean;
96
+ user_fields: Record<string, unknown>;
97
+ suspension_details: unknown | null;
98
+ }
99
+ export interface ZendeskTokens {
100
+ access_token: string;
101
+ refresh_token?: string;
102
+ token_type: string;
103
+ scope: string;
104
+ expires_in?: number;
105
+ refresh_token_expires_in?: number;
106
+ }
107
+ export declare function defineOAuthZendeskEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthZendeskConfig, {
108
+ user: ZendeskUser;
109
+ tokens: ZendeskTokens;
110
+ }>): import("nuxt/server").EventHandler<Promise<any>>;
@@ -0,0 +1,109 @@
1
+ import { defineEventHandler, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
3
+ import { withQuery } from "ufo";
4
+ import { defu } from "defu";
5
+ import {
6
+ handleMissingConfiguration,
7
+ handleAccessTokenErrorResponse,
8
+ getOAuthRedirectURL,
9
+ handleInvalidState,
10
+ handleState,
11
+ requestAccessToken
12
+ } from "../utils.js";
13
+ function getMarketplaceHeaders(config) {
14
+ const headers = {};
15
+ if (config.marketplaceName) {
16
+ headers["X-Zendesk-Marketplace-Name"] = config.marketplaceName;
17
+ }
18
+ if (config.marketplaceOrgId) {
19
+ headers["X-Zendesk-Marketplace-Organization-Id"] = config.marketplaceOrgId;
20
+ }
21
+ if (config.marketplaceBotId) {
22
+ headers["X-Zendesk-Marketplace-Bot-Id"] = config.marketplaceBotId;
23
+ }
24
+ if (config.marketplaceAppId) {
25
+ headers["X-Zendesk-Marketplace-App-Id"] = config.marketplaceAppId;
26
+ }
27
+ return headers;
28
+ }
29
+ export function defineOAuthZendeskEventHandler({
30
+ config,
31
+ onSuccess,
32
+ onError
33
+ }) {
34
+ return defineEventHandler(async (event) => {
35
+ const runtimeConfig = useRuntimeConfig().oauth?.zendesk;
36
+ config = defu(config, runtimeConfig);
37
+ config.scope = config.scope?.length ? config.scope : ["read"];
38
+ if (!config.scope.includes("read") && !config.scope.includes("users:read")) {
39
+ config.scope.push("users:read");
40
+ }
41
+ if (!config.clientId || !config.clientSecret || !config.subdomain) {
42
+ return handleMissingConfiguration(
43
+ event,
44
+ "zendesk",
45
+ ["clientId", "clientSecret", "subdomain"],
46
+ onError
47
+ );
48
+ }
49
+ const baseURL = `https://${config.subdomain}.zendesk.com`;
50
+ const query = getQuery(event);
51
+ const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
52
+ if (query.error) {
53
+ return handleAccessTokenErrorResponse(
54
+ event,
55
+ "zendesk",
56
+ {
57
+ error: query.error,
58
+ error_description: query.error_description
59
+ },
60
+ onError
61
+ );
62
+ }
63
+ const state = await handleState(event);
64
+ if (!query.code) {
65
+ return sendRedirect(
66
+ event,
67
+ withQuery(`${baseURL}/oauth/authorizations/new`, {
68
+ response_type: "code",
69
+ client_id: config.clientId,
70
+ redirect_uri: redirectURL,
71
+ scope: config.scope.join(" "),
72
+ state
73
+ })
74
+ );
75
+ }
76
+ if (!state || query.state !== state) {
77
+ return handleInvalidState(event, "zendesk", onError);
78
+ }
79
+ const marketplaceHeaders = getMarketplaceHeaders(config);
80
+ const tokens = await requestAccessToken(`${baseURL}/oauth/tokens`, {
81
+ headers: {
82
+ // Zendesk documents JSON bodies for the token endpoint
83
+ "Content-Type": "application/json",
84
+ ...marketplaceHeaders
85
+ },
86
+ body: {
87
+ grant_type: "authorization_code",
88
+ client_id: config.clientId,
89
+ client_secret: config.clientSecret,
90
+ redirect_uri: redirectURL,
91
+ code: query.code,
92
+ scope: config.scope.join(" ")
93
+ }
94
+ });
95
+ if (tokens.error) {
96
+ return handleAccessTokenErrorResponse(event, "zendesk", tokens, onError);
97
+ }
98
+ const data = await $fetch(`${baseURL}/api/v2/users/me.json`, {
99
+ headers: {
100
+ Authorization: `Bearer ${tokens.access_token}`,
101
+ ...marketplaceHeaders
102
+ }
103
+ });
104
+ return onSuccess(event, {
105
+ user: data.user,
106
+ tokens
107
+ });
108
+ });
109
+ }
@@ -34,4 +34,4 @@ export interface OAuthZitadelConfig {
34
34
  */
35
35
  redirectURL?: string;
36
36
  }
37
- export declare function defineOAuthZitadelEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthZitadelConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
37
+ export declare function defineOAuthZitadelEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthZitadelConfig>): import("nuxt/server").EventHandler<Promise<any>>;
@@ -1,17 +1,17 @@
1
- import { eventHandler, getQuery, sendRedirect } from "h3";
1
+ import { defineEventHandler, createError, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
2
3
  import { hasProtocol, withQuery } from "ufo";
3
4
  import { defu } from "defu";
4
5
  import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken, handleState, handlePkceVerifier, handleInvalidState } from "../utils.js";
5
- import { useRuntimeConfig, createError } from "#imports";
6
6
  export function defineOAuthZitadelEventHandler({ config, onSuccess, onError }) {
7
- return eventHandler(async (event) => {
8
- config = defu(config, useRuntimeConfig(event).oauth?.zitadel, {
7
+ return defineEventHandler(async (event) => {
8
+ config = defu(config, useRuntimeConfig().oauth?.zitadel, {
9
9
  authorizationParams: {}
10
10
  });
11
11
  const query = getQuery(event);
12
12
  if (query.error) {
13
13
  const error = createError({
14
- statusCode: 401,
14
+ status: 401,
15
15
  message: `Zitadel login failed: ${query.error || "Unknown error"}`,
16
16
  data: query
17
17
  });
@@ -75,7 +75,7 @@ export function defineOAuthZitadelEventHandler({ config, onSuccess, onError }) {
75
75
  });
76
76
  if (!user) {
77
77
  const error = createError({
78
- statusCode: 500,
78
+ status: 500,
79
79
  message: "Could not get Zitadel user",
80
80
  data: tokens
81
81
  });
@@ -1,8 +1,8 @@
1
- import { type H3Event } from 'h3';
1
+ import type { RequestEvent } from 'nuxt/server';
2
2
  import * as jose from 'jose';
3
3
  import type { OAuthProvider, OnError } from '#auth-utils';
4
4
  export declare const isDevelopment: boolean;
5
- export declare function getOAuthRedirectURL(event: H3Event): string;
5
+ export declare function getOAuthRedirectURL(event: RequestEvent): string;
6
6
  /**
7
7
  * Request an access token body.
8
8
  *
@@ -34,9 +34,9 @@ export declare function requestAccessToken<T = any>(url: string, options: Reques
34
34
  *
35
35
  * @see https://datatracker.ietf.org/doc/html/rfc6749#section-5.2
36
36
  */
37
- export declare function handleAccessTokenErrorResponse(event: H3Event, oauthProvider: OAuthProvider, oauthError: any, onError?: OnError): any;
38
- export declare function handleMissingConfiguration(event: H3Event, provider: OAuthProvider, missingKeys: string[], onError?: OnError): any;
39
- export declare function handleInvalidState(event: H3Event, provider: OAuthProvider, onError?: OnError): any;
37
+ export declare function handleAccessTokenErrorResponse(event: RequestEvent, oauthProvider: OAuthProvider, oauthError: any, onError?: OnError): any;
38
+ export declare function handleMissingConfiguration(event: RequestEvent, provider: OAuthProvider, missingKeys: string[], onError?: OnError): any;
39
+ export declare function handleInvalidState(event: RequestEvent, provider: OAuthProvider, onError?: OnError): any;
40
40
  /**
41
41
  * JWT signing using jose
42
42
  *
@@ -62,7 +62,7 @@ interface JWTVerifyOptions {
62
62
  issuer: string;
63
63
  }
64
64
  export declare function verifyJwt<T>(token: string, options: JWTVerifyOptions): Promise<T>;
65
- export declare function handlePkceVerifier(event: H3Event): Promise<{
65
+ export declare function handlePkceVerifier(event: RequestEvent): Promise<{
66
66
  code_verifier: string;
67
67
  code_challenge: string;
68
68
  code_challenge_method: string;
@@ -75,7 +75,7 @@ interface HandleStateOptions {
75
75
  isCallback?: boolean;
76
76
  sameSite?: 'lax' | 'none' | 'strict';
77
77
  }
78
- export declare function handleState(event: H3Event, options?: HandleStateOptions): Promise<string | undefined>;
78
+ export declare function handleState(event: RequestEvent, options?: HandleStateOptions): Promise<string | undefined>;
79
79
  export declare function parseJwt(token: string): jose.JWTPayload;
80
- export declare function handleNonce(event: H3Event): string | undefined;
80
+ export declare function handleNonce(event: RequestEvent): string | undefined;
81
81
  export {};
@@ -1,10 +1,8 @@
1
- import { deleteCookie, getCookie, getQuery, setCookie } from "h3";
2
- import { getRequestURL } from "h3";
3
- import { FetchError } from "ofetch";
1
+ import { createError, deleteCookie, getCookie, getQuery, getRequestURL, setCookie } from "nuxt/server";
2
+ import { $fetch, FetchError } from "ofetch";
4
3
  import { snakeCase, upperFirst } from "scule";
5
4
  import * as jose from "jose";
6
5
  import { subtle, getRandomValues } from "uncrypto";
7
- import { createError } from "#imports";
8
6
  export const isDevelopment = process.env.NODE_ENV === "development";
9
7
  const OAUTH_COOKIE_MAX_AGE = 60 * 10;
10
8
  export function getOAuthRedirectURL(event) {
@@ -33,7 +31,7 @@ export async function requestAccessToken(url, options) {
33
31
  export function handleAccessTokenErrorResponse(event, oauthProvider, oauthError, onError) {
34
32
  const message = `${upperFirst(oauthProvider)} login failed: ${oauthError.error_description || oauthError.error?.message || oauthError.error || "Unknown error"}`;
35
33
  const error = createError({
36
- statusCode: 401,
34
+ status: 401,
37
35
  message,
38
36
  data: oauthError
39
37
  });
@@ -43,7 +41,7 @@ export function handleAccessTokenErrorResponse(event, oauthProvider, oauthError,
43
41
  export function handleMissingConfiguration(event, provider, missingKeys, onError) {
44
42
  const environmentVariables = missingKeys.map((key) => `NUXT_OAUTH_${provider.toUpperCase()}_${snakeCase(key).toUpperCase()}`);
45
43
  const error = createError({
46
- statusCode: 500,
44
+ status: 500,
47
45
  message: `Missing ${environmentVariables.join(" or ")} env ${missingKeys.length > 1 ? "variables" : "variable"}.`
48
46
  });
49
47
  if (!onError) throw error;
@@ -52,7 +50,7 @@ export function handleMissingConfiguration(event, provider, missingKeys, onError
52
50
  export function handleInvalidState(event, provider, onError) {
53
51
  const message = `${upperFirst(provider)} login failed: state mismatch`;
54
52
  const error = createError({
55
- statusCode: 500,
53
+ status: 500,
56
54
  message
57
55
  });
58
56
  if (!onError) throw error;
@@ -1,3 +1,3 @@
1
- import type { EventHandler } from 'h3';
1
+ import type { EventHandler } from 'nuxt/server';
2
2
  import type { WebAuthnAuthenticateEventHandlerOptions, WebAuthnCredential } from '#auth-utils';
3
3
  export declare function defineWebAuthnAuthenticateEventHandler<T extends WebAuthnCredential>({ storeChallenge, getChallenge, getCredential, allowCredentials, getOptions, onSuccess, onError, }: WebAuthnAuthenticateEventHandlerOptions<T>): EventHandler;
@@ -1,9 +1,8 @@
1
- import { eventHandler, H3Error, createError, getRequestURL, readBody } from "h3";
1
+ import { defineEventHandler, createError, getRequestURL, isNuxtError, readBody, useRuntimeConfig } from "nuxt/server";
2
2
  import { generateAuthenticationOptions, verifyAuthenticationResponse } from "@simplewebauthn/server";
3
3
  import defu from "defu";
4
4
  import { getRandomValues } from "uncrypto";
5
5
  import { base64URLStringToBuffer, bufferToBase64URLString } from "@simplewebauthn/browser";
6
- import { useRuntimeConfig } from "#imports";
7
6
  export function defineWebAuthnAuthenticateEventHandler({
8
7
  storeChallenge,
9
8
  getChallenge,
@@ -13,10 +12,10 @@ export function defineWebAuthnAuthenticateEventHandler({
13
12
  onSuccess,
14
13
  onError
15
14
  }) {
16
- return eventHandler(async (event) => {
15
+ return defineEventHandler(async (event) => {
17
16
  const url = getRequestURL(event);
18
17
  const body = await readBody(event);
19
- const _config = defu(await getOptions?.(event, body) ?? {}, useRuntimeConfig(event).webauthn.authenticate, {
18
+ const _config = defu(await getOptions?.(event, body) ?? {}, useRuntimeConfig().webauthn.authenticate, {
20
19
  rpID: url.hostname
21
20
  });
22
21
  if (!storeChallenge) {
@@ -38,7 +37,7 @@ export function defineWebAuthnAuthenticateEventHandler({
38
37
  };
39
38
  }
40
39
  if (!body.attemptId)
41
- throw createError({ statusCode: 400 });
40
+ throw createError({ status: 400 });
42
41
  let expectedChallenge = "";
43
42
  if (getChallenge) {
44
43
  expectedChallenge = await getChallenge(event, body.attemptId);
@@ -59,7 +58,7 @@ export function defineWebAuthnAuthenticateEventHandler({
59
58
  }
60
59
  });
61
60
  if (!verification.verified)
62
- throw createError({ statusCode: 400, message: "Failed to verify registration response" });
61
+ throw createError({ status: 400, message: "Failed to verify registration response" });
63
62
  await onSuccess(event, {
64
63
  credential,
65
64
  authenticationInfo: verification.authenticationInfo
@@ -67,9 +66,9 @@ export function defineWebAuthnAuthenticateEventHandler({
67
66
  return verification;
68
67
  } catch (error) {
69
68
  if (!onError) throw error;
70
- if (error instanceof H3Error)
69
+ if (isNuxtError(error))
71
70
  return onError(event, error);
72
- return onError(event, createError({ statusCode: 500, message: "Failed to authenticate credential" }));
71
+ return onError(event, createError({ status: 500, message: "Failed to authenticate credential" }));
73
72
  }
74
73
  });
75
74
  }
@@ -1,5 +1,5 @@
1
- import type { H3Event, EventHandler } from 'h3';
1
+ import type { EventHandler, RequestEvent } from 'nuxt/server';
2
2
  import type { ValidateUserFunction } from '../../../types/webauthn.js';
3
3
  import type { WebAuthnUser, WebAuthnRegisterEventHandlerOptions } from '#auth-utils';
4
4
  export declare function defineWebAuthnRegisterEventHandler<T extends WebAuthnUser>({ storeChallenge, getChallenge, getOptions, validateUser, excludeCredentials, onSuccess, onError, }: WebAuthnRegisterEventHandlerOptions<T>): EventHandler;
5
- export declare function validateUserData<T>(userBody: WebAuthnUser, event: H3Event, fn: ValidateUserFunction<T>): Promise<T>;
5
+ export declare function validateUserData<T>(userBody: WebAuthnUser, event: RequestEvent, fn: ValidateUserFunction<T>): Promise<T>;
@@ -1,9 +1,8 @@
1
- import { eventHandler, H3Error, createError, getRequestURL, readBody } from "h3";
1
+ import { defineEventHandler, createError, getRequestURL, isNuxtError, readBody, useRuntimeConfig } from "nuxt/server";
2
2
  import { generateRegistrationOptions, verifyRegistrationResponse } from "@simplewebauthn/server";
3
3
  import defu from "defu";
4
4
  import { bufferToBase64URLString } from "@simplewebauthn/browser";
5
5
  import { getRandomValues } from "uncrypto";
6
- import { useRuntimeConfig } from "#imports";
7
6
  export function defineWebAuthnRegisterEventHandler({
8
7
  storeChallenge,
9
8
  getChallenge,
@@ -13,19 +12,19 @@ export function defineWebAuthnRegisterEventHandler({
13
12
  onSuccess,
14
13
  onError
15
14
  }) {
16
- return eventHandler(async (event) => {
15
+ return defineEventHandler(async (event) => {
17
16
  const url = getRequestURL(event);
18
17
  const body = await readBody(event);
19
18
  if (body.verify === void 0 || !body.user?.userName)
20
19
  throw createError({
21
20
  message: "Invalid request, missing userName or verify property",
22
- statusCode: 400
21
+ status: 400
23
22
  });
24
23
  let user = body.user;
25
24
  if (validateUser) {
26
25
  user = await validateUserData(body.user, event, validateUser);
27
26
  }
28
- const _config = defu(await getOptions?.(event, body) ?? {}, useRuntimeConfig(event).webauthn.register, {
27
+ const _config = defu(await getOptions?.(event, body) ?? {}, useRuntimeConfig().webauthn.register, {
29
28
  rpID: url.hostname,
30
29
  rpName: url.hostname,
31
30
  userName: user.userName,
@@ -55,7 +54,7 @@ export function defineWebAuthnRegisterEventHandler({
55
54
  if (!body.attemptId) {
56
55
  throw createError({
57
56
  message: "Invalid request, missing attemptId",
58
- statusCode: 400
57
+ status: 400
59
58
  });
60
59
  }
61
60
  let expectedChallenge = "";
@@ -74,7 +73,7 @@ export function defineWebAuthnRegisterEventHandler({
74
73
  if (!verification.verified) {
75
74
  throw createError({
76
75
  message: "Failed to verify registration response",
77
- statusCode: 400
76
+ status: 400
78
77
  });
79
78
  }
80
79
  await onSuccess(event, {
@@ -92,9 +91,9 @@ export function defineWebAuthnRegisterEventHandler({
92
91
  return verification;
93
92
  } catch (error) {
94
93
  if (!onError) throw error;
95
- if (error instanceof H3Error)
94
+ if (isNuxtError(error))
96
95
  return onError(event, error);
97
- return onError(event, createError({ statusCode: 500, message: "Failed to register credential" }));
96
+ return onError(event, createError({ status: 500, message: "Failed to register credential" }));
98
97
  }
99
98
  });
100
99
  }
@@ -114,7 +113,7 @@ export async function validateUserData(userBody, event, fn) {
114
113
  }
115
114
  function createUserValidationError(validateError) {
116
115
  throw createError({
117
- status: validateError?.statusCode || 400,
116
+ status: validateError?.status || validateError?.statusCode || 400,
118
117
  message: validateError?.message || "User Validation Error",
119
118
  data: validateError
120
119
  });
@@ -0,0 +1,2 @@
1
+ declare const _default: () => void;
2
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import { useRuntimeConfig, useServerHooks } from "nuxt/server";
2
+ export default () => {
3
+ useServerHooks().hook("render:html", (html) => {
4
+ const oauth = useRuntimeConfig().oauth;
5
+ if (!oauth?.facebook?.clientId && !oauth?.instagram?.clientId) return;
6
+ html.head.unshift('<script>if(window.location.hash==="#_=_"){history.replaceState?history.replaceState(null,null,window.location.href.split("#")[0]):window.location.hash=""}<\/script>');
7
+ });
8
+ };
@@ -1,4 +1,4 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, {
1
+ declare const _default: import("nuxt/server").EventHandler<{
2
2
  redirect_uris: [string, ...string[]];
3
3
  scope?: string | undefined;
4
4
  response_types?: ["code" | "none" | "token" | "code id_token token" | "code id_token" | "code token" | "id_token token" | "id_token", ...("code" | "none" | "token" | "code id_token token" | "code id_token" | "code token" | "id_token token" | "id_token")[]] | undefined;
@@ -1,10 +1,10 @@
1
- import { defineEventHandler, createError } from "h3";
1
+ import { createError, defineEventHandler, getRequestURL, useRuntimeConfig } from "nuxt/server";
2
+ import { withoutBase } from "ufo";
2
3
  import { getAtprotoClientMetadata } from "../../utils/atproto.js";
3
4
  import { atprotoProviders, getClientMetadataFilename } from "../../../utils/atproto.js";
4
- import { useRuntimeConfig } from "#imports";
5
5
  export default defineEventHandler((event) => {
6
- const path = event.path.slice(1);
7
- const runtimeConfig = useRuntimeConfig(event);
6
+ const runtimeConfig = useRuntimeConfig();
7
+ const path = withoutBase(getRequestURL(event).pathname, runtimeConfig.app.baseURL).slice(1);
8
8
  for (const provider of atprotoProviders) {
9
9
  const config = runtimeConfig.oauth[provider];
10
10
  if (getClientMetadataFilename(provider, config) === path) {
@@ -12,7 +12,7 @@ export default defineEventHandler((event) => {
12
12
  }
13
13
  }
14
14
  throw createError({
15
- statusCode: 404,
15
+ status: 404,
16
16
  message: "Provider not found"
17
17
  });
18
18
  });
@@ -1,5 +1,5 @@
1
- import type { H3Event } from 'h3';
1
+ import type { RequestEvent } from 'nuxt/server';
2
2
  import type { OAuthClientMetadataInput } from '@atproto/oauth-client-node';
3
3
  import type { OAuthBlueskyConfig } from '../lib/atproto/bluesky.js';
4
4
  import type { ATProtoProvider, OAuthConfig } from '#auth-utils';
5
- export declare function getAtprotoClientMetadata(event: H3Event, provider: ATProtoProvider, config?: OAuthConfig<OAuthBlueskyConfig>['config']): OAuthClientMetadataInput;
5
+ export declare function getAtprotoClientMetadata(event: RequestEvent, provider: ATProtoProvider, config?: OAuthConfig<OAuthBlueskyConfig>['config']): OAuthClientMetadataInput;
@@ -1,9 +1,8 @@
1
- import { getRequestURL } from "h3";
1
+ import { getRequestURL, useRuntimeConfig } from "nuxt/server";
2
2
  import { getOAuthRedirectURL } from "../lib/utils.js";
3
3
  import { getClientMetadataFilename } from "../../utils/atproto.js";
4
- import { useRuntimeConfig } from "#imports";
5
4
  export function getAtprotoClientMetadata(event, provider, config) {
6
- const providerRuntimeConfig = useRuntimeConfig(event).oauth[provider];
5
+ const providerRuntimeConfig = useRuntimeConfig().oauth[provider];
7
6
  const scopes = [.../* @__PURE__ */ new Set(["atproto", ...config?.scope ?? [], ...providerRuntimeConfig.scope ?? []])];
8
7
  const scope = scopes.join(" ");
9
8
  const grantTypes = [.../* @__PURE__ */ new Set(["authorization_code", ...providerRuntimeConfig.grantTypes ?? []])];
@@ -1,6 +1,6 @@
1
1
  import { Hash } from "@adonisjs/hash";
2
2
  import { Scrypt } from "@adonisjs/hash/drivers/scrypt";
3
- import { useRuntimeConfig } from "#imports";
3
+ import { useRuntimeConfig } from "nuxt/server";
4
4
  let _hash;
5
5
  function getHash() {
6
6
  if (!_hash) {
@@ -1,55 +1,68 @@
1
- import type { H3Event, SessionConfig } from 'h3';
2
- import { useSession } from 'h3';
1
+ import type { RequestEvent, SessionConfig } from 'nuxt/server';
3
2
  import type { OmitWithIndexSignature } from '../../types/utils.js';
4
- import type { SessionEvent, UserSession, UserSessionRequired } from '#auth-utils';
5
- type UseSessionEvent = Parameters<typeof useSession>[0] | SessionEvent;
3
+ import type { LegacyH3Event, SessionEvent, UserSession, UserSessionRequired } from '#auth-utils';
4
+ /**
5
+ * Name of the cookie the user session is sealed into.
6
+ */
7
+ export declare const USER_SESSION_COOKIE_NAME = "nuxt-auth-session";
8
+ type UserSessionData = OmitWithIndexSignature<UserSession, 'id'>;
9
+ /**
10
+ * Session options, the session is always sealed with a secret derived from `appSecret`.
11
+ */
12
+ type UserSessionConfig = Omit<SessionConfig, 'password'>;
13
+ /**
14
+ * An event the session can be written with, WebSocket peers and upgrade requests are read-only.
15
+ */
16
+ type WritableSessionEvent = RequestEvent | LegacyH3Event;
6
17
  export interface SessionHooks {
7
18
  /**
8
19
  * Called when fetching the session from the API
9
20
  * - Add extra properties to the session
10
21
  * - Throw an error if the session could not be verified (with a database for example)
11
22
  */
12
- fetch: (session: UserSession, event: H3Event) => void | Promise<void>;
23
+ fetch: (session: UserSession, event: RequestEvent) => void | Promise<void>;
13
24
  /**
14
25
  * Called before clearing the session
15
26
  */
16
- clear: (session: UserSession, event: H3Event) => void | Promise<void>;
27
+ clear: (session: UserSession, event: RequestEvent) => void | Promise<void>;
17
28
  }
18
29
  export declare const sessionHooks: import("hookable").Hookable<SessionHooks, import("hookable").HookKeys<SessionHooks>>;
19
30
  /**
20
31
  * Get the user session from the current request
21
- * @param event The Request (h3) event
32
+ * @param event The request event
22
33
  * @returns The user session
23
34
  */
24
- export declare function getUserSession(event: UseSessionEvent): Promise<UserSession>;
35
+ export declare function getUserSession(event: SessionEvent): Promise<UserSession>;
25
36
  /**
26
37
  * Set a user session
27
- * @param event The Request (h3) event
38
+ * @param event The request event
28
39
  * @param data User session data, please only store public information since it can be decoded with API calls
29
40
  * @see https://github.com/atinux/nuxt-auth-utils
30
41
  */
31
- export declare function setUserSession(event: SessionEvent, data: OmitWithIndexSignature<UserSession, 'id'>, config?: Partial<SessionConfig>): Promise<UserSession>;
42
+ export declare function setUserSession(event: WritableSessionEvent, data: UserSessionData, config?: UserSessionConfig): Promise<UserSession>;
32
43
  /**
33
44
  * Replace a user session
34
- * @param event The Request (h3) event
45
+ * @param event The request event
35
46
  * @param data User session data, please only store public information since it can be decoded with API calls
36
47
  */
37
- export declare function replaceUserSession(event: SessionEvent, data: OmitWithIndexSignature<UserSession, 'id'>, config?: Partial<SessionConfig>): Promise<UserSession>;
48
+ export declare function replaceUserSession(event: WritableSessionEvent, data: UserSessionData, config?: UserSessionConfig): Promise<UserSession>;
38
49
  /**
39
50
  * Clear the user session and removing the session cookie
40
- * @param event The Request (h3) event
51
+ * @param event The request event
41
52
  * @returns true if the session was cleared
42
53
  */
43
- export declare function clearUserSession(event: SessionEvent, config?: Partial<SessionConfig>): Promise<boolean>;
54
+ export declare function clearUserSession(event: WritableSessionEvent, config?: UserSessionConfig): Promise<boolean>;
44
55
  /**
45
56
  * Require a user session, throw a 401 error if the user is not logged in
46
57
  * @param event
47
58
  * @param opts Options to customize the error message and status code
48
- * @param opts.statusCode The status code to use for the error (defaults to 401)
59
+ * @param opts.status The status code to use for the error (defaults to 401)
60
+ * @param opts.statusCode Deprecated, use `status`
49
61
  * @param opts.message The message to use for the error (defaults to Unauthorized)
50
62
  * @see https://github.com/atinux/nuxt-auth-utils
51
63
  */
52
- export declare function requireUserSession(event: UseSessionEvent, opts?: {
64
+ export declare function requireUserSession(event: SessionEvent, opts?: {
65
+ status?: number;
53
66
  statusCode?: number;
54
67
  message?: string;
55
68
  }): Promise<UserSessionRequired>;