@aura-stack/auth 0.1.0 → 0.2.0-rc.1

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 (111) hide show
  1. package/dist/@types/index.d.ts +5 -5
  2. package/dist/@types/router.d.d.ts +5 -5
  3. package/dist/@types/utility.d.ts +1 -5
  4. package/dist/actions/callback/access-token.cjs +95 -74
  5. package/dist/actions/callback/access-token.d.ts +7 -7
  6. package/dist/actions/callback/access-token.js +5 -3
  7. package/dist/actions/callback/callback.cjs +171 -249
  8. package/dist/actions/callback/callback.d.ts +6 -6
  9. package/dist/actions/callback/callback.js +10 -10
  10. package/dist/actions/callback/userinfo.cjs +81 -57
  11. package/dist/actions/callback/userinfo.d.ts +5 -5
  12. package/dist/actions/callback/userinfo.js +7 -5
  13. package/dist/actions/csrfToken/csrfToken.cjs +36 -105
  14. package/dist/actions/csrfToken/csrfToken.js +6 -6
  15. package/dist/actions/index.cjs +309 -444
  16. package/dist/actions/index.d.ts +5 -5
  17. package/dist/actions/index.js +19 -19
  18. package/dist/actions/session/session.cjs +25 -109
  19. package/dist/actions/session/session.js +4 -5
  20. package/dist/actions/signIn/authorization.cjs +96 -87
  21. package/dist/actions/signIn/authorization.d.ts +5 -5
  22. package/dist/actions/signIn/authorization.js +5 -5
  23. package/dist/actions/signIn/signIn.cjs +133 -242
  24. package/dist/actions/signIn/signIn.d.ts +6 -6
  25. package/dist/actions/signIn/signIn.js +8 -9
  26. package/dist/actions/signOut/signOut.cjs +136 -282
  27. package/dist/actions/signOut/signOut.js +8 -9
  28. package/dist/assert.cjs +5 -0
  29. package/dist/assert.d.ts +10 -1
  30. package/dist/assert.js +3 -1
  31. package/dist/chunk-3EUWD5BB.js +63 -0
  32. package/dist/chunk-6R2YZ4AC.js +22 -0
  33. package/dist/chunk-A3N4PVAT.js +70 -0
  34. package/dist/chunk-B737EUJV.js +22 -0
  35. package/dist/{chunk-256KIVJL.js → chunk-CXLATHS5.js} +53 -9
  36. package/dist/{chunk-6SM22VVJ.js → chunk-EIL2FPSS.js} +5 -1
  37. package/dist/{chunk-VFTYH33W.js → chunk-EMKJA2GJ.js} +36 -8
  38. package/dist/{chunk-UJJ7R56J.js → chunk-GA2SMTJO.js} +16 -10
  39. package/dist/chunk-HP34YGGJ.js +22 -0
  40. package/dist/chunk-HT4YLL7N.js +35 -0
  41. package/dist/{chunk-EBPE35JT.js → chunk-IUYZQTJV.js} +0 -1
  42. package/dist/{chunk-RLT4RFKV.js → chunk-IVET23KF.js} +21 -8
  43. package/dist/{chunk-XXJKNKGQ.js → chunk-JVFTCTTE.js} +9 -13
  44. package/dist/chunk-KSWLO5ZU.js +102 -0
  45. package/dist/{chunk-GZU3RBTB.js → chunk-N2APGLXA.js} +19 -10
  46. package/dist/{chunk-CAKJT3KS.js → chunk-N4SX7TZT.js} +21 -17
  47. package/dist/chunk-RRLIF4PQ.js +55 -0
  48. package/dist/chunk-TLE4PXY3.js +39 -0
  49. package/dist/chunk-W6LG7BFW.js +197 -0
  50. package/dist/{chunk-HMRKN75I.js → chunk-YRCB5FLE.js} +14 -9
  51. package/dist/chunk-ZNCZVF6U.js +14 -0
  52. package/dist/cookie.cjs +140 -99
  53. package/dist/cookie.d.ts +35 -44
  54. package/dist/cookie.js +10 -17
  55. package/dist/errors.cjs +85 -0
  56. package/dist/errors.d.ts +49 -0
  57. package/dist/errors.js +18 -0
  58. package/dist/{index-DpfbvTZ_.d.ts → index-DkaLJFn8.d.ts} +192 -61
  59. package/dist/index.cjs +543 -443
  60. package/dist/index.d.ts +6 -6
  61. package/dist/index.js +42 -28
  62. package/dist/jose.cjs +25 -14
  63. package/dist/jose.d.ts +4 -1
  64. package/dist/jose.js +5 -4
  65. package/dist/oauth/bitbucket.d.ts +5 -5
  66. package/dist/oauth/discord.cjs +0 -1
  67. package/dist/oauth/discord.d.ts +5 -5
  68. package/dist/oauth/discord.js +1 -1
  69. package/dist/oauth/figma.d.ts +5 -5
  70. package/dist/oauth/github.d.ts +5 -5
  71. package/dist/oauth/gitlab.d.ts +5 -5
  72. package/dist/oauth/index.cjs +176 -6
  73. package/dist/oauth/index.d.ts +5 -5
  74. package/dist/oauth/index.js +19 -4
  75. package/dist/oauth/mailchimp.cjs +46 -0
  76. package/dist/oauth/mailchimp.d.ts +7 -0
  77. package/dist/oauth/mailchimp.js +6 -0
  78. package/dist/oauth/pinterest.cjs +46 -0
  79. package/dist/oauth/pinterest.d.ts +7 -0
  80. package/dist/oauth/pinterest.js +6 -0
  81. package/dist/oauth/spotify.d.ts +5 -5
  82. package/dist/oauth/strava.cjs +46 -0
  83. package/dist/oauth/strava.d.ts +7 -0
  84. package/dist/oauth/strava.js +6 -0
  85. package/dist/oauth/x.d.ts +5 -5
  86. package/dist/{response.cjs → request.cjs} +14 -10
  87. package/dist/request.d.ts +13 -0
  88. package/dist/request.js +6 -0
  89. package/dist/schemas.cjs +43 -37
  90. package/dist/schemas.d.ts +67 -64
  91. package/dist/schemas.js +3 -1
  92. package/dist/secure.cjs +32 -24
  93. package/dist/secure.d.ts +5 -5
  94. package/dist/secure.js +4 -3
  95. package/dist/utils.cjs +90 -15
  96. package/dist/utils.d.ts +11 -2
  97. package/dist/utils.js +8 -4
  98. package/package.json +8 -7
  99. package/dist/chunk-FJUDBLCP.js +0 -59
  100. package/dist/chunk-HGJ4TXY4.js +0 -137
  101. package/dist/chunk-JAPMIE6S.js +0 -10
  102. package/dist/chunk-LLR722CL.js +0 -96
  103. package/dist/chunk-SJPDVKUS.js +0 -112
  104. package/dist/chunk-SMQO5WD7.js +0 -30
  105. package/dist/chunk-UTDLUEEG.js +0 -31
  106. package/dist/chunk-ZV4BH47P.js +0 -154
  107. package/dist/error.cjs +0 -88
  108. package/dist/error.d.ts +0 -62
  109. package/dist/error.js +0 -16
  110. package/dist/response.d.ts +0 -10
  111. package/dist/response.js +0 -6
@@ -1,30 +0,0 @@
1
- import {
2
- getCookie,
3
- secureCookieOptions,
4
- setCookie
5
- } from "./chunk-ZV4BH47P.js";
6
- import {
7
- cacheControl
8
- } from "./chunk-STHEPPUZ.js";
9
- import {
10
- createCSRF
11
- } from "./chunk-GZU3RBTB.js";
12
-
13
- // src/actions/csrfToken/csrfToken.ts
14
- import { createEndpoint } from "@aura-stack/router";
15
- var csrfTokenAction = createEndpoint("GET", "/csrfToken", async (ctx) => {
16
- const {
17
- request,
18
- context: { cookies, jose, trustedProxyHeaders }
19
- } = ctx;
20
- const cookieOptions = secureCookieOptions(request, { ...cookies, strategy: "host" }, trustedProxyHeaders);
21
- const existingCSRFToken = getCookie(request, "csrfToken", cookieOptions, true);
22
- const csrfToken = await createCSRF(jose, existingCSRFToken);
23
- const headers = new Headers(cacheControl);
24
- headers.set("Set-Cookie", setCookie("csrfToken", csrfToken, cookieOptions));
25
- return Response.json({ csrfToken }, { headers });
26
- });
27
-
28
- export {
29
- csrfTokenAction
30
- };
@@ -1,31 +0,0 @@
1
- import {
2
- createDerivedSalt
3
- } from "./chunk-GZU3RBTB.js";
4
- import {
5
- AuthError
6
- } from "./chunk-FJUDBLCP.js";
7
-
8
- // src/jose.ts
9
- import "dotenv/config";
10
- import { createJWT, createJWS, createDeriveKey } from "@aura-stack/jose";
11
- var createJoseInstance = (secret) => {
12
- secret ?? (secret = process.env.AURA_AUTH_SECRET);
13
- if (!secret) {
14
- throw new AuthError("JOSE_INIT_ERROR", "AURA_AUTH_SECRET environment variable is not set and no secret was provided.");
15
- }
16
- const salt = process.env.AURA_AUTH_SALT ?? createDerivedSalt(secret);
17
- const { derivedKey: derivedSessionKey } = createDeriveKey(secret, salt, "session");
18
- const { derivedKey: derivedCsrfTokenKey } = createDeriveKey(secret, salt, "csrfToken");
19
- const { decodeJWT, encodeJWT } = createJWT(derivedSessionKey);
20
- const { signJWS, verifyJWS } = createJWS(derivedCsrfTokenKey);
21
- return {
22
- decodeJWT,
23
- encodeJWT,
24
- signJWS,
25
- verifyJWS
26
- };
27
- };
28
-
29
- export {
30
- createJoseInstance
31
- };
@@ -1,154 +0,0 @@
1
- import {
2
- isRequest
3
- } from "./chunk-6SM22VVJ.js";
4
- import {
5
- AuthError
6
- } from "./chunk-FJUDBLCP.js";
7
-
8
- // src/cookie.ts
9
- import { parse, serialize } from "cookie";
10
- import { parse as parse2 } from "cookie";
11
- var COOKIE_NAME = "aura-auth";
12
- var defaultCookieOptions = {
13
- httpOnly: true,
14
- sameSite: "lax",
15
- path: "/",
16
- maxAge: 60 * 60 * 24 * 15
17
- };
18
- var defaultCookieConfig = {
19
- strategy: "standard",
20
- name: COOKIE_NAME,
21
- options: defaultCookieOptions
22
- };
23
- var defaultStandardCookieConfig = {
24
- secure: false,
25
- httpOnly: true,
26
- prefix: ""
27
- };
28
- var defaultSecureCookieConfig = {
29
- secure: true,
30
- prefix: "__Secure-"
31
- };
32
- var defaultHostCookieConfig = {
33
- secure: true,
34
- prefix: "__Host-",
35
- path: "/",
36
- domain: void 0
37
- };
38
- var expiredCookieOptions = {
39
- ...defaultCookieOptions,
40
- expires: /* @__PURE__ */ new Date(0),
41
- maxAge: 0
42
- };
43
- var defineDefaultCookieOptions = (options) => {
44
- return {
45
- name: options?.name ?? COOKIE_NAME,
46
- prefix: options?.prefix ?? (options?.secure ? "__Secure-" : ""),
47
- ...defaultCookieOptions,
48
- ...options
49
- };
50
- };
51
- var setCookie = (cookieName, value, options) => {
52
- const { prefix, name } = defineDefaultCookieOptions(options);
53
- const cookieNameWithPrefix = `${prefix}${name}.${cookieName}`;
54
- return serialize(cookieNameWithPrefix, value, {
55
- ...defaultCookieOptions,
56
- ...options
57
- });
58
- };
59
- var getCookie = (petition, cookie, options, optional = false) => {
60
- const cookies = isRequest(petition) ? petition.headers.get("Cookie") : petition.headers.getSetCookie().join("; ");
61
- if (!cookies) {
62
- if (optional) {
63
- return "";
64
- }
65
- throw new AuthError("invalid_request", "No cookies found. There is no active session");
66
- }
67
- const { name, prefix } = defineDefaultCookieOptions(options);
68
- const parsedCookies = parse(cookies);
69
- const value = parsedCookies[`${prefix}${name}.${cookie}`];
70
- if (value === void 0) {
71
- if (optional) {
72
- return "";
73
- }
74
- throw new AuthError("invalid_request", `Cookie "${cookie}" not found. There is no active session`);
75
- }
76
- return value;
77
- };
78
- var createSessionCookie = async (session, cookieOptions, jose) => {
79
- try {
80
- const encoded = await jose.encodeJWT(session);
81
- return setCookie("sessionToken", encoded, cookieOptions);
82
- } catch (error) {
83
- throw new AuthError("server_error", "Failed to create session cookie", { cause: error });
84
- }
85
- };
86
- var secureCookieOptions = (request, cookieOptions, trustedProxyHeaders) => {
87
- const name = cookieOptions.name ?? COOKIE_NAME;
88
- const isSecure = trustedProxyHeaders ? request.url.startsWith("https://") || request.headers.get("X-Forwarded-Proto") === "https" || request.headers.get("Forwarded")?.includes("proto=https") : request.url.startsWith("https://");
89
- if (!cookieOptions.options?.httpOnly) {
90
- console.warn(
91
- "[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
92
- );
93
- }
94
- if (cookieOptions.options?.domain === "*") {
95
- console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.");
96
- }
97
- if (!isSecure) {
98
- const options = cookieOptions.options;
99
- if (options?.secure) {
100
- console.warn(
101
- "[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
102
- );
103
- }
104
- if (options?.sameSite == "none") {
105
- console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.");
106
- }
107
- if (process.env.NODE_ENV === "production") {
108
- console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.");
109
- }
110
- return {
111
- ...defaultCookieOptions,
112
- ...cookieOptions.options,
113
- sameSite: options?.sameSite === "none" ? "lax" : options?.sameSite ?? "lax",
114
- ...defaultStandardCookieConfig,
115
- name
116
- };
117
- }
118
- return cookieOptions.strategy === "host" ? {
119
- ...defaultCookieOptions,
120
- ...cookieOptions.options,
121
- ...defaultHostCookieConfig,
122
- name
123
- } : { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name };
124
- };
125
- var expireCookie = (name, options) => {
126
- return setCookie(name, "", { ...options, ...expiredCookieOptions });
127
- };
128
- var oauthCookie = (options) => {
129
- return {
130
- ...options,
131
- secure: options.secure,
132
- httpOnly: options.httpOnly,
133
- maxAge: 5 * 60,
134
- expires: new Date(Date.now() + 5 * 60 * 1e3)
135
- };
136
- };
137
-
138
- export {
139
- COOKIE_NAME,
140
- defaultCookieOptions,
141
- defaultCookieConfig,
142
- defaultStandardCookieConfig,
143
- defaultSecureCookieConfig,
144
- defaultHostCookieConfig,
145
- expiredCookieOptions,
146
- defineDefaultCookieOptions,
147
- setCookie,
148
- getCookie,
149
- createSessionCookie,
150
- secureCookieOptions,
151
- expireCookie,
152
- oauthCookie,
153
- parse2 as parse
154
- };
package/dist/error.cjs DELETED
@@ -1,88 +0,0 @@
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
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
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);
19
-
20
- // src/error.ts
21
- var error_exports = {};
22
- __export(error_exports, {
23
- AuthError: () => AuthError,
24
- ERROR_RESPONSE: () => ERROR_RESPONSE,
25
- InvalidCsrfTokenError: () => InvalidCsrfTokenError,
26
- InvalidRedirectToError: () => InvalidRedirectToError,
27
- isAuthError: () => isAuthError,
28
- throwAuthError: () => throwAuthError
29
- });
30
- module.exports = __toCommonJS(error_exports);
31
- var AuthError = class extends Error {
32
- constructor(type, message) {
33
- super(message);
34
- this.type = type;
35
- this.name = "AuthError";
36
- }
37
- };
38
- var InvalidCsrfTokenError = class extends AuthError {
39
- constructor(message = "The provided CSRF token is invalid or has expired") {
40
- super("invalid_csrf_token", message);
41
- this.name = "InvalidCsrfTokenError";
42
- }
43
- };
44
- var InvalidRedirectToError = class extends AuthError {
45
- constructor(message = "The redirectTo parameter does not match the hosted origin.") {
46
- super("invalid_redirect_to", message);
47
- this.name = "InvalidRedirectToError";
48
- }
49
- };
50
- var isAuthError = (error) => {
51
- return error instanceof AuthError;
52
- };
53
- var throwAuthError = (error, message) => {
54
- if (error instanceof Error) {
55
- if (isAuthError(error)) {
56
- throw error;
57
- }
58
- throw new AuthError("invalid_request", error.message ?? message);
59
- }
60
- };
61
- var ERROR_RESPONSE = {
62
- AUTHORIZATION: {
63
- INVALID_REQUEST: "invalid_request",
64
- UNAUTHORIZED_CLIENT: "unauthorized_client",
65
- ACCESS_DENIED: "access_denied",
66
- UNSUPPORTED_RESPONSE_TYPE: "unsupported_response_type",
67
- INVALID_SCOPE: "invalid_scope",
68
- SERVER_ERROR: "server_error",
69
- TEMPORARILY_UNAVAILABLE: "temporarily_unavailable"
70
- },
71
- ACCESS_TOKEN: {
72
- INVALID_REQUEST: "invalid_request",
73
- INVALID_CLIENT: "invalid_client",
74
- INVALID_GRANT: "invalid_grant",
75
- UNAUTHORIZED_CLIENT: "unauthorized_client",
76
- UNSUPPORTED_GRANT_TYPE: "unsupported_grant_type",
77
- INVALID_SCOPE: "invalid_scope"
78
- }
79
- };
80
- // Annotate the CommonJS export names for ESM import in node:
81
- 0 && (module.exports = {
82
- AuthError,
83
- ERROR_RESPONSE,
84
- InvalidCsrfTokenError,
85
- InvalidRedirectToError,
86
- isAuthError,
87
- throwAuthError
88
- });
package/dist/error.d.ts DELETED
@@ -1,62 +0,0 @@
1
- import { E as ErrorType } from './index-DpfbvTZ_.js';
2
- import { LiteralUnion } from './@types/utility.js';
3
- import 'zod/v4';
4
- import '@aura-stack/jose/jose';
5
- import './schemas.js';
6
- import 'zod/v4/core';
7
- import 'cookie';
8
-
9
- /**
10
- * Error class for all Aura Auth errors.
11
- */
12
- declare class AuthError extends Error {
13
- readonly type: LiteralUnion<ErrorType>;
14
- constructor(type: LiteralUnion<ErrorType>, message: string);
15
- }
16
- declare class InvalidCsrfTokenError extends AuthError {
17
- constructor(message?: string);
18
- }
19
- declare class InvalidRedirectToError extends AuthError {
20
- constructor(message?: string);
21
- }
22
- /**
23
- * Verifies if the provided error is an instance of AuthError.
24
- *
25
- * @param error The error to be checked
26
- * @returns True if the error is an instance of AuthError, false otherwise
27
- */
28
- declare const isAuthError: (error: unknown) => error is AuthError;
29
- /**
30
- * Captures and Error and verifies if it's an AuthError, rethrowing it if so.
31
- * If it's a different type of error, it wraps it in a new AuthError with the provided message.
32
- *
33
- * @param error The error to be processed
34
- * @param message The error message to be used if wrapping the error
35
- */
36
- declare const throwAuthError: (error: unknown, message?: string) => void;
37
- /**
38
- * Errores responses returned by the OAuth flows including Authorization and Access Token errors.
39
- * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1
40
- * @see https://datatracker.ietf.org/doc/html/rfc6749#section-5.2
41
- */
42
- declare const ERROR_RESPONSE: {
43
- AUTHORIZATION: {
44
- INVALID_REQUEST: string;
45
- UNAUTHORIZED_CLIENT: string;
46
- ACCESS_DENIED: string;
47
- UNSUPPORTED_RESPONSE_TYPE: string;
48
- INVALID_SCOPE: string;
49
- SERVER_ERROR: string;
50
- TEMPORARILY_UNAVAILABLE: string;
51
- };
52
- ACCESS_TOKEN: {
53
- INVALID_REQUEST: string;
54
- INVALID_CLIENT: string;
55
- INVALID_GRANT: string;
56
- UNAUTHORIZED_CLIENT: string;
57
- UNSUPPORTED_GRANT_TYPE: string;
58
- INVALID_SCOPE: string;
59
- };
60
- };
61
-
62
- export { AuthError, ERROR_RESPONSE, InvalidCsrfTokenError, InvalidRedirectToError, isAuthError, throwAuthError };
package/dist/error.js DELETED
@@ -1,16 +0,0 @@
1
- import {
2
- AuthError,
3
- ERROR_RESPONSE,
4
- InvalidCsrfTokenError,
5
- InvalidRedirectToError,
6
- isAuthError,
7
- throwAuthError
8
- } from "./chunk-FJUDBLCP.js";
9
- export {
10
- AuthError,
11
- ERROR_RESPONSE,
12
- InvalidCsrfTokenError,
13
- InvalidRedirectToError,
14
- isAuthError,
15
- throwAuthError
16
- };
@@ -1,10 +0,0 @@
1
- /**
2
- * Custom Response class for Aura Auth.
3
- *
4
- * @experimental
5
- */
6
- declare class AuraResponse extends Response {
7
- static json<T>(body: T, init?: ResponseInit): Response;
8
- }
9
-
10
- export { AuraResponse };
package/dist/response.js DELETED
@@ -1,6 +0,0 @@
1
- import {
2
- AuraResponse
3
- } from "./chunk-JAPMIE6S.js";
4
- export {
5
- AuraResponse
6
- };