nuxt-auth-utils 0.5.29 → 0.5.30

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 (53) hide show
  1. package/README.md +1 -1
  2. package/dist/module.json +1 -1
  3. package/dist/runtime/app/plugins/session.client.js +1 -1
  4. package/dist/runtime/server/lib/oauth/apple.js +12 -3
  5. package/dist/runtime/server/lib/oauth/atlassian.js +7 -4
  6. package/dist/runtime/server/lib/oauth/auth0.js +7 -2
  7. package/dist/runtime/server/lib/oauth/authentik.js +7 -2
  8. package/dist/runtime/server/lib/oauth/azureb2c.js +2 -2
  9. package/dist/runtime/server/lib/oauth/battledotnet.js +7 -5
  10. package/dist/runtime/server/lib/oauth/box.js +2 -2
  11. package/dist/runtime/server/lib/oauth/cognito.js +7 -2
  12. package/dist/runtime/server/lib/oauth/discord.js +7 -2
  13. package/dist/runtime/server/lib/oauth/dropbox.js +7 -2
  14. package/dist/runtime/server/lib/oauth/facebook.js +7 -3
  15. package/dist/runtime/server/lib/oauth/gitea.js +8 -1
  16. package/dist/runtime/server/lib/oauth/github.js +2 -2
  17. package/dist/runtime/server/lib/oauth/gitlab.js +8 -1
  18. package/dist/runtime/server/lib/oauth/google.js +7 -3
  19. package/dist/runtime/server/lib/oauth/heroku.js +2 -2
  20. package/dist/runtime/server/lib/oauth/hubspot.js +8 -1
  21. package/dist/runtime/server/lib/oauth/instagram.js +7 -2
  22. package/dist/runtime/server/lib/oauth/keycloak.js +7 -2
  23. package/dist/runtime/server/lib/oauth/kick.js +6 -3
  24. package/dist/runtime/server/lib/oauth/line.js +7 -3
  25. package/dist/runtime/server/lib/oauth/linear.js +7 -2
  26. package/dist/runtime/server/lib/oauth/linkedin.js +7 -2
  27. package/dist/runtime/server/lib/oauth/livechat.js +9 -5
  28. package/dist/runtime/server/lib/oauth/microsoft.js +7 -3
  29. package/dist/runtime/server/lib/oauth/oidc.js +2 -2
  30. package/dist/runtime/server/lib/oauth/okta.js +3 -4
  31. package/dist/runtime/server/lib/oauth/ory.js +2 -2
  32. package/dist/runtime/server/lib/oauth/osu.js +2 -2
  33. package/dist/runtime/server/lib/oauth/paypal.js +7 -2
  34. package/dist/runtime/server/lib/oauth/polar.js +7 -2
  35. package/dist/runtime/server/lib/oauth/riotgames.js +2 -2
  36. package/dist/runtime/server/lib/oauth/roblox.js +7 -2
  37. package/dist/runtime/server/lib/oauth/salesforce.js +2 -2
  38. package/dist/runtime/server/lib/oauth/seznam.js +6 -2
  39. package/dist/runtime/server/lib/oauth/shopifyCustomer.js +4 -1
  40. package/dist/runtime/server/lib/oauth/slack.js +2 -2
  41. package/dist/runtime/server/lib/oauth/spotify.js +7 -2
  42. package/dist/runtime/server/lib/oauth/steam.js +6 -2
  43. package/dist/runtime/server/lib/oauth/strava.js +8 -1
  44. package/dist/runtime/server/lib/oauth/tiktok.js +7 -2
  45. package/dist/runtime/server/lib/oauth/twitch.js +7 -2
  46. package/dist/runtime/server/lib/oauth/vk.js +7 -1
  47. package/dist/runtime/server/lib/oauth/workos.js +7 -2
  48. package/dist/runtime/server/lib/oauth/xsuaa.js +7 -2
  49. package/dist/runtime/server/lib/oauth/yandex.js +8 -1
  50. package/dist/runtime/server/lib/oauth/zitadel.js +2 -2
  51. package/dist/runtime/server/lib/utils.d.ts +5 -1
  52. package/dist/runtime/server/lib/utils.js +11 -9
  53. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import { eventHandler, getQuery, sendRedirect, getRequestIP, getRequestHeader } from "h3";
2
2
  import { withQuery } from "ufo";
3
3
  import { defu } from "defu";
4
- import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken } from "../utils.js";
4
+ import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
5
5
  import { useRuntimeConfig } from "#imports";
6
6
  export function defineOAuthWorkOSEventHandler({ config, onSuccess, onError }) {
7
7
  return eventHandler(async (event) => {
@@ -14,6 +14,7 @@ export function defineOAuthWorkOSEventHandler({ config, onSuccess, onError }) {
14
14
  if (query.error) {
15
15
  return handleAccessTokenErrorResponse(event, "workos", query, onError);
16
16
  }
17
+ const state = await handleState(event);
17
18
  if (!query.code) {
18
19
  return sendRedirect(
19
20
  event,
@@ -24,10 +25,14 @@ export function defineOAuthWorkOSEventHandler({ config, onSuccess, onError }) {
24
25
  redirect_uri: redirectURL || void 0,
25
26
  connection_id: config.connectionId || void 0,
26
27
  screen_hint: config.screenHint || "sign-in",
27
- organization_id: config.organizationId || void 0
28
+ organization_id: config.organizationId || void 0,
29
+ state
28
30
  })
29
31
  );
30
32
  }
33
+ if (query.state !== state) {
34
+ return handleInvalidState(event, "workos", onError);
35
+ }
31
36
  const authenticateResponse = await requestAccessToken("https://api.workos.com/user_management/authenticate", {
32
37
  headers: {
33
38
  "Content-Type": "application/json"
@@ -1,7 +1,7 @@
1
1
  import { eventHandler, getQuery, sendRedirect } from "h3";
2
2
  import { withQuery } from "ufo";
3
3
  import { defu } from "defu";
4
- import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken } from "../utils.js";
4
+ import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
5
5
  import { useRuntimeConfig } from "#imports";
6
6
  export function defineOAuthXSUAAEventHandler({ config, onSuccess, onError }) {
7
7
  return eventHandler(async (event) => {
@@ -13,6 +13,7 @@ export function defineOAuthXSUAAEventHandler({ config, onSuccess, onError }) {
13
13
  const authorizationURL = `https://${config.domain}/oauth/authorize`;
14
14
  const tokenURL = `https://${config.domain}/oauth/token`;
15
15
  const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
16
+ const state = await handleState(event);
16
17
  if (!query.code) {
17
18
  config.scope = config.scope || [];
18
19
  return sendRedirect(
@@ -21,10 +22,14 @@ export function defineOAuthXSUAAEventHandler({ config, onSuccess, onError }) {
21
22
  response_type: "code",
22
23
  client_id: config.clientId,
23
24
  redirect_uri: redirectURL,
24
- scope: config.scope.join(" ")
25
+ scope: config.scope.join(" "),
26
+ state
25
27
  })
26
28
  );
27
29
  }
30
+ if (query.state !== state) {
31
+ return handleInvalidState(event, "xsuaa", onError);
32
+ }
28
33
  const tokens = await requestAccessToken(tokenURL, {
29
34
  body: {
30
35
  grant_type: "authorization_code",
@@ -5,6 +5,8 @@ import {
5
5
  handleMissingConfiguration,
6
6
  handleAccessTokenErrorResponse,
7
7
  getOAuthRedirectURL,
8
+ handleInvalidState,
9
+ handleState,
8
10
  requestAccessToken
9
11
  } from "../utils.js";
10
12
  import { useRuntimeConfig } from "#imports";
@@ -29,6 +31,7 @@ export function defineOAuthYandexEventHandler({
29
31
  );
30
32
  }
31
33
  const redirectURL = config.redirectURL || getOAuthRedirectURL(event);
34
+ const state = await handleState(event);
32
35
  if (!query.code) {
33
36
  config.scope = config.scope || [];
34
37
  if (config.emailRequired && !config.scope.includes("login:email")) {
@@ -40,10 +43,14 @@ export function defineOAuthYandexEventHandler({
40
43
  response_type: "code",
41
44
  client_id: config.clientId,
42
45
  redirect_uri: redirectURL,
43
- scope: config.scope.join(" ")
46
+ scope: config.scope.join(" "),
47
+ state
44
48
  })
45
49
  );
46
50
  }
51
+ if (query.state !== state) {
52
+ return handleInvalidState(event, "yandex", onError);
53
+ }
47
54
  const tokens = await requestAccessToken(config.tokenURL, {
48
55
  body: {
49
56
  grant_type: "authorization_code",
@@ -36,10 +36,10 @@ export function defineOAuthZitadelEventHandler({ config, onSuccess, onError }) {
36
36
  client_id: config.clientId,
37
37
  redirect_uri: redirectURL,
38
38
  scope: config.scope.join(" "),
39
- state,
40
39
  code_challenge: verifier.code_challenge,
41
40
  code_challenge_method: verifier.code_challenge_method,
42
- ...config.authorizationParams
41
+ ...config.authorizationParams,
42
+ state
43
43
  })
44
44
  );
45
45
  }
@@ -70,7 +70,11 @@ export declare function handlePkceVerifier(event: H3Event): Promise<{
70
70
  code_challenge?: undefined;
71
71
  code_challenge_method?: undefined;
72
72
  }>;
73
- export declare function handleState(event: H3Event): Promise<string | undefined>;
73
+ interface HandleStateOptions {
74
+ isCallback?: boolean;
75
+ sameSite?: 'lax' | 'none' | 'strict';
76
+ }
77
+ export declare function handleState(event: H3Event, options?: HandleStateOptions): Promise<string | undefined>;
74
78
  export declare function parseJwt(token: string): jose.JWTPayload;
75
79
  export declare function handleNonce(event: H3Event): string | undefined;
76
80
  export {};
@@ -101,21 +101,23 @@ export async function handlePkceVerifier(event) {
101
101
  };
102
102
  }
103
103
  const verifier = getCookie(event, "nuxt-auth-pkce");
104
- deleteCookie(event, "nuxt-auth-pkce");
104
+ deleteCookie(event, "nuxt-auth-pkce", { path: "/" });
105
105
  return { code_verifier: verifier };
106
106
  }
107
- export async function handleState(event) {
107
+ export async function handleState(event, options = {}) {
108
108
  const query = getQuery(event);
109
- if (query.state) {
109
+ const isCallback = options.isCallback ?? Boolean(query.code);
110
+ if (isCallback) {
110
111
  const state2 = getCookie(event, "nuxt-auth-state");
111
- deleteCookie(event, "nuxt-auth-state");
112
+ deleteCookie(event, "nuxt-auth-state", { path: "/" });
112
113
  return state2;
113
114
  }
114
- const state = encodeBase64Url(getRandomBytes(8));
115
+ const state = encodeBase64Url(getRandomBytes());
116
+ const sameSite = options.sameSite || "lax";
115
117
  setCookie(event, "nuxt-auth-state", state, {
116
118
  httpOnly: true,
117
- secure: !isDevelopment,
118
- sameSite: "lax",
119
+ secure: sameSite === "none" || !isDevelopment,
120
+ sameSite,
119
121
  maxAge: OAUTH_COOKIE_MAX_AGE,
120
122
  path: "/"
121
123
  });
@@ -128,10 +130,10 @@ export function handleNonce(event) {
128
130
  const query = getQuery(event);
129
131
  if (query.code) {
130
132
  const nonce2 = getCookie(event, "nuxt-auth-nonce");
131
- deleteCookie(event, "nuxt-auth-nonce");
133
+ deleteCookie(event, "nuxt-auth-nonce", { path: "/" });
132
134
  return nonce2;
133
135
  }
134
- const nonce = encodeBase64Url(getRandomBytes(8));
136
+ const nonce = encodeBase64Url(getRandomBytes());
135
137
  setCookie(event, "nuxt-auth-nonce", nonce, {
136
138
  httpOnly: true,
137
139
  secure: !isDevelopment,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-auth-utils",
3
- "version": "0.5.29",
3
+ "version": "0.5.30",
4
4
  "description": "Add Authentication to Nuxt applications with secured & sealed cookies sessions.",
5
5
  "repository": {
6
6
  "type": "git",