@aura-stack/auth 0.1.0-rc.7 → 0.1.0-rc.9

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 (117) hide show
  1. package/dist/@types/index.cjs +15 -15
  2. package/dist/@types/index.d.ts +31 -7
  3. package/dist/@types/index.js +1 -1
  4. package/dist/@types/router.d.cjs +1 -1
  5. package/dist/@types/router.d.d.ts +7 -7
  6. package/dist/@types/utility.cjs +15 -15
  7. package/dist/@types/utility.d.ts +6 -6
  8. package/dist/@types/utility.js +1 -1
  9. package/dist/actions/callback/access-token.cjs +143 -143
  10. package/dist/actions/callback/access-token.d.ts +20 -15
  11. package/dist/actions/callback/access-token.js +4 -8
  12. package/dist/actions/callback/callback.cjs +455 -437
  13. package/dist/actions/callback/callback.d.ts +12 -10
  14. package/dist/actions/callback/callback.js +12 -16
  15. package/dist/actions/callback/userinfo.cjs +134 -131
  16. package/dist/actions/callback/userinfo.d.ts +9 -9
  17. package/dist/actions/callback/userinfo.js +6 -10
  18. package/dist/actions/csrfToken/csrfToken.cjs +171 -162
  19. package/dist/actions/csrfToken/csrfToken.d.ts +3 -3
  20. package/dist/actions/csrfToken/csrfToken.js +8 -12
  21. package/dist/actions/index.cjs +773 -746
  22. package/dist/actions/index.d.ts +13 -13
  23. package/dist/actions/index.js +18 -34
  24. package/dist/actions/session/session.cjs +155 -149
  25. package/dist/actions/session/session.d.ts +3 -3
  26. package/dist/actions/session/session.js +7 -11
  27. package/dist/actions/signIn/authorization.cjs +249 -231
  28. package/dist/actions/signIn/authorization.d.ts +18 -12
  29. package/dist/actions/signIn/authorization.js +6 -16
  30. package/dist/actions/signIn/signIn.cjs +423 -396
  31. package/dist/actions/signIn/signIn.d.ts +10 -10
  32. package/dist/actions/signIn/signIn.js +10 -14
  33. package/dist/actions/signOut/signOut.cjs +440 -417
  34. package/dist/actions/signOut/signOut.d.ts +3 -3
  35. package/dist/actions/signOut/signOut.js +11 -15
  36. package/dist/assert.cjs +36 -35
  37. package/dist/assert.d.ts +4 -4
  38. package/dist/assert.js +2 -10
  39. package/dist/chunk-256KIVJL.js +96 -85
  40. package/dist/chunk-42XB3YCW.js +17 -19
  41. package/dist/chunk-6SM22VVJ.js +10 -13
  42. package/dist/chunk-CAKJT3KS.js +69 -84
  43. package/dist/chunk-E3OXBRYF.js +17 -19
  44. package/dist/chunk-EBPE35JT.js +26 -28
  45. package/dist/chunk-FIPU4MLT.js +16 -18
  46. package/dist/chunk-FJUDBLCP.js +43 -50
  47. package/dist/chunk-FKRDCWBF.js +17 -19
  48. package/dist/chunk-GZU3RBTB.js +40 -51
  49. package/dist/chunk-HGJ4TXY4.js +100 -132
  50. package/dist/chunk-HMRKN75I.js +63 -63
  51. package/dist/chunk-IKHPGFCW.js +9 -11
  52. package/dist/chunk-JAPMIE6S.js +5 -7
  53. package/dist/chunk-KRNOMBXQ.js +17 -19
  54. package/dist/chunk-LLR722CL.js +70 -91
  55. package/dist/chunk-RLT4RFKV.js +30 -39
  56. package/dist/chunk-SJPDVKUS.js +88 -107
  57. package/dist/chunk-SMQO5WD7.js +16 -26
  58. package/dist/chunk-STHEPPUZ.js +6 -8
  59. package/dist/chunk-UJJ7R56J.js +37 -47
  60. package/dist/chunk-UTDLUEEG.js +25 -0
  61. package/dist/chunk-VFTYH33W.js +37 -54
  62. package/dist/chunk-XXJKNKGQ.js +23 -33
  63. package/dist/chunk-ZV4BH47P.js +134 -132
  64. package/dist/cookie.cjs +175 -169
  65. package/dist/cookie.d.ts +51 -23
  66. package/dist/cookie.js +34 -34
  67. package/dist/error.cjs +75 -75
  68. package/dist/error.d.ts +30 -30
  69. package/dist/error.js +8 -15
  70. package/dist/headers.cjs +28 -28
  71. package/dist/headers.d.ts +2 -2
  72. package/dist/headers.js +2 -6
  73. package/dist/index-DpfbvTZ_.d.ts +298 -249
  74. package/dist/index.cjs +969 -933
  75. package/dist/index.d.ts +31 -10
  76. package/dist/index.js +50 -70
  77. package/dist/jose.cjs +67 -52
  78. package/dist/jose.d.ts +8 -8
  79. package/dist/jose.js +5 -9
  80. package/dist/oauth/bitbucket.cjs +38 -38
  81. package/dist/oauth/bitbucket.d.ts +7 -7
  82. package/dist/oauth/bitbucket.js +2 -6
  83. package/dist/oauth/discord.cjs +48 -48
  84. package/dist/oauth/discord.d.ts +7 -7
  85. package/dist/oauth/discord.js +2 -6
  86. package/dist/oauth/figma.cjs +39 -39
  87. package/dist/oauth/figma.d.ts +7 -7
  88. package/dist/oauth/figma.js +2 -6
  89. package/dist/oauth/github.cjs +31 -31
  90. package/dist/oauth/github.d.ts +7 -7
  91. package/dist/oauth/github.js +2 -6
  92. package/dist/oauth/gitlab.cjs +39 -39
  93. package/dist/oauth/gitlab.d.ts +7 -7
  94. package/dist/oauth/gitlab.js +2 -6
  95. package/dist/oauth/index.cjs +180 -180
  96. package/dist/oauth/index.d.ts +26 -7
  97. package/dist/oauth/index.js +9 -36
  98. package/dist/oauth/spotify.cjs +39 -39
  99. package/dist/oauth/spotify.d.ts +7 -7
  100. package/dist/oauth/spotify.js +2 -6
  101. package/dist/oauth/x.cjs +39 -39
  102. package/dist/oauth/x.d.ts +7 -7
  103. package/dist/oauth/x.js +2 -6
  104. package/dist/response.cjs +27 -27
  105. package/dist/response.d.ts +2 -2
  106. package/dist/response.js +2 -6
  107. package/dist/schemas.cjs +91 -91
  108. package/dist/schemas.d.ts +126 -93
  109. package/dist/schemas.js +18 -18
  110. package/dist/secure.cjs +98 -95
  111. package/dist/secure.d.ts +17 -17
  112. package/dist/secure.js +4 -18
  113. package/dist/utils.cjs +132 -119
  114. package/dist/utils.d.ts +26 -11
  115. package/dist/utils.js +21 -21
  116. package/package.json +1 -1
  117. package/dist/chunk-X7M4CQTN.js +0 -25
@@ -1,74 +1,74 @@
1
1
  // src/schemas.ts
2
- import { object, string, enum as options, number, url } from "zod/v4";
2
+ import { object, string, enum as options, number, url } from "zod/v4"
3
3
  var OAuthProviderConfigSchema = object({
4
- authorizeURL: url(),
5
- accessToken: url(),
6
- scope: string().optional(),
7
- userInfo: url(),
8
- responseType: options(["code", "token", "id_token"]),
9
- clientId: string(),
10
- clientSecret: string()
11
- });
4
+ authorizeURL: url(),
5
+ accessToken: url(),
6
+ scope: string().optional(),
7
+ userInfo: url(),
8
+ responseType: options(["code", "token", "id_token"]),
9
+ clientId: string(),
10
+ clientSecret: string(),
11
+ })
12
12
  var OAuthAuthorization = OAuthProviderConfigSchema.extend({
13
- redirectURI: string(),
14
- state: string(),
15
- codeChallenge: string(),
16
- codeChallengeMethod: options(["plain", "S256"])
17
- });
13
+ redirectURI: string(),
14
+ state: string(),
15
+ codeChallenge: string(),
16
+ codeChallengeMethod: options(["plain", "S256"]),
17
+ })
18
18
  var OAuthAuthorizationResponse = object({
19
- state: string(),
20
- code: string()
21
- });
19
+ state: string(),
20
+ code: string(),
21
+ })
22
22
  var OAuthAuthorizationErrorResponse = object({
23
- error: options([
24
- "invalid_request",
25
- "unauthorized_client",
26
- "access_denied",
27
- "unsupported_response_type",
28
- "invalid_scope",
29
- "server_error",
30
- "temporarily_unavailable"
31
- ]),
32
- error_description: string().optional(),
33
- error_uri: string().optional(),
34
- state: string()
35
- });
23
+ error: options([
24
+ "invalid_request",
25
+ "unauthorized_client",
26
+ "access_denied",
27
+ "unsupported_response_type",
28
+ "invalid_scope",
29
+ "server_error",
30
+ "temporarily_unavailable",
31
+ ]),
32
+ error_description: string().optional(),
33
+ error_uri: string().optional(),
34
+ state: string(),
35
+ })
36
36
  var OAuthAccessToken = OAuthProviderConfigSchema.extend({
37
- redirectURI: string(),
38
- code: string(),
39
- codeVerifier: string().min(43).max(128)
40
- });
37
+ redirectURI: string(),
38
+ code: string(),
39
+ codeVerifier: string().min(43).max(128),
40
+ })
41
41
  var OAuthAccessTokenResponse = object({
42
- access_token: string(),
43
- token_type: string(),
44
- expires_in: number().optional(),
45
- refresh_token: string().optional(),
46
- scope: string().optional()
47
- });
42
+ access_token: string(),
43
+ token_type: string(),
44
+ expires_in: number().optional(),
45
+ refresh_token: string().optional(),
46
+ scope: string().optional(),
47
+ })
48
48
  var OAuthAccessTokenErrorResponse = object({
49
- error: options([
50
- "invalid_request",
51
- "invalid_client",
52
- "invalid_grant",
53
- "unauthorized_client",
54
- "unsupported_grant_type",
55
- "invalid_scope"
56
- ]),
57
- error_description: string().optional(),
58
- error_uri: string().optional()
59
- });
49
+ error: options([
50
+ "invalid_request",
51
+ "invalid_client",
52
+ "invalid_grant",
53
+ "unauthorized_client",
54
+ "unsupported_grant_type",
55
+ "invalid_scope",
56
+ ]),
57
+ error_description: string().optional(),
58
+ error_uri: string().optional(),
59
+ })
60
60
  var OAuthErrorResponse = object({
61
- error: string(),
62
- error_description: string().optional()
63
- });
61
+ error: string(),
62
+ error_description: string().optional(),
63
+ })
64
64
 
65
65
  export {
66
- OAuthProviderConfigSchema,
67
- OAuthAuthorization,
68
- OAuthAuthorizationResponse,
69
- OAuthAuthorizationErrorResponse,
70
- OAuthAccessToken,
71
- OAuthAccessTokenResponse,
72
- OAuthAccessTokenErrorResponse,
73
- OAuthErrorResponse
74
- };
66
+ OAuthProviderConfigSchema,
67
+ OAuthAuthorization,
68
+ OAuthAuthorizationResponse,
69
+ OAuthAuthorizationErrorResponse,
70
+ OAuthAccessToken,
71
+ OAuthAccessTokenResponse,
72
+ OAuthAccessTokenErrorResponse,
73
+ OAuthErrorResponse,
74
+ }
@@ -1,14 +1,12 @@
1
1
  // src/oauth/github.ts
2
2
  var github = {
3
- id: "github",
4
- name: "GitHub",
5
- authorizeURL: "https://github.com/login/oauth/authorize",
6
- accessToken: "https://github.com/login/oauth/access_token",
7
- userInfo: "https://api.github.com/user",
8
- scope: "read:user user:email",
9
- responseType: "code"
10
- };
3
+ id: "github",
4
+ name: "GitHub",
5
+ authorizeURL: "https://github.com/login/oauth/authorize",
6
+ accessToken: "https://github.com/login/oauth/access_token",
7
+ userInfo: "https://api.github.com/user",
8
+ scope: "read:user user:email",
9
+ responseType: "code",
10
+ }
11
11
 
12
- export {
13
- github
14
- };
12
+ export { github }
@@ -1,10 +1,8 @@
1
1
  // src/response.ts
2
2
  var AuraResponse = class extends Response {
3
- static json(body, init) {
4
- return Response.json(body, init);
5
- }
6
- };
3
+ static json(body, init) {
4
+ return Response.json(body, init)
5
+ }
6
+ }
7
7
 
8
- export {
9
- AuraResponse
10
- };
8
+ export { AuraResponse }
@@ -1,22 +1,20 @@
1
1
  // src/oauth/gitlab.ts
2
2
  var gitlab = {
3
- id: "gitlab",
4
- name: "GitLab",
5
- authorizeURL: "https://gitlab.com/oauth/authorize",
6
- accessToken: "https://gitlab.com/oauth/token",
7
- userInfo: "https://gitlab.com/api/v4/user",
8
- scope: "read_user",
9
- responseType: "code",
10
- profile(profile) {
11
- return {
12
- sub: profile.id.toString(),
13
- name: profile.name ?? profile.username,
14
- email: profile.email,
15
- avatar: profile.avatar_url
16
- };
17
- }
18
- };
3
+ id: "gitlab",
4
+ name: "GitLab",
5
+ authorizeURL: "https://gitlab.com/oauth/authorize",
6
+ accessToken: "https://gitlab.com/oauth/token",
7
+ userInfo: "https://gitlab.com/api/v4/user",
8
+ scope: "read_user",
9
+ responseType: "code",
10
+ profile(profile) {
11
+ return {
12
+ sub: profile.id.toString(),
13
+ name: profile.name ?? profile.username,
14
+ email: profile.email,
15
+ avatar: profile.avatar_url,
16
+ }
17
+ },
18
+ }
19
19
 
20
- export {
21
- gitlab
22
- };
20
+ export { gitlab }
@@ -1,96 +1,75 @@
1
- import {
2
- createAuthorizationURL,
3
- createRedirectTo,
4
- createRedirectURI
5
- } from "./chunk-CAKJT3KS.js";
6
- import {
7
- oauthCookie,
8
- secureCookieOptions,
9
- setCookie
10
- } from "./chunk-ZV4BH47P.js";
11
- import {
12
- createPKCE,
13
- generateSecure
14
- } from "./chunk-GZU3RBTB.js";
15
- import {
16
- ERROR_RESPONSE,
17
- isAuthError
18
- } from "./chunk-FJUDBLCP.js";
19
- import {
20
- AuraResponse
21
- } from "./chunk-JAPMIE6S.js";
1
+ import { createAuthorizationURL, createRedirectTo, createRedirectURI } from "./chunk-CAKJT3KS.js"
2
+ import { oauthCookie, secureCookieOptions, setCookie } from "./chunk-ZV4BH47P.js"
3
+ import { createPKCE, generateSecure } from "./chunk-GZU3RBTB.js"
4
+ import { ERROR_RESPONSE, isAuthError } from "./chunk-FJUDBLCP.js"
5
+ import { AuraResponse } from "./chunk-JAPMIE6S.js"
22
6
 
23
7
  // src/actions/signIn/signIn.ts
24
- import z from "zod";
25
- import { createEndpoint, createEndpointConfig, statusCode } from "@aura-stack/router";
8
+ import z from "zod"
9
+ import { createEndpoint, createEndpointConfig, statusCode } from "@aura-stack/router"
26
10
  var signInConfig = (oauth) => {
27
- return createEndpointConfig("/signIn/:oauth", {
28
- schemas: {
29
- params: z.object({
30
- oauth: z.enum(Object.keys(oauth)),
31
- redirectTo: z.string().optional()
32
- })
33
- }
34
- });
35
- };
11
+ return createEndpointConfig("/signIn/:oauth", {
12
+ schemas: {
13
+ params: z.object({
14
+ oauth: z.enum(Object.keys(oauth)),
15
+ redirectTo: z.string().optional(),
16
+ }),
17
+ },
18
+ })
19
+ }
36
20
  var signInAction = (oauth) => {
37
- return createEndpoint(
38
- "GET",
39
- "/signIn/:oauth",
40
- async (ctx) => {
41
- const {
42
- request,
43
- params: { oauth: oauth2, redirectTo },
44
- context: { oauth: providers, cookies, trustedProxyHeaders, basePath }
45
- } = ctx;
46
- try {
47
- const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders);
48
- const state = generateSecure();
49
- const redirectURI = createRedirectURI(request, oauth2, basePath, trustedProxyHeaders);
50
- const stateCookie = setCookie("state", state, oauthCookie(cookieOptions));
51
- const redirectURICookie = setCookie("redirect_uri", redirectURI, oauthCookie(cookieOptions));
52
- const redirectToCookie = setCookie(
53
- "redirect_to",
54
- createRedirectTo(request, redirectTo, trustedProxyHeaders),
55
- oauthCookie(cookieOptions)
56
- );
57
- const { codeVerifier, codeChallenge, method } = await createPKCE();
58
- const codeVerifierCookie = setCookie("code_verifier", codeVerifier, oauthCookie(cookieOptions));
59
- const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method);
60
- const headers = new Headers();
61
- headers.set("Location", authorization);
62
- headers.append("Set-Cookie", stateCookie);
63
- headers.append("Set-Cookie", redirectURICookie);
64
- headers.append("Set-Cookie", redirectToCookie);
65
- headers.append("Set-Cookie", codeVerifierCookie);
66
- return Response.json(
67
- { oauth: oauth2 },
68
- {
69
- status: 302,
70
- headers
71
- }
72
- );
73
- } catch (error) {
74
- if (isAuthError(error)) {
75
- const { type, message } = error;
76
- return AuraResponse.json(
77
- { error: type, error_description: message },
78
- { status: statusCode.BAD_REQUEST }
79
- );
80
- }
81
- return AuraResponse.json(
82
- {
83
- error: ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR,
84
- error_description: "An unexpected error occurred"
85
- },
86
- { status: statusCode.INTERNAL_SERVER_ERROR }
87
- );
88
- }
89
- },
90
- signInConfig(oauth)
91
- );
92
- };
21
+ return createEndpoint(
22
+ "GET",
23
+ "/signIn/:oauth",
24
+ async (ctx) => {
25
+ const {
26
+ request,
27
+ params: { oauth: oauth2, redirectTo },
28
+ context: { oauth: providers, cookies, trustedProxyHeaders, basePath },
29
+ } = ctx
30
+ try {
31
+ const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders)
32
+ const state = generateSecure()
33
+ const redirectURI = createRedirectURI(request, oauth2, basePath, trustedProxyHeaders)
34
+ const stateCookie = setCookie("state", state, oauthCookie(cookieOptions))
35
+ const redirectURICookie = setCookie("redirect_uri", redirectURI, oauthCookie(cookieOptions))
36
+ const redirectToCookie = setCookie(
37
+ "redirect_to",
38
+ createRedirectTo(request, redirectTo, trustedProxyHeaders),
39
+ oauthCookie(cookieOptions)
40
+ )
41
+ const { codeVerifier, codeChallenge, method } = await createPKCE()
42
+ const codeVerifierCookie = setCookie("code_verifier", codeVerifier, oauthCookie(cookieOptions))
43
+ const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method)
44
+ const headers = new Headers()
45
+ headers.set("Location", authorization)
46
+ headers.append("Set-Cookie", stateCookie)
47
+ headers.append("Set-Cookie", redirectURICookie)
48
+ headers.append("Set-Cookie", redirectToCookie)
49
+ headers.append("Set-Cookie", codeVerifierCookie)
50
+ return Response.json(
51
+ { oauth: oauth2 },
52
+ {
53
+ status: 302,
54
+ headers,
55
+ }
56
+ )
57
+ } catch (error) {
58
+ if (isAuthError(error)) {
59
+ const { type, message } = error
60
+ return AuraResponse.json({ error: type, error_description: message }, { status: statusCode.BAD_REQUEST })
61
+ }
62
+ return AuraResponse.json(
63
+ {
64
+ error: ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR,
65
+ error_description: "An unexpected error occurred",
66
+ },
67
+ { status: statusCode.INTERNAL_SERVER_ERROR }
68
+ )
69
+ }
70
+ },
71
+ signInConfig(oauth)
72
+ )
73
+ }
93
74
 
94
- export {
95
- signInAction
96
- };
75
+ export { signInAction }
@@ -1,45 +1,36 @@
1
- import {
2
- generateSecure
3
- } from "./chunk-GZU3RBTB.js";
4
- import {
5
- AuthError,
6
- throwAuthError
7
- } from "./chunk-FJUDBLCP.js";
8
- import {
9
- OAuthErrorResponse
10
- } from "./chunk-HMRKN75I.js";
1
+ import { generateSecure } from "./chunk-GZU3RBTB.js"
2
+ import { AuthError, throwAuthError } from "./chunk-FJUDBLCP.js"
3
+ import { OAuthErrorResponse } from "./chunk-HMRKN75I.js"
11
4
 
12
5
  // src/actions/callback/userinfo.ts
13
6
  var getDefaultUserInfo = (profile) => {
14
- const sub = generateSecure(16);
15
- return {
16
- sub: profile?.id ?? profile?.sub ?? sub,
17
- email: profile?.email,
18
- name: profile?.name ?? profile?.username ?? profile?.nickname,
19
- image: profile?.image ?? profile?.picture
20
- };
21
- };
7
+ const sub = generateSecure(16)
8
+ return {
9
+ sub: profile?.id ?? profile?.sub ?? sub,
10
+ email: profile?.email,
11
+ name: profile?.name ?? profile?.username ?? profile?.nickname,
12
+ image: profile?.image ?? profile?.picture,
13
+ }
14
+ }
22
15
  var getUserInfo = async (oauthConfig, accessToken) => {
23
- const userinfoEndpoint = oauthConfig.userInfo;
24
- try {
25
- const response = await fetch(userinfoEndpoint, {
26
- method: "GET",
27
- headers: {
28
- Accept: "application/json",
29
- Authorization: `Bearer ${accessToken}`
30
- }
31
- });
32
- const json = await response.json();
33
- const { success, data } = OAuthErrorResponse.safeParse(json);
34
- if (success) {
35
- throw new AuthError(data.error, data?.error_description ?? "An error occurred while fetching user information.");
16
+ const userinfoEndpoint = oauthConfig.userInfo
17
+ try {
18
+ const response = await fetch(userinfoEndpoint, {
19
+ method: "GET",
20
+ headers: {
21
+ Accept: "application/json",
22
+ Authorization: `Bearer ${accessToken}`,
23
+ },
24
+ })
25
+ const json = await response.json()
26
+ const { success, data } = OAuthErrorResponse.safeParse(json)
27
+ if (success) {
28
+ throw new AuthError(data.error, data?.error_description ?? "An error occurred while fetching user information.")
29
+ }
30
+ return oauthConfig?.profile ? oauthConfig.profile(json) : getDefaultUserInfo(json)
31
+ } catch (error) {
32
+ throw throwAuthError(error, "Failed to retrieve userinfo")
36
33
  }
37
- return oauthConfig?.profile ? oauthConfig.profile(json) : getDefaultUserInfo(json);
38
- } catch (error) {
39
- throw throwAuthError(error, "Failed to retrieve userinfo");
40
- }
41
- };
34
+ }
42
35
 
43
- export {
44
- getUserInfo
45
- };
36
+ export { getUserInfo }