@aura-stack/auth 0.1.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.
- package/LICENSE +21 -0
- package/README.md +42 -0
- package/dist/@types/index.cjs +18 -0
- package/dist/@types/index.d.cts +9 -0
- package/dist/@types/index.d.ts +9 -0
- package/dist/@types/index.js +1 -0
- package/dist/@types/router.d.cjs +1 -0
- package/dist/@types/router.d.d.cts +16 -0
- package/dist/@types/router.d.d.ts +16 -0
- package/dist/@types/router.d.js +0 -0
- package/dist/@types/utility.cjs +18 -0
- package/dist/@types/utility.d.cts +6 -0
- package/dist/@types/utility.d.ts +6 -0
- package/dist/@types/utility.js +1 -0
- package/dist/actions/callback/access-token.cjs +170 -0
- package/dist/actions/callback/access-token.d.cts +30 -0
- package/dist/actions/callback/access-token.d.ts +30 -0
- package/dist/actions/callback/access-token.js +8 -0
- package/dist/actions/callback/callback.cjs +517 -0
- package/dist/actions/callback/callback.d.cts +13 -0
- package/dist/actions/callback/callback.d.ts +13 -0
- package/dist/actions/callback/callback.js +16 -0
- package/dist/actions/callback/userinfo.cjs +165 -0
- package/dist/actions/callback/userinfo.d.cts +22 -0
- package/dist/actions/callback/userinfo.d.ts +22 -0
- package/dist/actions/callback/userinfo.js +10 -0
- package/dist/actions/csrfToken/csrfToken.cjs +207 -0
- package/dist/actions/csrfToken/csrfToken.d.cts +5 -0
- package/dist/actions/csrfToken/csrfToken.d.ts +5 -0
- package/dist/actions/csrfToken/csrfToken.js +12 -0
- package/dist/actions/index.cjs +864 -0
- package/dist/actions/index.d.cts +14 -0
- package/dist/actions/index.d.ts +14 -0
- package/dist/actions/index.js +34 -0
- package/dist/actions/session/session.cjs +191 -0
- package/dist/actions/session/session.d.cts +5 -0
- package/dist/actions/session/session.d.ts +5 -0
- package/dist/actions/session/session.js +11 -0
- package/dist/actions/signIn/authorization.cjs +274 -0
- package/dist/actions/signIn/authorization.d.cts +45 -0
- package/dist/actions/signIn/authorization.d.ts +45 -0
- package/dist/actions/signIn/authorization.js +16 -0
- package/dist/actions/signIn/signIn.cjs +469 -0
- package/dist/actions/signIn/signIn.d.cts +13 -0
- package/dist/actions/signIn/signIn.d.ts +13 -0
- package/dist/actions/signIn/signIn.js +14 -0
- package/dist/actions/signOut/signOut.cjs +490 -0
- package/dist/actions/signOut/signOut.d.cts +8 -0
- package/dist/actions/signOut/signOut.d.ts +8 -0
- package/dist/actions/signOut/signOut.js +15 -0
- package/dist/assert.cjs +44 -0
- package/dist/assert.d.ts +5 -0
- package/dist/assert.js +10 -0
- package/dist/chunk-256KIVJL.js +99 -0
- package/dist/chunk-42XB3YCW.js +22 -0
- package/dist/chunk-6SM22VVJ.js +18 -0
- package/dist/chunk-CAKJT3KS.js +92 -0
- package/dist/chunk-E3OXBRYF.js +22 -0
- package/dist/chunk-EBPE35JT.js +31 -0
- package/dist/chunk-FIPU4MLT.js +21 -0
- package/dist/chunk-FJUDBLCP.js +59 -0
- package/dist/chunk-FKRDCWBF.js +22 -0
- package/dist/chunk-GZU3RBTB.js +62 -0
- package/dist/chunk-HGJ4TXY4.js +137 -0
- package/dist/chunk-HMRKN75I.js +74 -0
- package/dist/chunk-IKHPGFCW.js +14 -0
- package/dist/chunk-ITQ7352M.js +0 -0
- package/dist/chunk-JAPMIE6S.js +10 -0
- package/dist/chunk-KRNOMBXQ.js +22 -0
- package/dist/chunk-LLR722CL.js +96 -0
- package/dist/chunk-PG7UYFG5.js +0 -0
- package/dist/chunk-RLT4RFKV.js +45 -0
- package/dist/chunk-SJPDVKUS.js +112 -0
- package/dist/chunk-SMQO5WD7.js +30 -0
- package/dist/chunk-STHEPPUZ.js +11 -0
- package/dist/chunk-UJJ7R56J.js +52 -0
- package/dist/chunk-VFTYH33W.js +61 -0
- package/dist/chunk-X7M4CQTN.js +25 -0
- package/dist/chunk-XXJKNKGQ.js +37 -0
- package/dist/chunk-ZV4BH47P.js +154 -0
- package/dist/cookie.cjs +201 -0
- package/dist/cookie.d.ts +95 -0
- package/dist/cookie.js +36 -0
- package/dist/error.cjs +88 -0
- package/dist/error.d.ts +64 -0
- package/dist/error.js +16 -0
- package/dist/headers.cjs +35 -0
- package/dist/headers.d.ts +9 -0
- package/dist/headers.js +6 -0
- package/dist/index-CGRZ0wrw.d.ts +530 -0
- package/dist/index.cjs +1089 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +75 -0
- package/dist/jose.cjs +68 -0
- package/dist/jose.d.ts +20 -0
- package/dist/jose.js +9 -0
- package/dist/oauth/bitbucket.cjs +45 -0
- package/dist/oauth/bitbucket.d.cts +9 -0
- package/dist/oauth/bitbucket.d.ts +9 -0
- package/dist/oauth/bitbucket.js +6 -0
- package/dist/oauth/discord.cjs +55 -0
- package/dist/oauth/discord.d.cts +9 -0
- package/dist/oauth/discord.d.ts +9 -0
- package/dist/oauth/discord.js +6 -0
- package/dist/oauth/figma.cjs +46 -0
- package/dist/oauth/figma.d.cts +9 -0
- package/dist/oauth/figma.d.ts +9 -0
- package/dist/oauth/figma.js +6 -0
- package/dist/oauth/github.cjs +38 -0
- package/dist/oauth/github.d.cts +9 -0
- package/dist/oauth/github.d.ts +9 -0
- package/dist/oauth/github.js +6 -0
- package/dist/oauth/gitlab.cjs +46 -0
- package/dist/oauth/gitlab.d.cts +9 -0
- package/dist/oauth/gitlab.d.ts +9 -0
- package/dist/oauth/gitlab.js +6 -0
- package/dist/oauth/index.cjs +213 -0
- package/dist/oauth/index.d.cts +9 -0
- package/dist/oauth/index.d.ts +9 -0
- package/dist/oauth/index.js +36 -0
- package/dist/oauth/spotify.cjs +46 -0
- package/dist/oauth/spotify.d.cts +9 -0
- package/dist/oauth/spotify.d.ts +9 -0
- package/dist/oauth/spotify.js +6 -0
- package/dist/oauth/x.cjs +46 -0
- package/dist/oauth/x.d.cts +9 -0
- package/dist/oauth/x.d.ts +9 -0
- package/dist/oauth/x.js +6 -0
- package/dist/response.cjs +34 -0
- package/dist/response.d.ts +10 -0
- package/dist/response.js +6 -0
- package/dist/schemas.cjs +105 -0
- package/dist/schemas.d.ts +130 -0
- package/dist/schemas.js +20 -0
- package/dist/secure.cjs +120 -0
- package/dist/secure.d.ts +43 -0
- package/dist/secure.js +18 -0
- package/dist/utils.cjs +141 -0
- package/dist/utils.d.ts +45 -0
- package/dist/utils.js +23 -0
- package/package.json +70 -0
package/dist/cookie.cjs
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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/cookie.ts
|
|
21
|
+
var cookie_exports = {};
|
|
22
|
+
__export(cookie_exports, {
|
|
23
|
+
COOKIE_NAME: () => COOKIE_NAME,
|
|
24
|
+
createSessionCookie: () => createSessionCookie,
|
|
25
|
+
defaultCookieConfig: () => defaultCookieConfig,
|
|
26
|
+
defaultCookieOptions: () => defaultCookieOptions,
|
|
27
|
+
defaultHostCookieConfig: () => defaultHostCookieConfig,
|
|
28
|
+
defaultSecureCookieConfig: () => defaultSecureCookieConfig,
|
|
29
|
+
defaultStandardCookieConfig: () => defaultStandardCookieConfig,
|
|
30
|
+
defineDefaultCookieOptions: () => defineDefaultCookieOptions,
|
|
31
|
+
expireCookie: () => expireCookie,
|
|
32
|
+
expiredCookieOptions: () => expiredCookieOptions,
|
|
33
|
+
getCookie: () => getCookie,
|
|
34
|
+
oauthCookie: () => oauthCookie,
|
|
35
|
+
parse: () => import_cookie2.parse,
|
|
36
|
+
secureCookieOptions: () => secureCookieOptions,
|
|
37
|
+
setCookie: () => setCookie
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(cookie_exports);
|
|
40
|
+
var import_cookie = require("cookie");
|
|
41
|
+
|
|
42
|
+
// src/error.ts
|
|
43
|
+
var AuthError = class extends Error {
|
|
44
|
+
constructor(type, message) {
|
|
45
|
+
super(message);
|
|
46
|
+
this.type = type;
|
|
47
|
+
this.name = "AuthError";
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/assert.ts
|
|
52
|
+
var isRequest = (value) => {
|
|
53
|
+
return typeof Request !== "undefined" && value instanceof Request;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/cookie.ts
|
|
57
|
+
var import_cookie2 = require("cookie");
|
|
58
|
+
var COOKIE_NAME = "aura-auth";
|
|
59
|
+
var defaultCookieOptions = {
|
|
60
|
+
httpOnly: true,
|
|
61
|
+
sameSite: "lax",
|
|
62
|
+
path: "/",
|
|
63
|
+
maxAge: 60 * 60 * 24 * 15
|
|
64
|
+
};
|
|
65
|
+
var defaultCookieConfig = {
|
|
66
|
+
strategy: "standard",
|
|
67
|
+
name: COOKIE_NAME,
|
|
68
|
+
options: defaultCookieOptions
|
|
69
|
+
};
|
|
70
|
+
var defaultStandardCookieConfig = {
|
|
71
|
+
secure: false,
|
|
72
|
+
httpOnly: true,
|
|
73
|
+
prefix: ""
|
|
74
|
+
};
|
|
75
|
+
var defaultSecureCookieConfig = {
|
|
76
|
+
secure: true,
|
|
77
|
+
prefix: "__Secure-"
|
|
78
|
+
};
|
|
79
|
+
var defaultHostCookieConfig = {
|
|
80
|
+
secure: true,
|
|
81
|
+
prefix: "__Host-",
|
|
82
|
+
path: "/",
|
|
83
|
+
domain: void 0
|
|
84
|
+
};
|
|
85
|
+
var expiredCookieOptions = {
|
|
86
|
+
...defaultCookieOptions,
|
|
87
|
+
expires: /* @__PURE__ */ new Date(0),
|
|
88
|
+
maxAge: 0
|
|
89
|
+
};
|
|
90
|
+
var defineDefaultCookieOptions = (options) => {
|
|
91
|
+
return {
|
|
92
|
+
name: options?.name ?? COOKIE_NAME,
|
|
93
|
+
prefix: options?.prefix ?? (options?.secure ? "__Secure-" : ""),
|
|
94
|
+
...defaultCookieOptions,
|
|
95
|
+
...options
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
var setCookie = (cookieName, value, options) => {
|
|
99
|
+
const { prefix, name } = defineDefaultCookieOptions(options);
|
|
100
|
+
const cookieNameWithPrefix = `${prefix}${name}.${cookieName}`;
|
|
101
|
+
return (0, import_cookie.serialize)(cookieNameWithPrefix, value, {
|
|
102
|
+
...defaultCookieOptions,
|
|
103
|
+
...options
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
var getCookie = (petition, cookie, options, optional = false) => {
|
|
107
|
+
const cookies = isRequest(petition) ? petition.headers.get("Cookie") : petition.headers.getSetCookie().join("; ");
|
|
108
|
+
if (!cookies) {
|
|
109
|
+
if (optional) {
|
|
110
|
+
return "";
|
|
111
|
+
}
|
|
112
|
+
throw new AuthError("invalid_request", "No cookies found. There is no active session");
|
|
113
|
+
}
|
|
114
|
+
const { name, prefix } = defineDefaultCookieOptions(options);
|
|
115
|
+
const parsedCookies = (0, import_cookie.parse)(cookies);
|
|
116
|
+
const value = parsedCookies[`${prefix}${name}.${cookie}`];
|
|
117
|
+
if (value === void 0) {
|
|
118
|
+
if (optional) {
|
|
119
|
+
return "";
|
|
120
|
+
}
|
|
121
|
+
throw new AuthError("invalid_request", `Cookie "${cookie}" not found. There is no active session`);
|
|
122
|
+
}
|
|
123
|
+
return value;
|
|
124
|
+
};
|
|
125
|
+
var createSessionCookie = async (session, cookieOptions, jose) => {
|
|
126
|
+
try {
|
|
127
|
+
const encoded = await jose.encodeJWT(session);
|
|
128
|
+
return setCookie("sessionToken", encoded, cookieOptions);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
throw new AuthError("server_error", "Failed to create session cookie", { cause: error });
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
var secureCookieOptions = (request, cookieOptions, trustedProxyHeaders) => {
|
|
134
|
+
const name = cookieOptions.name ?? COOKIE_NAME;
|
|
135
|
+
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://");
|
|
136
|
+
if (!cookieOptions.options?.httpOnly) {
|
|
137
|
+
console.warn(
|
|
138
|
+
"[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
if (cookieOptions.options?.domain === "*") {
|
|
142
|
+
console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.");
|
|
143
|
+
}
|
|
144
|
+
if (!isSecure) {
|
|
145
|
+
const options = cookieOptions.options;
|
|
146
|
+
if (options?.secure) {
|
|
147
|
+
console.warn(
|
|
148
|
+
"[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
if (options?.sameSite == "none") {
|
|
152
|
+
console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.");
|
|
153
|
+
}
|
|
154
|
+
if (process.env.NODE_ENV === "production") {
|
|
155
|
+
console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.");
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
...defaultCookieOptions,
|
|
159
|
+
...cookieOptions.options,
|
|
160
|
+
sameSite: options?.sameSite === "none" ? "lax" : options?.sameSite ?? "lax",
|
|
161
|
+
...defaultStandardCookieConfig,
|
|
162
|
+
name
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
return cookieOptions.strategy === "host" ? {
|
|
166
|
+
...defaultCookieOptions,
|
|
167
|
+
...cookieOptions.options,
|
|
168
|
+
...defaultHostCookieConfig,
|
|
169
|
+
name
|
|
170
|
+
} : { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name };
|
|
171
|
+
};
|
|
172
|
+
var expireCookie = (name, options) => {
|
|
173
|
+
return setCookie(name, "", { ...options, ...expiredCookieOptions });
|
|
174
|
+
};
|
|
175
|
+
var oauthCookie = (options) => {
|
|
176
|
+
return {
|
|
177
|
+
...options,
|
|
178
|
+
secure: options.secure,
|
|
179
|
+
httpOnly: options.httpOnly,
|
|
180
|
+
maxAge: 5 * 60,
|
|
181
|
+
expires: new Date(Date.now() + 5 * 60 * 1e3)
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
185
|
+
0 && (module.exports = {
|
|
186
|
+
COOKIE_NAME,
|
|
187
|
+
createSessionCookie,
|
|
188
|
+
defaultCookieConfig,
|
|
189
|
+
defaultCookieOptions,
|
|
190
|
+
defaultHostCookieConfig,
|
|
191
|
+
defaultSecureCookieConfig,
|
|
192
|
+
defaultStandardCookieConfig,
|
|
193
|
+
defineDefaultCookieOptions,
|
|
194
|
+
expireCookie,
|
|
195
|
+
expiredCookieOptions,
|
|
196
|
+
getCookie,
|
|
197
|
+
oauthCookie,
|
|
198
|
+
parse,
|
|
199
|
+
secureCookieOptions,
|
|
200
|
+
setCookie
|
|
201
|
+
});
|
package/dist/cookie.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { SerializeOptions } from 'cookie';
|
|
2
|
+
export { parse } from 'cookie';
|
|
3
|
+
import { JWTPayload } from '@aura-stack/jose/jose';
|
|
4
|
+
import { C as CookieConfig, a as CookieConfigInternal, b as CookieName, A as AuthRuntimeConfig } from './index-CGRZ0wrw.js';
|
|
5
|
+
import { LiteralUnion } from './@types/utility.js';
|
|
6
|
+
import 'zod/v4';
|
|
7
|
+
import './jose.js';
|
|
8
|
+
import './schemas.js';
|
|
9
|
+
import 'zod/v4/core';
|
|
10
|
+
import '@aura-stack/router';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Prefix for all cookies set by Aura Auth.
|
|
14
|
+
*/
|
|
15
|
+
declare const COOKIE_NAME = "aura-auth";
|
|
16
|
+
/**
|
|
17
|
+
* Default cookie options used by Aura Auth.
|
|
18
|
+
*/
|
|
19
|
+
declare const defaultCookieOptions: SerializeOptions;
|
|
20
|
+
/**
|
|
21
|
+
* Default cookie options for "standard" cookies.
|
|
22
|
+
*/
|
|
23
|
+
declare const defaultCookieConfig: CookieConfig;
|
|
24
|
+
declare const defaultStandardCookieConfig: CookieConfigInternal;
|
|
25
|
+
/**
|
|
26
|
+
* Default cookie options for "secure" cookies.
|
|
27
|
+
* @see https://httpwg.org/http-extensions/draft-ietf-httpbis-rfc6265bis.html#name-the-__secure-prefix
|
|
28
|
+
*/
|
|
29
|
+
declare const defaultSecureCookieConfig: CookieConfigInternal;
|
|
30
|
+
/**
|
|
31
|
+
* Default cookie options for "host" cookies.
|
|
32
|
+
* @see https://httpwg.org/http-extensions/draft-ietf-httpbis-rfc6265bis.html#name-the-__host-prefix
|
|
33
|
+
*/
|
|
34
|
+
declare const defaultHostCookieConfig: CookieConfigInternal;
|
|
35
|
+
/**
|
|
36
|
+
* Cookie options for expired cookies.
|
|
37
|
+
*/
|
|
38
|
+
declare const expiredCookieOptions: SerializeOptions;
|
|
39
|
+
declare const defineDefaultCookieOptions: (options?: CookieConfigInternal) => CookieConfigInternal;
|
|
40
|
+
/**
|
|
41
|
+
* Set a cookie with the given name, value and `CookieOptionsInternal`; supports secure
|
|
42
|
+
* cookies with the `__Secure-` and `__Host-` prefixes.
|
|
43
|
+
*
|
|
44
|
+
* Cookie attributes are serialized in the following order:
|
|
45
|
+
* Expires, Max-Age, Domain, Path, Secure, HttpOnly, SameSite, Partitioned, Priority.
|
|
46
|
+
*/
|
|
47
|
+
declare const setCookie: (cookieName: LiteralUnion<CookieName>, value: string, options?: CookieConfigInternal) => string;
|
|
48
|
+
/**
|
|
49
|
+
* Get a cookie by name from the request.
|
|
50
|
+
*
|
|
51
|
+
* @param request The incoming request object
|
|
52
|
+
* @param cookie Cookie name to retrieve
|
|
53
|
+
* @param options Cookie options to define the prefix and other attributes
|
|
54
|
+
* @param optional If true, returns an empty string instead of throwing an error when the cookie is not found
|
|
55
|
+
* @returns The value of the cookie or undefined if not found
|
|
56
|
+
*/
|
|
57
|
+
declare const getCookie: (petition: Request | Response, cookie: LiteralUnion<CookieName>, options?: CookieConfigInternal, optional?: boolean) => string;
|
|
58
|
+
/**
|
|
59
|
+
* Create a session cookie containing a signed and encrypted JWT, using the
|
|
60
|
+
* `@aura-stack/jose` package for the encoding.
|
|
61
|
+
*
|
|
62
|
+
* @param session - The JWT payload to be encoded in the session cookie
|
|
63
|
+
* @returns The serialized session cookie string
|
|
64
|
+
*/
|
|
65
|
+
declare const createSessionCookie: (session: JWTPayload, cookieOptions: CookieConfigInternal, jose: AuthRuntimeConfig["jose"]) => Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Defines the cookie configuration based on the request security and cookie options passed
|
|
68
|
+
* in the Aura Auth configuration (`createAuth` function). This function ensures the correct
|
|
69
|
+
* cookie prefixes and security attributes are applied based on whether the request is secure
|
|
70
|
+
* (HTTPS) or not.
|
|
71
|
+
*
|
|
72
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-Proto
|
|
73
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Forwarded
|
|
74
|
+
* @param request The incoming request object
|
|
75
|
+
* @param cookieOptions Cookie options from the Aura Auth configuration
|
|
76
|
+
* @returns The finalized cookie options to be used for setting cookies
|
|
77
|
+
*/
|
|
78
|
+
declare const secureCookieOptions: (request: Request, cookieOptions: CookieConfig, trustedProxyHeaders?: boolean) => CookieConfigInternal;
|
|
79
|
+
/**
|
|
80
|
+
* Expire a cookie by setting its value to an empty string and applying expired cookie options.
|
|
81
|
+
*
|
|
82
|
+
* @param name The name of the cookie to expire
|
|
83
|
+
* @param options cookie options obtained from secureCookieOptions
|
|
84
|
+
* @returns formatted cookie options for an expired cookie
|
|
85
|
+
*/
|
|
86
|
+
declare const expireCookie: (name: LiteralUnion<CookieName>, options: CookieConfigInternal) => string;
|
|
87
|
+
/**
|
|
88
|
+
* Set OAuth-specific cookie options, including a short maxAge of 5 minutes.
|
|
89
|
+
*
|
|
90
|
+
* @param options cookie options obtained from secureCookieOptions
|
|
91
|
+
* @returns formatted cookie options for OAuth cookies
|
|
92
|
+
*/
|
|
93
|
+
declare const oauthCookie: (options: CookieConfigInternal) => CookieConfigInternal;
|
|
94
|
+
|
|
95
|
+
export { COOKIE_NAME, createSessionCookie, defaultCookieConfig, defaultCookieOptions, defaultHostCookieConfig, defaultSecureCookieConfig, defaultStandardCookieConfig, defineDefaultCookieOptions, expireCookie, expiredCookieOptions, getCookie, oauthCookie, secureCookieOptions, setCookie };
|
package/dist/cookie.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
COOKIE_NAME,
|
|
3
|
+
createSessionCookie,
|
|
4
|
+
defaultCookieConfig,
|
|
5
|
+
defaultCookieOptions,
|
|
6
|
+
defaultHostCookieConfig,
|
|
7
|
+
defaultSecureCookieConfig,
|
|
8
|
+
defaultStandardCookieConfig,
|
|
9
|
+
defineDefaultCookieOptions,
|
|
10
|
+
expireCookie,
|
|
11
|
+
expiredCookieOptions,
|
|
12
|
+
getCookie,
|
|
13
|
+
oauthCookie,
|
|
14
|
+
parse,
|
|
15
|
+
secureCookieOptions,
|
|
16
|
+
setCookie
|
|
17
|
+
} from "./chunk-ZV4BH47P.js";
|
|
18
|
+
import "./chunk-6SM22VVJ.js";
|
|
19
|
+
import "./chunk-FJUDBLCP.js";
|
|
20
|
+
export {
|
|
21
|
+
COOKIE_NAME,
|
|
22
|
+
createSessionCookie,
|
|
23
|
+
defaultCookieConfig,
|
|
24
|
+
defaultCookieOptions,
|
|
25
|
+
defaultHostCookieConfig,
|
|
26
|
+
defaultSecureCookieConfig,
|
|
27
|
+
defaultStandardCookieConfig,
|
|
28
|
+
defineDefaultCookieOptions,
|
|
29
|
+
expireCookie,
|
|
30
|
+
expiredCookieOptions,
|
|
31
|
+
getCookie,
|
|
32
|
+
oauthCookie,
|
|
33
|
+
parse,
|
|
34
|
+
secureCookieOptions,
|
|
35
|
+
setCookie
|
|
36
|
+
};
|
package/dist/error.cjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { E as ErrorType } from './index-CGRZ0wrw.js';
|
|
2
|
+
import { LiteralUnion } from './@types/utility.js';
|
|
3
|
+
import 'zod/v4';
|
|
4
|
+
import './jose.js';
|
|
5
|
+
import '@aura-stack/jose/jose';
|
|
6
|
+
import './schemas.js';
|
|
7
|
+
import 'zod/v4/core';
|
|
8
|
+
import '@aura-stack/router';
|
|
9
|
+
import 'cookie';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Error class for all Aura Auth errors.
|
|
13
|
+
*/
|
|
14
|
+
declare class AuthError extends Error {
|
|
15
|
+
readonly type: LiteralUnion<ErrorType>;
|
|
16
|
+
constructor(type: LiteralUnion<ErrorType>, message: string);
|
|
17
|
+
}
|
|
18
|
+
declare class InvalidCsrfTokenError extends AuthError {
|
|
19
|
+
constructor(message?: string);
|
|
20
|
+
}
|
|
21
|
+
declare class InvalidRedirectToError extends AuthError {
|
|
22
|
+
constructor(message?: string);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Verifies if the provided error is an instance of AuthError.
|
|
26
|
+
*
|
|
27
|
+
* @param error The error to be checked
|
|
28
|
+
* @returns True if the error is an instance of AuthError, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
declare const isAuthError: (error: unknown) => error is AuthError;
|
|
31
|
+
/**
|
|
32
|
+
* Captures and Error and verifies if it's an AuthError, rethrowing it if so.
|
|
33
|
+
* If it's a different type of error, it wraps it in a new AuthError with the provided message.
|
|
34
|
+
*
|
|
35
|
+
* @param error The error to be processed
|
|
36
|
+
* @param message The error message to be used if wrapping the error
|
|
37
|
+
*/
|
|
38
|
+
declare const throwAuthError: (error: unknown, message?: string) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Errores responses returned by the OAuth flows including Authorization and Access Token errors.
|
|
41
|
+
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1
|
|
42
|
+
* @see https://datatracker.ietf.org/doc/html/rfc6749#section-5.2
|
|
43
|
+
*/
|
|
44
|
+
declare const ERROR_RESPONSE: {
|
|
45
|
+
AUTHORIZATION: {
|
|
46
|
+
INVALID_REQUEST: string;
|
|
47
|
+
UNAUTHORIZED_CLIENT: string;
|
|
48
|
+
ACCESS_DENIED: string;
|
|
49
|
+
UNSUPPORTED_RESPONSE_TYPE: string;
|
|
50
|
+
INVALID_SCOPE: string;
|
|
51
|
+
SERVER_ERROR: string;
|
|
52
|
+
TEMPORARILY_UNAVAILABLE: string;
|
|
53
|
+
};
|
|
54
|
+
ACCESS_TOKEN: {
|
|
55
|
+
INVALID_REQUEST: string;
|
|
56
|
+
INVALID_CLIENT: string;
|
|
57
|
+
INVALID_GRANT: string;
|
|
58
|
+
UNAUTHORIZED_CLIENT: string;
|
|
59
|
+
UNSUPPORTED_GRANT_TYPE: string;
|
|
60
|
+
INVALID_SCOPE: string;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export { AuthError, ERROR_RESPONSE, InvalidCsrfTokenError, InvalidRedirectToError, isAuthError, throwAuthError };
|
package/dist/error.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
};
|
package/dist/headers.cjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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/headers.ts
|
|
21
|
+
var headers_exports = {};
|
|
22
|
+
__export(headers_exports, {
|
|
23
|
+
cacheControl: () => cacheControl
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(headers_exports);
|
|
26
|
+
var cacheControl = {
|
|
27
|
+
"Cache-Control": "no-store",
|
|
28
|
+
Pragma: "no-cache",
|
|
29
|
+
Expires: "0",
|
|
30
|
+
Vary: "Cookie"
|
|
31
|
+
};
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
cacheControl
|
|
35
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headers to prevent caching of responses. It includes Pragma header for HTTP/1.0 compatibility.
|
|
3
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control
|
|
4
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Pragma
|
|
5
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Vary
|
|
6
|
+
*/
|
|
7
|
+
declare const cacheControl: HeadersInit;
|
|
8
|
+
|
|
9
|
+
export { cacheControl };
|