@aura-stack/auth 0.1.0-rc.9 → 0.2.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/dist/@types/index.cjs +15 -15
  2. package/dist/@types/index.d.ts +6 -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 +6 -7
  6. package/dist/@types/utility.cjs +15 -15
  7. package/dist/@types/utility.d.ts +4 -8
  8. package/dist/@types/utility.js +1 -1
  9. package/dist/actions/callback/access-token.cjs +159 -149
  10. package/dist/actions/callback/access-token.d.ts +14 -20
  11. package/dist/actions/callback/access-token.js +9 -4
  12. package/dist/actions/callback/callback.cjs +371 -484
  13. package/dist/actions/callback/callback.d.ts +9 -12
  14. package/dist/actions/callback/callback.js +15 -12
  15. package/dist/actions/callback/userinfo.cjs +149 -139
  16. package/dist/actions/callback/userinfo.d.ts +8 -9
  17. package/dist/actions/callback/userinfo.js +11 -6
  18. package/dist/actions/csrfToken/csrfToken.cjs +112 -190
  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 +623 -807
  22. package/dist/actions/index.d.ts +12 -13
  23. package/dist/actions/index.js +33 -18
  24. package/dist/actions/session/session.cjs +86 -176
  25. package/dist/actions/session/session.d.ts +3 -3
  26. package/dist/actions/session/session.js +10 -7
  27. package/dist/actions/signIn/authorization.cjs +248 -257
  28. package/dist/actions/signIn/authorization.d.ts +11 -18
  29. package/dist/actions/signIn/authorization.js +16 -6
  30. package/dist/actions/signIn/signIn.cjs +302 -451
  31. package/dist/actions/signIn/signIn.d.ts +9 -10
  32. package/dist/actions/signIn/signIn.js +12 -10
  33. package/dist/actions/signOut/signOut.cjs +299 -468
  34. package/dist/actions/signOut/signOut.d.ts +3 -3
  35. package/dist/actions/signOut/signOut.js +14 -11
  36. package/dist/assert.cjs +40 -36
  37. package/dist/assert.d.ts +12 -4
  38. package/dist/assert.js +12 -2
  39. package/dist/chunk-2RXNXMCZ.js +55 -0
  40. package/dist/chunk-42XB3YCW.js +19 -17
  41. package/dist/chunk-4V4JNXVF.js +55 -0
  42. package/dist/chunk-6R2YZ4AC.js +22 -0
  43. package/dist/chunk-7H3OR6UU.js +81 -0
  44. package/dist/chunk-CXLATHS5.js +143 -0
  45. package/dist/chunk-E3OXBRYF.js +19 -17
  46. package/dist/chunk-EIL2FPSS.js +22 -0
  47. package/dist/chunk-FIPU4MLT.js +18 -16
  48. package/dist/chunk-FKRDCWBF.js +19 -17
  49. package/dist/chunk-IKHPGFCW.js +11 -9
  50. package/dist/chunk-IMICRJ5U.js +197 -0
  51. package/dist/chunk-IUYZQTJV.js +30 -0
  52. package/dist/chunk-KRNOMBXQ.js +19 -17
  53. package/dist/chunk-N2APGLXA.js +71 -0
  54. package/dist/chunk-NEVKX6K2.js +70 -0
  55. package/dist/chunk-PTJUYB33.js +33 -0
  56. package/dist/chunk-QDO2KSRJ.js +35 -0
  57. package/dist/chunk-QEZL7EYN.js +96 -0
  58. package/dist/chunk-RRLIF4PQ.js +55 -0
  59. package/dist/chunk-STHEPPUZ.js +8 -6
  60. package/dist/chunk-TLE4PXY3.js +39 -0
  61. package/dist/chunk-UEH3LVON.js +97 -0
  62. package/dist/chunk-WD7AUHQ5.js +79 -0
  63. package/dist/chunk-ZLR3LI6X.js +55 -0
  64. package/dist/cookie.cjs +222 -187
  65. package/dist/cookie.d.ts +38 -76
  66. package/dist/cookie.js +27 -34
  67. package/dist/errors.cjs +85 -0
  68. package/dist/errors.d.ts +48 -0
  69. package/dist/errors.js +18 -0
  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 → index-EqsoyjrF.d.ts} +351 -318
  74. package/dist/index.cjs +1006 -1001
  75. package/dist/index.d.ts +9 -31
  76. package/dist/index.js +82 -51
  77. package/dist/jose.cjs +74 -66
  78. package/dist/jose.d.ts +11 -8
  79. package/dist/jose.js +10 -5
  80. package/dist/oauth/bitbucket.cjs +38 -38
  81. package/dist/oauth/bitbucket.d.ts +6 -7
  82. package/dist/oauth/bitbucket.js +6 -2
  83. package/dist/oauth/discord.cjs +47 -48
  84. package/dist/oauth/discord.d.ts +6 -7
  85. package/dist/oauth/discord.js +6 -2
  86. package/dist/oauth/figma.cjs +39 -39
  87. package/dist/oauth/figma.d.ts +6 -7
  88. package/dist/oauth/figma.js +6 -2
  89. package/dist/oauth/github.cjs +31 -31
  90. package/dist/oauth/github.d.ts +6 -7
  91. package/dist/oauth/github.js +6 -2
  92. package/dist/oauth/gitlab.cjs +39 -39
  93. package/dist/oauth/gitlab.d.ts +6 -7
  94. package/dist/oauth/gitlab.js +6 -2
  95. package/dist/oauth/index.cjs +306 -180
  96. package/dist/oauth/index.d.ts +6 -26
  97. package/dist/oauth/index.js +43 -9
  98. package/dist/oauth/spotify.cjs +39 -39
  99. package/dist/oauth/spotify.d.ts +6 -7
  100. package/dist/oauth/spotify.js +6 -2
  101. package/dist/oauth/strava.cjs +46 -0
  102. package/dist/oauth/strava.d.ts +6 -0
  103. package/dist/oauth/strava.js +6 -0
  104. package/dist/oauth/x.cjs +39 -39
  105. package/dist/oauth/x.d.ts +6 -7
  106. package/dist/oauth/x.js +6 -2
  107. package/dist/schemas.cjs +97 -91
  108. package/dist/schemas.d.ts +96 -126
  109. package/dist/schemas.js +20 -18
  110. package/dist/secure.cjs +106 -101
  111. package/dist/secure.d.ts +16 -17
  112. package/dist/secure.js +19 -4
  113. package/dist/utils.cjs +197 -135
  114. package/dist/utils.d.ts +20 -26
  115. package/dist/utils.js +25 -21
  116. package/package.json +5 -6
  117. package/dist/chunk-256KIVJL.js +0 -110
  118. package/dist/chunk-6SM22VVJ.js +0 -15
  119. package/dist/chunk-CAKJT3KS.js +0 -77
  120. package/dist/chunk-EBPE35JT.js +0 -29
  121. package/dist/chunk-FJUDBLCP.js +0 -52
  122. package/dist/chunk-GZU3RBTB.js +0 -51
  123. package/dist/chunk-HGJ4TXY4.js +0 -105
  124. package/dist/chunk-HMRKN75I.js +0 -74
  125. package/dist/chunk-JAPMIE6S.js +0 -8
  126. package/dist/chunk-LLR722CL.js +0 -75
  127. package/dist/chunk-RLT4RFKV.js +0 -36
  128. package/dist/chunk-SJPDVKUS.js +0 -93
  129. package/dist/chunk-SMQO5WD7.js +0 -20
  130. package/dist/chunk-UJJ7R56J.js +0 -42
  131. package/dist/chunk-UTDLUEEG.js +0 -25
  132. package/dist/chunk-VFTYH33W.js +0 -44
  133. package/dist/chunk-XXJKNKGQ.js +0 -27
  134. package/dist/chunk-ZV4BH47P.js +0 -156
  135. package/dist/error.cjs +0 -88
  136. package/dist/error.d.ts +0 -62
  137. package/dist/error.js +0 -9
  138. package/dist/response.cjs +0 -34
  139. package/dist/response.d.ts +0 -10
  140. package/dist/response.js +0 -2
@@ -1,8 +1,8 @@
1
- import * as _aura_stack_router from "@aura-stack/router"
1
+ import * as _aura_stack_router from '@aura-stack/router';
2
2
 
3
3
  /**
4
4
  * @see https://datatracker.ietf.org/doc/html/rfc7009
5
5
  */
6
- declare const signOutAction: _aura_stack_router.RouteEndpoint<"POST", "/signOut", {}>
6
+ declare const signOutAction: _aura_stack_router.RouteEndpoint<"POST", "/signOut", {}>;
7
7
 
8
- export { signOutAction }
8
+ export { signOutAction };
@@ -1,11 +1,14 @@
1
- import { signOutAction } from "../../chunk-SJPDVKUS.js"
2
- import "../../chunk-CAKJT3KS.js"
3
- import "../../chunk-ZV4BH47P.js"
4
- import "../../chunk-6SM22VVJ.js"
5
- import "../../chunk-STHEPPUZ.js"
6
- import "../../chunk-GZU3RBTB.js"
7
- import "../../chunk-256KIVJL.js"
8
- import "../../chunk-FJUDBLCP.js"
9
- import "../../chunk-JAPMIE6S.js"
10
- import "../../chunk-HMRKN75I.js"
11
- export { signOutAction }
1
+ import {
2
+ signOutAction
3
+ } from "../../chunk-NEVKX6K2.js";
4
+ import "../../chunk-QEZL7EYN.js";
5
+ import "../../chunk-IMICRJ5U.js";
6
+ import "../../chunk-STHEPPUZ.js";
7
+ import "../../chunk-WD7AUHQ5.js";
8
+ import "../../chunk-N2APGLXA.js";
9
+ import "../../chunk-CXLATHS5.js";
10
+ import "../../chunk-EIL2FPSS.js";
11
+ import "../../chunk-RRLIF4PQ.js";
12
+ export {
13
+ signOutAction
14
+ };
package/dist/assert.cjs CHANGED
@@ -1,45 +1,49 @@
1
- "use strict"
2
- var __defProp = Object.defineProperty
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor
4
- var __getOwnPropNames = Object.getOwnPropertyNames
5
- var __hasOwnProp = Object.prototype.hasOwnProperty
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __export = (target, all) => {
7
- for (var name in all) __defProp(target, name, { get: all[name], enumerable: true })
8
- }
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
9
10
  var __copyProps = (to, from, except, desc) => {
10
- if ((from && typeof from === "object") || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable })
14
- }
15
- return to
16
- }
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod)
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
19
 
19
20
  // src/assert.ts
20
- var assert_exports = {}
21
+ var assert_exports = {};
21
22
  __export(assert_exports, {
22
- isFalsy: () => isFalsy,
23
- isRequest: () => isRequest,
24
- isValidURL: () => isValidURL,
25
- })
26
- module.exports = __toCommonJS(assert_exports)
23
+ isFalsy: () => isFalsy,
24
+ isJWTPayloadWithToken: () => isJWTPayloadWithToken,
25
+ isRequest: () => isRequest,
26
+ isValidURL: () => isValidURL
27
+ });
28
+ module.exports = __toCommonJS(assert_exports);
27
29
  var isFalsy = (value) => {
28
- return value === false || value === 0 || value === "" || value === null || value === void 0 || Number.isNaN(value)
29
- }
30
+ return value === false || value === 0 || value === "" || value === null || value === void 0 || Number.isNaN(value);
31
+ };
30
32
  var isRequest = (value) => {
31
- return typeof Request !== "undefined" && value instanceof Request
32
- }
33
+ return typeof Request !== "undefined" && value instanceof Request;
34
+ };
33
35
  var isValidURL = (value) => {
34
- if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false
35
- const regex =
36
- /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/
37
- return regex.test(value)
38
- }
36
+ if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false;
37
+ const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/;
38
+ return regex.test(value);
39
+ };
40
+ var isJWTPayloadWithToken = (payload) => {
41
+ return typeof payload === "object" && payload !== null && "token" in payload && typeof payload?.token === "string";
42
+ };
39
43
  // Annotate the CommonJS export names for ESM import in node:
40
- 0 &&
41
- (module.exports = {
42
- isFalsy,
43
- isRequest,
44
- isValidURL,
45
- })
44
+ 0 && (module.exports = {
45
+ isFalsy,
46
+ isJWTPayloadWithToken,
47
+ isRequest,
48
+ isValidURL
49
+ });
package/dist/assert.d.ts CHANGED
@@ -1,5 +1,13 @@
1
- declare const isFalsy: (value: unknown) => boolean
2
- declare const isRequest: (value: unknown) => value is Request
3
- declare const isValidURL: (value: string) => boolean
1
+ import { J as JWTPayloadWithToken } from './index-EqsoyjrF.js';
2
+ import 'zod/v4';
3
+ import './schemas.js';
4
+ import '@aura-stack/router/cookie';
5
+ import '@aura-stack/jose/jose';
6
+ import './@types/utility.js';
4
7
 
5
- export { isFalsy, isRequest, isValidURL }
8
+ declare const isFalsy: (value: unknown) => boolean;
9
+ declare const isRequest: (value: unknown) => value is Request;
10
+ declare const isValidURL: (value: string) => boolean;
11
+ declare const isJWTPayloadWithToken: (payload: unknown) => payload is JWTPayloadWithToken;
12
+
13
+ export { isFalsy, isJWTPayloadWithToken, isRequest, isValidURL };
package/dist/assert.js CHANGED
@@ -1,2 +1,12 @@
1
- import { isFalsy, isRequest, isValidURL } from "./chunk-6SM22VVJ.js"
2
- export { isFalsy, isRequest, isValidURL }
1
+ import {
2
+ isFalsy,
3
+ isJWTPayloadWithToken,
4
+ isRequest,
5
+ isValidURL
6
+ } from "./chunk-EIL2FPSS.js";
7
+ export {
8
+ isFalsy,
9
+ isJWTPayloadWithToken,
10
+ isRequest,
11
+ isValidURL
12
+ };
@@ -0,0 +1,55 @@
1
+ import {
2
+ createAuthorizationURL,
3
+ createRedirectTo,
4
+ createRedirectURI
5
+ } from "./chunk-QEZL7EYN.js";
6
+ import {
7
+ createPKCE,
8
+ generateSecure
9
+ } from "./chunk-N2APGLXA.js";
10
+
11
+ // src/actions/signIn/signIn.ts
12
+ import z from "zod";
13
+ import { createEndpoint, createEndpointConfig } from "@aura-stack/router";
14
+ var signInConfig = (oauth) => {
15
+ return createEndpointConfig("/signIn/:oauth", {
16
+ schemas: {
17
+ params: z.object({
18
+ oauth: z.enum(Object.keys(oauth), "The OAuth provider is not supported or invalid."),
19
+ redirectTo: z.string().optional()
20
+ })
21
+ }
22
+ });
23
+ };
24
+ var signInAction = (oauth) => {
25
+ return createEndpoint(
26
+ "GET",
27
+ "/signIn/:oauth",
28
+ async (ctx) => {
29
+ const {
30
+ request,
31
+ headers: headersBuilder,
32
+ params: { oauth: oauth2, redirectTo },
33
+ context: { oauth: providers, cookies, trustedProxyHeaders, basePath }
34
+ } = ctx;
35
+ const state = generateSecure();
36
+ const redirectURI = createRedirectURI(request, oauth2, basePath, trustedProxyHeaders);
37
+ const redirectToValue = createRedirectTo(request, redirectTo, trustedProxyHeaders);
38
+ const { codeVerifier, codeChallenge, method } = await createPKCE();
39
+ const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method);
40
+ const headers = headersBuilder.setHeader("Location", authorization).setCookie(cookies.state.name, state, cookies.state.attributes).setCookie(cookies.redirect_uri.name, redirectURI, cookies.redirect_uri.attributes).setCookie(cookies.redirect_to.name, redirectToValue, cookies.redirect_to.attributes).setCookie(cookies.code_verifier.name, codeVerifier, cookies.code_verifier.attributes).toHeaders();
41
+ return Response.json(
42
+ { oauth: oauth2 },
43
+ {
44
+ status: 302,
45
+ headers
46
+ }
47
+ );
48
+ },
49
+ signInConfig(oauth)
50
+ );
51
+ };
52
+
53
+ export {
54
+ signInAction
55
+ };
@@ -1,20 +1,22 @@
1
1
  // src/oauth/x.ts
2
2
  var x = {
3
- id: "x",
4
- name: "X",
5
- authorizeURL: "https://x.com/i/oauth2/authorize",
6
- accessToken: "https://api.x.com/2/oauth2/token",
7
- userInfo: "https://api.x.com/2/users/me?user.fields=profile_image_url",
8
- scope: "users.read users.email tweet.read offline.access",
9
- responseType: "code",
10
- profile({ data }) {
11
- return {
12
- sub: data.id,
13
- name: data.name,
14
- image: data.profile_image_url,
15
- email: "",
16
- }
17
- },
18
- }
3
+ id: "x",
4
+ name: "X",
5
+ authorizeURL: "https://x.com/i/oauth2/authorize",
6
+ accessToken: "https://api.x.com/2/oauth2/token",
7
+ userInfo: "https://api.x.com/2/users/me?user.fields=profile_image_url",
8
+ scope: "users.read users.email tweet.read offline.access",
9
+ responseType: "code",
10
+ profile({ data }) {
11
+ return {
12
+ sub: data.id,
13
+ name: data.name,
14
+ image: data.profile_image_url,
15
+ email: ""
16
+ };
17
+ }
18
+ };
19
19
 
20
- export { x }
20
+ export {
21
+ x
22
+ };
@@ -0,0 +1,55 @@
1
+ import {
2
+ OAuthAccessToken,
3
+ OAuthAccessTokenErrorResponse,
4
+ OAuthAccessTokenResponse
5
+ } from "./chunk-WD7AUHQ5.js";
6
+ import {
7
+ formatZodError
8
+ } from "./chunk-CXLATHS5.js";
9
+ import {
10
+ AuthInternalError,
11
+ OAuthProtocolError
12
+ } from "./chunk-RRLIF4PQ.js";
13
+
14
+ // src/actions/callback/access-token.ts
15
+ var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) => {
16
+ const parsed = OAuthAccessToken.safeParse({ ...oauthConfig, redirectURI, code, codeVerifier });
17
+ if (!parsed.success) {
18
+ const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
19
+ throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
20
+ }
21
+ const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data;
22
+ try {
23
+ const response = await fetch(accessToken, {
24
+ method: "POST",
25
+ headers: {
26
+ Accept: "application/json",
27
+ "Content-Type": "application/x-www-form-urlencoded"
28
+ },
29
+ body: new URLSearchParams({
30
+ client_id: clientId,
31
+ client_secret: clientSecret,
32
+ code: codeParsed,
33
+ redirect_uri: redirectParsed,
34
+ grant_type: "authorization_code",
35
+ code_verifier: codeVerifier
36
+ }).toString()
37
+ });
38
+ const json = await response.json();
39
+ const token = OAuthAccessTokenResponse.safeParse(json);
40
+ if (!token.success) {
41
+ const { success, data } = OAuthAccessTokenErrorResponse.safeParse(json);
42
+ if (!success) {
43
+ throw new OAuthProtocolError("INVALID_REQUEST", "Invalid access token response format");
44
+ }
45
+ throw new OAuthProtocolError(data.error, data?.error_description ?? "Failed to retrieve access token");
46
+ }
47
+ return token.data;
48
+ } catch (error) {
49
+ throw error;
50
+ }
51
+ };
52
+
53
+ export {
54
+ createAccessToken
55
+ };
@@ -0,0 +1,22 @@
1
+ // src/oauth/strava.ts
2
+ var strava = {
3
+ id: "strava",
4
+ name: "Strava",
5
+ authorizeURL: "https://www.strava.com/oauth/authorize",
6
+ accessToken: "https://www.strava.com/oauth/token",
7
+ userInfo: "https://www.strava.com/api/v3/athlete",
8
+ scope: "read",
9
+ responseType: "code",
10
+ profile(profile) {
11
+ return {
12
+ sub: profile.id.toString(),
13
+ name: `${profile.firstname} ${profile.lastname}`,
14
+ image: profile.profile,
15
+ email: ""
16
+ };
17
+ }
18
+ };
19
+
20
+ export {
21
+ strava
22
+ };
@@ -0,0 +1,81 @@
1
+ import {
2
+ github
3
+ } from "./chunk-IKHPGFCW.js";
4
+ import {
5
+ gitlab
6
+ } from "./chunk-KRNOMBXQ.js";
7
+ import {
8
+ spotify
9
+ } from "./chunk-E3OXBRYF.js";
10
+ import {
11
+ strava
12
+ } from "./chunk-6R2YZ4AC.js";
13
+ import {
14
+ x
15
+ } from "./chunk-42XB3YCW.js";
16
+ import {
17
+ bitbucket
18
+ } from "./chunk-FIPU4MLT.js";
19
+ import {
20
+ discord
21
+ } from "./chunk-IUYZQTJV.js";
22
+ import {
23
+ figma
24
+ } from "./chunk-FKRDCWBF.js";
25
+ import {
26
+ OAuthEnvSchema
27
+ } from "./chunk-WD7AUHQ5.js";
28
+ import {
29
+ formatZodError
30
+ } from "./chunk-CXLATHS5.js";
31
+ import {
32
+ AuthInternalError
33
+ } from "./chunk-RRLIF4PQ.js";
34
+
35
+ // src/oauth/index.ts
36
+ var builtInOAuthProviders = {
37
+ github,
38
+ bitbucket,
39
+ figma,
40
+ discord,
41
+ gitlab,
42
+ spotify,
43
+ x,
44
+ strava
45
+ };
46
+ var defineOAuthEnvironment = (oauth) => {
47
+ const env = process.env;
48
+ const clientIdSuffix = `${oauth.toUpperCase()}_CLIENT_ID`;
49
+ const clientSecretSuffix = `${oauth.toUpperCase()}_CLIENT_SECRET`;
50
+ const loadEnvs = OAuthEnvSchema.safeParse({
51
+ clientId: env[`AURA_AUTH_${clientIdSuffix}`] ?? env[`AUTH_${clientIdSuffix}`] ?? env[`${clientIdSuffix}`],
52
+ clientSecret: env[`AURA_AUTH_${clientSecretSuffix}`] ?? env[`AUTH_${clientSecretSuffix}`] ?? env[`${clientSecretSuffix}`]
53
+ });
54
+ if (!loadEnvs.success) {
55
+ const msg = JSON.stringify(formatZodError(loadEnvs.error), null, 2);
56
+ throw new AuthInternalError("INVALID_ENVIRONMENT_CONFIGURATION", msg);
57
+ }
58
+ return loadEnvs.data;
59
+ };
60
+ var defineOAuthProviderConfig = (config) => {
61
+ if (typeof config === "string") {
62
+ const definition = defineOAuthEnvironment(config);
63
+ const oauthConfig = builtInOAuthProviders[config];
64
+ return {
65
+ ...oauthConfig,
66
+ ...definition
67
+ };
68
+ }
69
+ return config;
70
+ };
71
+ var createBuiltInOAuthProviders = (oauth = []) => {
72
+ return oauth.reduce((previous, config) => {
73
+ const oauthConfig = defineOAuthProviderConfig(config);
74
+ return { ...previous, [oauthConfig.id]: oauthConfig };
75
+ }, {});
76
+ };
77
+
78
+ export {
79
+ builtInOAuthProviders,
80
+ createBuiltInOAuthProviders
81
+ };
@@ -0,0 +1,143 @@
1
+ import {
2
+ isAuthInternalError,
3
+ isAuthSecurityError,
4
+ isOAuthProtocolError
5
+ } from "./chunk-RRLIF4PQ.js";
6
+
7
+ // src/utils.ts
8
+ import { isInvalidZodSchemaError, isRouterError } from "@aura-stack/router";
9
+ var toSnakeCase = (str) => {
10
+ return str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/^_+/, "");
11
+ };
12
+ var toUpperCase = (str) => {
13
+ return str.toUpperCase();
14
+ };
15
+ var toCastCase = (obj, type = "snake") => {
16
+ return Object.entries(obj).reduce((previous, [key, value]) => {
17
+ const newKey = type === "snake" ? toSnakeCase(key) : toUpperCase(key);
18
+ return { ...previous, [newKey]: value };
19
+ }, {});
20
+ };
21
+ var equals = (a, b) => {
22
+ if (a === null || b === null || a === void 0 || b === void 0) return false;
23
+ return a === b;
24
+ };
25
+ var sanitizeURL = (url) => {
26
+ try {
27
+ let decodedURL = decodeURIComponent(url).trim();
28
+ const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
29
+ let protocol = "";
30
+ let rest = decodedURL;
31
+ if (protocolMatch) {
32
+ protocol = protocolMatch[1];
33
+ rest = decodedURL.slice(protocol.length);
34
+ const slashIndex = rest.indexOf("/");
35
+ if (slashIndex === -1) {
36
+ return protocol + rest;
37
+ }
38
+ const domain = rest.slice(0, slashIndex);
39
+ let path = rest.slice(slashIndex).replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
40
+ if (path !== "/" && path.endsWith("/")) {
41
+ path = path.replace(/\/+$/, "/");
42
+ } else if (path !== "/") {
43
+ path = path.replace(/\/+$/, "");
44
+ }
45
+ return protocol + domain + path;
46
+ }
47
+ let sanitized = decodedURL.replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
48
+ if (sanitized !== "/" && sanitized.endsWith("/")) {
49
+ sanitized = sanitized.replace(/\/+$/, "/");
50
+ } else if (sanitized !== "/") {
51
+ sanitized = sanitized.replace(/\/+$/, "");
52
+ }
53
+ return sanitized;
54
+ } catch {
55
+ return url.trim();
56
+ }
57
+ };
58
+ var isValidRelativePath = (path) => {
59
+ if (!path || typeof path !== "string") return false;
60
+ if (!path.startsWith("/") || path.includes("://") || path.includes("\r") || path.includes("\n")) return false;
61
+ if (/[\x00-\x1F\x7F]/.test(path) || path.includes("\0")) return false;
62
+ const sanitized = sanitizeURL(path);
63
+ if (sanitized.includes("..")) return false;
64
+ return true;
65
+ };
66
+ var onErrorHandler = (error) => {
67
+ if (isRouterError(error)) {
68
+ const { message, status, statusText } = error;
69
+ return Response.json({ type: "ROUTER_ERROR", code: "ROUTER_INTERNAL_ERROR", message }, { status, statusText });
70
+ }
71
+ if (isInvalidZodSchemaError(error)) {
72
+ return Response.json({ type: "ROUTER_ERROR", code: "INVALID_REQUEST", message: error.errors }, { status: 422 });
73
+ }
74
+ if (isOAuthProtocolError(error)) {
75
+ const { error: errorCode, message, type, errorURI } = error;
76
+ return Response.json(
77
+ {
78
+ type,
79
+ error: errorCode,
80
+ error_description: message,
81
+ error_uri: errorURI
82
+ },
83
+ { status: 400 }
84
+ );
85
+ }
86
+ if (isAuthInternalError(error) || isAuthSecurityError(error)) {
87
+ const { type, code, message } = error;
88
+ return Response.json(
89
+ {
90
+ type,
91
+ code,
92
+ message
93
+ },
94
+ { status: 400 }
95
+ );
96
+ }
97
+ return Response.json({ type: "SERVER_ERROR", code: "server_error", message: "An unexpected error occurred" }, { status: 500 });
98
+ };
99
+ var getNormalizedOriginPath = (path) => {
100
+ try {
101
+ const url = new URL(path);
102
+ url.hash = "";
103
+ url.search = "";
104
+ return `${url.origin}${url.pathname}`;
105
+ } catch {
106
+ return sanitizeURL(path);
107
+ }
108
+ };
109
+ var toISOString = (date) => {
110
+ return new Date(date).toISOString();
111
+ };
112
+ var useSecureCookies = (request, trustedProxyHeaders) => {
113
+ return trustedProxyHeaders ? request.url.startsWith("https://") || request.headers.get("X-Forwarded-Proto") === "https" || (request.headers.get("Forwarded")?.includes("proto=https") ?? false) : request.url.startsWith("https://");
114
+ };
115
+ var formatZodError = (error) => {
116
+ if (!error.issues || error.issues.length === 0) {
117
+ return {};
118
+ }
119
+ return error.issues.reduce((previous, issue) => {
120
+ const key = issue.path.join(".");
121
+ return {
122
+ ...previous,
123
+ [key]: {
124
+ code: issue.code,
125
+ message: issue.message
126
+ }
127
+ };
128
+ }, {});
129
+ };
130
+
131
+ export {
132
+ toSnakeCase,
133
+ toUpperCase,
134
+ toCastCase,
135
+ equals,
136
+ sanitizeURL,
137
+ isValidRelativePath,
138
+ onErrorHandler,
139
+ getNormalizedOriginPath,
140
+ toISOString,
141
+ useSecureCookies,
142
+ formatZodError
143
+ };
@@ -1,20 +1,22 @@
1
1
  // src/oauth/spotify.ts
2
2
  var spotify = {
3
- id: "spotify",
4
- name: "Spotify",
5
- authorizeURL: "https://accounts.spotify.com/authorize",
6
- accessToken: "https://accounts.spotify.com/api/token",
7
- userInfo: "https://api.spotify.com/v1/me",
8
- scope: "user-read-email user-read-private",
9
- responseType: "token",
10
- profile(profile) {
11
- return {
12
- sub: profile.id,
13
- name: profile.display_name,
14
- email: profile.email,
15
- image: profile.images?.[0]?.url,
16
- }
17
- },
18
- }
3
+ id: "spotify",
4
+ name: "Spotify",
5
+ authorizeURL: "https://accounts.spotify.com/authorize",
6
+ accessToken: "https://accounts.spotify.com/api/token",
7
+ userInfo: "https://api.spotify.com/v1/me",
8
+ scope: "user-read-email user-read-private",
9
+ responseType: "token",
10
+ profile(profile) {
11
+ return {
12
+ sub: profile.id,
13
+ name: profile.display_name,
14
+ email: profile.email,
15
+ image: profile.images?.[0]?.url
16
+ };
17
+ }
18
+ };
19
19
 
20
- export { spotify }
20
+ export {
21
+ spotify
22
+ };
@@ -0,0 +1,22 @@
1
+ // src/assert.ts
2
+ var isFalsy = (value) => {
3
+ return value === false || value === 0 || value === "" || value === null || value === void 0 || Number.isNaN(value);
4
+ };
5
+ var isRequest = (value) => {
6
+ return typeof Request !== "undefined" && value instanceof Request;
7
+ };
8
+ var isValidURL = (value) => {
9
+ if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false;
10
+ const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/;
11
+ return regex.test(value);
12
+ };
13
+ var isJWTPayloadWithToken = (payload) => {
14
+ return typeof payload === "object" && payload !== null && "token" in payload && typeof payload?.token === "string";
15
+ };
16
+
17
+ export {
18
+ isFalsy,
19
+ isRequest,
20
+ isValidURL,
21
+ isJWTPayloadWithToken
22
+ };
@@ -1,19 +1,21 @@
1
1
  // src/oauth/bitbucket.ts
2
2
  var bitbucket = {
3
- id: "bitbucket",
4
- name: "Bitbucket",
5
- authorizeURL: "https://bitbucket.org/site/oauth2/authorize",
6
- accessToken: "https://bitbucket.org/site/oauth2/access_token",
7
- userInfo: "https://api.bitbucket.org/2.0/user",
8
- scope: "account email",
9
- responseType: "code",
10
- profile(profile) {
11
- return {
12
- sub: profile.uuid ?? profile.account_id,
13
- name: profile.display_name ?? profile.nickname,
14
- image: profile.links.avatar.href,
15
- }
16
- },
17
- }
3
+ id: "bitbucket",
4
+ name: "Bitbucket",
5
+ authorizeURL: "https://bitbucket.org/site/oauth2/authorize",
6
+ accessToken: "https://bitbucket.org/site/oauth2/access_token",
7
+ userInfo: "https://api.bitbucket.org/2.0/user",
8
+ scope: "account email",
9
+ responseType: "code",
10
+ profile(profile) {
11
+ return {
12
+ sub: profile.uuid ?? profile.account_id,
13
+ name: profile.display_name ?? profile.nickname,
14
+ image: profile.links.avatar.href
15
+ };
16
+ }
17
+ };
18
18
 
19
- export { bitbucket }
19
+ export {
20
+ bitbucket
21
+ };