@aura-stack/auth 0.1.0-rc.8 → 0.1.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 (116) hide show
  1. package/dist/@types/index.cjs +15 -15
  2. package/dist/@types/index.d.ts +7 -31
  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 +15 -20
  11. package/dist/actions/callback/access-token.js +8 -4
  12. package/dist/actions/callback/callback.cjs +437 -455
  13. package/dist/actions/callback/callback.d.ts +10 -12
  14. package/dist/actions/callback/callback.js +16 -12
  15. package/dist/actions/callback/userinfo.cjs +131 -134
  16. package/dist/actions/callback/userinfo.d.ts +9 -9
  17. package/dist/actions/callback/userinfo.js +10 -6
  18. package/dist/actions/csrfToken/csrfToken.cjs +162 -171
  19. package/dist/actions/csrfToken/csrfToken.d.ts +3 -3
  20. package/dist/actions/csrfToken/csrfToken.js +12 -8
  21. package/dist/actions/index.cjs +746 -773
  22. package/dist/actions/index.d.ts +13 -13
  23. package/dist/actions/index.js +34 -18
  24. package/dist/actions/session/session.cjs +149 -155
  25. package/dist/actions/session/session.d.ts +3 -3
  26. package/dist/actions/session/session.js +11 -7
  27. package/dist/actions/signIn/authorization.cjs +231 -249
  28. package/dist/actions/signIn/authorization.d.ts +12 -18
  29. package/dist/actions/signIn/authorization.js +16 -6
  30. package/dist/actions/signIn/signIn.cjs +396 -423
  31. package/dist/actions/signIn/signIn.d.ts +10 -10
  32. package/dist/actions/signIn/signIn.js +14 -10
  33. package/dist/actions/signOut/signOut.cjs +417 -440
  34. package/dist/actions/signOut/signOut.d.ts +3 -3
  35. package/dist/actions/signOut/signOut.js +15 -11
  36. package/dist/assert.cjs +35 -36
  37. package/dist/assert.d.ts +4 -4
  38. package/dist/assert.js +10 -2
  39. package/dist/chunk-256KIVJL.js +85 -96
  40. package/dist/chunk-42XB3YCW.js +19 -17
  41. package/dist/chunk-6SM22VVJ.js +13 -10
  42. package/dist/chunk-CAKJT3KS.js +84 -69
  43. package/dist/chunk-E3OXBRYF.js +19 -17
  44. package/dist/chunk-EBPE35JT.js +28 -26
  45. package/dist/chunk-FIPU4MLT.js +18 -16
  46. package/dist/chunk-FJUDBLCP.js +50 -43
  47. package/dist/chunk-FKRDCWBF.js +19 -17
  48. package/dist/chunk-GZU3RBTB.js +51 -40
  49. package/dist/chunk-HGJ4TXY4.js +132 -100
  50. package/dist/chunk-HMRKN75I.js +63 -63
  51. package/dist/chunk-IKHPGFCW.js +11 -9
  52. package/dist/chunk-JAPMIE6S.js +7 -5
  53. package/dist/chunk-KRNOMBXQ.js +19 -17
  54. package/dist/chunk-LLR722CL.js +91 -70
  55. package/dist/chunk-RLT4RFKV.js +39 -30
  56. package/dist/chunk-SJPDVKUS.js +107 -88
  57. package/dist/chunk-SMQO5WD7.js +26 -16
  58. package/dist/chunk-STHEPPUZ.js +8 -6
  59. package/dist/chunk-UJJ7R56J.js +47 -37
  60. package/dist/chunk-UTDLUEEG.js +27 -21
  61. package/dist/chunk-VFTYH33W.js +54 -37
  62. package/dist/chunk-XXJKNKGQ.js +33 -23
  63. package/dist/chunk-ZV4BH47P.js +132 -134
  64. package/dist/cookie.cjs +169 -175
  65. package/dist/cookie.d.ts +23 -51
  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 +15 -8
  70. package/dist/headers.cjs +28 -28
  71. package/dist/headers.d.ts +2 -2
  72. package/dist/headers.js +6 -2
  73. package/dist/index-DpfbvTZ_.d.ts +249 -298
  74. package/dist/index.cjs +936 -969
  75. package/dist/index.d.ts +10 -31
  76. package/dist/index.js +70 -50
  77. package/dist/jose.cjs +61 -64
  78. package/dist/jose.d.ts +8 -8
  79. package/dist/jose.js +9 -5
  80. package/dist/oauth/bitbucket.cjs +38 -38
  81. package/dist/oauth/bitbucket.d.ts +7 -7
  82. package/dist/oauth/bitbucket.js +6 -2
  83. package/dist/oauth/discord.cjs +48 -48
  84. package/dist/oauth/discord.d.ts +7 -7
  85. package/dist/oauth/discord.js +6 -2
  86. package/dist/oauth/figma.cjs +39 -39
  87. package/dist/oauth/figma.d.ts +7 -7
  88. package/dist/oauth/figma.js +6 -2
  89. package/dist/oauth/github.cjs +31 -31
  90. package/dist/oauth/github.d.ts +7 -7
  91. package/dist/oauth/github.js +6 -2
  92. package/dist/oauth/gitlab.cjs +39 -39
  93. package/dist/oauth/gitlab.d.ts +7 -7
  94. package/dist/oauth/gitlab.js +6 -2
  95. package/dist/oauth/index.cjs +180 -180
  96. package/dist/oauth/index.d.ts +7 -26
  97. package/dist/oauth/index.js +36 -9
  98. package/dist/oauth/spotify.cjs +39 -39
  99. package/dist/oauth/spotify.d.ts +7 -7
  100. package/dist/oauth/spotify.js +6 -2
  101. package/dist/oauth/x.cjs +39 -39
  102. package/dist/oauth/x.d.ts +7 -7
  103. package/dist/oauth/x.js +6 -2
  104. package/dist/response.cjs +27 -27
  105. package/dist/response.d.ts +2 -2
  106. package/dist/response.js +6 -2
  107. package/dist/schemas.cjs +91 -91
  108. package/dist/schemas.d.ts +93 -126
  109. package/dist/schemas.js +18 -18
  110. package/dist/secure.cjs +95 -98
  111. package/dist/secure.d.ts +17 -17
  112. package/dist/secure.js +18 -4
  113. package/dist/utils.cjs +119 -132
  114. package/dist/utils.d.ts +11 -26
  115. package/dist/utils.js +21 -21
  116. package/package.json +2 -2
@@ -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,12 +1,14 @@
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 { github }
12
+ export {
13
+ github
14
+ };
@@ -1,8 +1,10 @@
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 { AuraResponse }
8
+ export {
9
+ AuraResponse
10
+ };
@@ -1,20 +1,22 @@
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 { gitlab }
20
+ export {
21
+ gitlab
22
+ };
@@ -1,75 +1,96 @@
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"
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";
6
22
 
7
23
  // src/actions/signIn/signIn.ts
8
- import z from "zod"
9
- import { createEndpoint, createEndpointConfig, statusCode } from "@aura-stack/router"
24
+ import z from "zod";
25
+ import { createEndpoint, createEndpointConfig, statusCode } from "@aura-stack/router";
10
26
  var signInConfig = (oauth) => {
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
- }
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
+ };
20
36
  var signInAction = (oauth) => {
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
- }
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
+ };
74
93
 
75
- export { signInAction }
94
+ export {
95
+ signInAction
96
+ };
@@ -1,36 +1,45 @@
1
- import { generateSecure } from "./chunk-GZU3RBTB.js"
2
- import { AuthError, throwAuthError } from "./chunk-FJUDBLCP.js"
3
- import { OAuthErrorResponse } from "./chunk-HMRKN75I.js"
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";
4
11
 
5
12
  // src/actions/callback/userinfo.ts
6
13
  var getDefaultUserInfo = (profile) => {
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
- }
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
+ };
15
22
  var getUserInfo = async (oauthConfig, accessToken) => {
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")
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.");
33
36
  }
34
- }
37
+ return oauthConfig?.profile ? oauthConfig.profile(json) : getDefaultUserInfo(json);
38
+ } catch (error) {
39
+ throw throwAuthError(error, "Failed to retrieve userinfo");
40
+ }
41
+ };
35
42
 
36
- export { getUserInfo }
43
+ export {
44
+ getUserInfo
45
+ };