@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.
- package/dist/@types/index.cjs +15 -15
- package/dist/@types/index.d.ts +6 -31
- package/dist/@types/index.js +1 -1
- package/dist/@types/router.d.cjs +1 -1
- package/dist/@types/router.d.d.ts +6 -7
- package/dist/@types/utility.cjs +15 -15
- package/dist/@types/utility.d.ts +4 -8
- package/dist/@types/utility.js +1 -1
- package/dist/actions/callback/access-token.cjs +159 -149
- package/dist/actions/callback/access-token.d.ts +14 -20
- package/dist/actions/callback/access-token.js +9 -4
- package/dist/actions/callback/callback.cjs +371 -484
- package/dist/actions/callback/callback.d.ts +9 -12
- package/dist/actions/callback/callback.js +15 -12
- package/dist/actions/callback/userinfo.cjs +149 -139
- package/dist/actions/callback/userinfo.d.ts +8 -9
- package/dist/actions/callback/userinfo.js +11 -6
- package/dist/actions/csrfToken/csrfToken.cjs +112 -190
- package/dist/actions/csrfToken/csrfToken.d.ts +3 -3
- package/dist/actions/csrfToken/csrfToken.js +12 -8
- package/dist/actions/index.cjs +623 -807
- package/dist/actions/index.d.ts +12 -13
- package/dist/actions/index.js +33 -18
- package/dist/actions/session/session.cjs +86 -176
- package/dist/actions/session/session.d.ts +3 -3
- package/dist/actions/session/session.js +10 -7
- package/dist/actions/signIn/authorization.cjs +248 -257
- package/dist/actions/signIn/authorization.d.ts +11 -18
- package/dist/actions/signIn/authorization.js +16 -6
- package/dist/actions/signIn/signIn.cjs +302 -451
- package/dist/actions/signIn/signIn.d.ts +9 -10
- package/dist/actions/signIn/signIn.js +12 -10
- package/dist/actions/signOut/signOut.cjs +299 -468
- package/dist/actions/signOut/signOut.d.ts +3 -3
- package/dist/actions/signOut/signOut.js +14 -11
- package/dist/assert.cjs +40 -36
- package/dist/assert.d.ts +12 -4
- package/dist/assert.js +12 -2
- package/dist/chunk-2RXNXMCZ.js +55 -0
- package/dist/chunk-42XB3YCW.js +19 -17
- package/dist/chunk-4V4JNXVF.js +55 -0
- package/dist/chunk-6R2YZ4AC.js +22 -0
- package/dist/chunk-7H3OR6UU.js +81 -0
- package/dist/chunk-CXLATHS5.js +143 -0
- package/dist/chunk-E3OXBRYF.js +19 -17
- package/dist/chunk-EIL2FPSS.js +22 -0
- package/dist/chunk-FIPU4MLT.js +18 -16
- package/dist/chunk-FKRDCWBF.js +19 -17
- package/dist/chunk-IKHPGFCW.js +11 -9
- package/dist/chunk-IMICRJ5U.js +197 -0
- package/dist/chunk-IUYZQTJV.js +30 -0
- package/dist/chunk-KRNOMBXQ.js +19 -17
- package/dist/chunk-N2APGLXA.js +71 -0
- package/dist/chunk-NEVKX6K2.js +70 -0
- package/dist/chunk-PTJUYB33.js +33 -0
- package/dist/chunk-QDO2KSRJ.js +35 -0
- package/dist/chunk-QEZL7EYN.js +96 -0
- package/dist/chunk-RRLIF4PQ.js +55 -0
- package/dist/chunk-STHEPPUZ.js +8 -6
- package/dist/chunk-TLE4PXY3.js +39 -0
- package/dist/chunk-UEH3LVON.js +97 -0
- package/dist/chunk-WD7AUHQ5.js +79 -0
- package/dist/chunk-ZLR3LI6X.js +55 -0
- package/dist/cookie.cjs +222 -187
- package/dist/cookie.d.ts +38 -76
- package/dist/cookie.js +27 -34
- package/dist/errors.cjs +85 -0
- package/dist/errors.d.ts +48 -0
- package/dist/errors.js +18 -0
- package/dist/headers.cjs +28 -28
- package/dist/headers.d.ts +2 -2
- package/dist/headers.js +6 -2
- package/dist/{index-DpfbvTZ_.d.ts → index-EqsoyjrF.d.ts} +351 -318
- package/dist/index.cjs +1006 -1001
- package/dist/index.d.ts +9 -31
- package/dist/index.js +82 -51
- package/dist/jose.cjs +74 -66
- package/dist/jose.d.ts +11 -8
- package/dist/jose.js +10 -5
- package/dist/oauth/bitbucket.cjs +38 -38
- package/dist/oauth/bitbucket.d.ts +6 -7
- package/dist/oauth/bitbucket.js +6 -2
- package/dist/oauth/discord.cjs +47 -48
- package/dist/oauth/discord.d.ts +6 -7
- package/dist/oauth/discord.js +6 -2
- package/dist/oauth/figma.cjs +39 -39
- package/dist/oauth/figma.d.ts +6 -7
- package/dist/oauth/figma.js +6 -2
- package/dist/oauth/github.cjs +31 -31
- package/dist/oauth/github.d.ts +6 -7
- package/dist/oauth/github.js +6 -2
- package/dist/oauth/gitlab.cjs +39 -39
- package/dist/oauth/gitlab.d.ts +6 -7
- package/dist/oauth/gitlab.js +6 -2
- package/dist/oauth/index.cjs +306 -180
- package/dist/oauth/index.d.ts +6 -26
- package/dist/oauth/index.js +43 -9
- package/dist/oauth/spotify.cjs +39 -39
- package/dist/oauth/spotify.d.ts +6 -7
- package/dist/oauth/spotify.js +6 -2
- package/dist/oauth/strava.cjs +46 -0
- package/dist/oauth/strava.d.ts +6 -0
- package/dist/oauth/strava.js +6 -0
- package/dist/oauth/x.cjs +39 -39
- package/dist/oauth/x.d.ts +6 -7
- package/dist/oauth/x.js +6 -2
- package/dist/schemas.cjs +97 -91
- package/dist/schemas.d.ts +96 -126
- package/dist/schemas.js +20 -18
- package/dist/secure.cjs +106 -101
- package/dist/secure.d.ts +16 -17
- package/dist/secure.js +19 -4
- package/dist/utils.cjs +197 -135
- package/dist/utils.d.ts +20 -26
- package/dist/utils.js +25 -21
- package/package.json +5 -6
- package/dist/chunk-256KIVJL.js +0 -110
- package/dist/chunk-6SM22VVJ.js +0 -15
- package/dist/chunk-CAKJT3KS.js +0 -77
- package/dist/chunk-EBPE35JT.js +0 -29
- package/dist/chunk-FJUDBLCP.js +0 -52
- package/dist/chunk-GZU3RBTB.js +0 -51
- package/dist/chunk-HGJ4TXY4.js +0 -105
- package/dist/chunk-HMRKN75I.js +0 -74
- package/dist/chunk-JAPMIE6S.js +0 -8
- package/dist/chunk-LLR722CL.js +0 -75
- package/dist/chunk-RLT4RFKV.js +0 -36
- package/dist/chunk-SJPDVKUS.js +0 -93
- package/dist/chunk-SMQO5WD7.js +0 -20
- package/dist/chunk-UJJ7R56J.js +0 -42
- package/dist/chunk-UTDLUEEG.js +0 -25
- package/dist/chunk-VFTYH33W.js +0 -44
- package/dist/chunk-XXJKNKGQ.js +0 -27
- package/dist/chunk-ZV4BH47P.js +0 -156
- package/dist/error.cjs +0 -88
- package/dist/error.d.ts +0 -62
- package/dist/error.js +0 -9
- package/dist/response.cjs +0 -34
- package/dist/response.d.ts +0 -10
- package/dist/response.js +0 -2
package/dist/cookie.cjs
CHANGED
|
@@ -1,207 +1,242 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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/cookie.ts
|
|
20
|
-
var cookie_exports = {}
|
|
21
|
+
var cookie_exports = {};
|
|
21
22
|
__export(cookie_exports, {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
})
|
|
38
|
-
module.exports = __toCommonJS(cookie_exports)
|
|
39
|
-
var import_cookie = require("cookie")
|
|
40
|
-
|
|
41
|
-
// src/error.ts
|
|
42
|
-
var AuthError = class extends Error {
|
|
43
|
-
constructor(type, message) {
|
|
44
|
-
super(message)
|
|
45
|
-
this.type = type
|
|
46
|
-
this.name = "AuthError"
|
|
47
|
-
}
|
|
48
|
-
}
|
|
23
|
+
COOKIE_NAME: () => COOKIE_NAME,
|
|
24
|
+
createCookieStore: () => createCookieStore,
|
|
25
|
+
createSessionCookie: () => createSessionCookie,
|
|
26
|
+
defaultCookieOptions: () => defaultCookieOptions,
|
|
27
|
+
defaultHostCookieConfig: () => defaultHostCookieConfig,
|
|
28
|
+
defaultSecureCookieConfig: () => defaultSecureCookieConfig,
|
|
29
|
+
defaultStandardCookieConfig: () => defaultStandardCookieConfig,
|
|
30
|
+
defineSecureCookieOptions: () => defineSecureCookieOptions,
|
|
31
|
+
expiredCookieAttributes: () => expiredCookieAttributes,
|
|
32
|
+
getCookie: () => getCookie,
|
|
33
|
+
getSetCookie: () => getSetCookie,
|
|
34
|
+
setCookie: () => setCookie
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(cookie_exports);
|
|
37
|
+
var import_cookie = require("@aura-stack/router/cookie");
|
|
49
38
|
|
|
50
|
-
// src/
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
39
|
+
// src/errors.ts
|
|
40
|
+
var AuthInternalError = class extends Error {
|
|
41
|
+
type = "AUTH_INTERNAL_ERROR";
|
|
42
|
+
code;
|
|
43
|
+
constructor(code, message, options) {
|
|
44
|
+
super(message, options);
|
|
45
|
+
this.code = code;
|
|
46
|
+
this.name = new.target.name;
|
|
47
|
+
Error.captureStackTrace(this, new.target);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
54
50
|
|
|
55
51
|
// src/cookie.ts
|
|
56
|
-
var
|
|
57
|
-
var COOKIE_NAME = "aura-auth"
|
|
52
|
+
var COOKIE_NAME = "aura-auth";
|
|
58
53
|
var defaultCookieOptions = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
var defaultCookieConfig = {
|
|
65
|
-
strategy: "standard",
|
|
66
|
-
name: COOKIE_NAME,
|
|
67
|
-
options: defaultCookieOptions,
|
|
68
|
-
}
|
|
54
|
+
httpOnly: true,
|
|
55
|
+
sameSite: "lax",
|
|
56
|
+
path: "/",
|
|
57
|
+
maxAge: 60 * 60 * 24 * 15
|
|
58
|
+
};
|
|
69
59
|
var defaultStandardCookieConfig = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
60
|
+
secure: false,
|
|
61
|
+
httpOnly: true
|
|
62
|
+
};
|
|
74
63
|
var defaultSecureCookieConfig = {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
64
|
+
secure: true,
|
|
65
|
+
httpOnly: true
|
|
66
|
+
};
|
|
78
67
|
var defaultHostCookieConfig = {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
var
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
name: options?.name ?? COOKIE_NAME,
|
|
92
|
-
prefix: options?.prefix ?? (options?.secure ? "__Secure-" : ""),
|
|
93
|
-
...defaultCookieOptions,
|
|
94
|
-
...options,
|
|
95
|
-
}
|
|
96
|
-
}
|
|
68
|
+
secure: true,
|
|
69
|
+
httpOnly: true,
|
|
70
|
+
path: "/",
|
|
71
|
+
domain: void 0
|
|
72
|
+
};
|
|
73
|
+
var oauthCookieOptions = {
|
|
74
|
+
httpOnly: true,
|
|
75
|
+
maxAge: 5 * 60,
|
|
76
|
+
sameSite: "lax",
|
|
77
|
+
expires: new Date(Date.now() + 5 * 60 * 1e3)
|
|
78
|
+
};
|
|
97
79
|
var setCookie = (cookieName, value, options) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
var getCookie = (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
80
|
+
return (0, import_cookie.serialize)(cookieName, value, options);
|
|
81
|
+
};
|
|
82
|
+
var expiredCookieAttributes = {
|
|
83
|
+
...defaultCookieOptions,
|
|
84
|
+
expires: /* @__PURE__ */ new Date(0),
|
|
85
|
+
maxAge: 0
|
|
86
|
+
};
|
|
87
|
+
var getCookie = (request, cookieName) => {
|
|
88
|
+
const cookies = request.headers.get("Cookie");
|
|
89
|
+
if (!cookies) {
|
|
90
|
+
throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
|
|
91
|
+
}
|
|
92
|
+
const value = (0, import_cookie.parse)(cookies)[cookieName];
|
|
93
|
+
if (!value) {
|
|
94
|
+
throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found. There is no active session`);
|
|
95
|
+
}
|
|
96
|
+
return value;
|
|
97
|
+
};
|
|
98
|
+
var getSetCookie = (response, cookieName) => {
|
|
99
|
+
const cookies = response.headers.getSetCookie();
|
|
100
|
+
if (!cookies) {
|
|
101
|
+
throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found in response.");
|
|
102
|
+
}
|
|
103
|
+
const strCookie = cookies.find((cookie) => cookie.startsWith(`${cookieName}=`));
|
|
104
|
+
if (!strCookie) {
|
|
105
|
+
throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found in response.`);
|
|
106
|
+
}
|
|
107
|
+
return (0, import_cookie.parseSetCookie)(strCookie).value;
|
|
108
|
+
};
|
|
109
|
+
var createSessionCookie = async (jose, session) => {
|
|
110
|
+
try {
|
|
111
|
+
const encoded = await jose.encodeJWT(session);
|
|
112
|
+
return encoded;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
throw new AuthInternalError("INVALID_JWT_TOKEN", "Failed to create session cookie", { cause: error });
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var defineSecureCookieOptions = (useSecure, attributes, strategy) => {
|
|
118
|
+
if (!attributes.httpOnly) {
|
|
119
|
+
console.warn(
|
|
120
|
+
"[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
if (attributes.domain === "*") {
|
|
124
|
+
attributes.domain = void 0;
|
|
125
|
+
console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.");
|
|
126
|
+
}
|
|
127
|
+
if (!useSecure) {
|
|
128
|
+
if (attributes.secure) {
|
|
129
|
+
console.warn(
|
|
130
|
+
"[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
|
|
131
|
+
);
|
|
121
132
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
try {
|
|
126
|
-
const encoded = await jose.encodeJWT(session)
|
|
127
|
-
return setCookie("sessionToken", encoded, cookieOptions)
|
|
128
|
-
} catch (error) {
|
|
129
|
-
throw new AuthError("server_error", "Failed to create session cookie", { cause: error })
|
|
133
|
+
if (attributes.sameSite == "none") {
|
|
134
|
+
attributes.sameSite = "lax";
|
|
135
|
+
console.warn("[WARNING]: SameSite=None requires Secure attribute. Changing SameSite to 'Lax'.");
|
|
130
136
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const name = cookieOptions.name ?? COOKIE_NAME
|
|
134
|
-
const isSecure = trustedProxyHeaders
|
|
135
|
-
? request.url.startsWith("https://") ||
|
|
136
|
-
request.headers.get("X-Forwarded-Proto") === "https" ||
|
|
137
|
-
request.headers.get("Forwarded")?.includes("proto=https")
|
|
138
|
-
: request.url.startsWith("https://")
|
|
139
|
-
if (!cookieOptions.options?.httpOnly) {
|
|
140
|
-
console.warn(
|
|
141
|
-
"[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
|
|
142
|
-
)
|
|
137
|
+
if (process.env.NODE_ENV === "production") {
|
|
138
|
+
console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.");
|
|
143
139
|
}
|
|
144
|
-
if (
|
|
145
|
-
|
|
140
|
+
if (strategy === "host") {
|
|
141
|
+
console.warn("[WARNING]: __Host- cookies require a secure context. Falling back to standard cookie settings.");
|
|
146
142
|
}
|
|
147
|
-
if (!isSecure) {
|
|
148
|
-
const options = cookieOptions.options
|
|
149
|
-
if (options?.secure) {
|
|
150
|
-
console.warn(
|
|
151
|
-
"[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
|
|
152
|
-
)
|
|
153
|
-
}
|
|
154
|
-
if (options?.sameSite == "none") {
|
|
155
|
-
console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.")
|
|
156
|
-
}
|
|
157
|
-
if (process.env.NODE_ENV === "production") {
|
|
158
|
-
console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.")
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
...defaultCookieOptions,
|
|
162
|
-
...cookieOptions.options,
|
|
163
|
-
sameSite: options?.sameSite === "none" ? "lax" : (options?.sameSite ?? "lax"),
|
|
164
|
-
...defaultStandardCookieConfig,
|
|
165
|
-
name,
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return cookieOptions.strategy === "host"
|
|
169
|
-
? {
|
|
170
|
-
...defaultCookieOptions,
|
|
171
|
-
...cookieOptions.options,
|
|
172
|
-
...defaultHostCookieConfig,
|
|
173
|
-
name,
|
|
174
|
-
}
|
|
175
|
-
: { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name }
|
|
176
|
-
}
|
|
177
|
-
var expireCookie = (name, options) => {
|
|
178
|
-
return setCookie(name, "", { ...options, ...expiredCookieOptions })
|
|
179
|
-
}
|
|
180
|
-
var oauthCookie = (options) => {
|
|
181
143
|
return {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
144
|
+
...defaultCookieOptions,
|
|
145
|
+
...attributes,
|
|
146
|
+
...defaultStandardCookieConfig
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return strategy === "host" ? {
|
|
150
|
+
...defaultCookieOptions,
|
|
151
|
+
...attributes,
|
|
152
|
+
...defaultHostCookieConfig
|
|
153
|
+
} : { ...defaultCookieOptions, ...attributes, ...defaultSecureCookieConfig };
|
|
154
|
+
};
|
|
155
|
+
var createCookieStore = (useSecure, prefix, overrides) => {
|
|
156
|
+
prefix ??= COOKIE_NAME;
|
|
157
|
+
const securePrefix = useSecure ? "__Secure-" : "";
|
|
158
|
+
const hostPrefix = useSecure ? "__Host-" : "";
|
|
159
|
+
return {
|
|
160
|
+
sessionToken: {
|
|
161
|
+
name: `${securePrefix}${prefix}.${overrides?.sessionToken?.name ?? "sessionToken"}`,
|
|
162
|
+
attributes: defineSecureCookieOptions(
|
|
163
|
+
useSecure,
|
|
164
|
+
{
|
|
165
|
+
...defaultCookieOptions,
|
|
166
|
+
...overrides?.sessionToken?.attributes
|
|
167
|
+
},
|
|
168
|
+
overrides?.sessionToken?.attributes?.strategy ?? "secure"
|
|
169
|
+
)
|
|
170
|
+
},
|
|
171
|
+
state: {
|
|
172
|
+
name: `${securePrefix}${prefix}.${overrides?.state?.name ?? "state"}`,
|
|
173
|
+
attributes: defineSecureCookieOptions(
|
|
174
|
+
useSecure,
|
|
175
|
+
{
|
|
176
|
+
...oauthCookieOptions,
|
|
177
|
+
...overrides?.state?.attributes
|
|
178
|
+
},
|
|
179
|
+
overrides?.state?.attributes?.strategy ?? "secure"
|
|
180
|
+
)
|
|
181
|
+
},
|
|
182
|
+
csrfToken: {
|
|
183
|
+
name: `${hostPrefix}${prefix}.${overrides?.csrfToken?.name ?? "csrfToken"}`,
|
|
184
|
+
attributes: defineSecureCookieOptions(
|
|
185
|
+
useSecure,
|
|
186
|
+
{
|
|
187
|
+
...overrides?.csrfToken?.attributes,
|
|
188
|
+
...defaultHostCookieConfig
|
|
189
|
+
},
|
|
190
|
+
overrides?.csrfToken?.attributes?.strategy ?? "host"
|
|
191
|
+
)
|
|
192
|
+
},
|
|
193
|
+
redirect_to: {
|
|
194
|
+
name: `${securePrefix}${prefix}.${overrides?.redirect_to?.name ?? "redirect_to"}`,
|
|
195
|
+
attributes: defineSecureCookieOptions(
|
|
196
|
+
useSecure,
|
|
197
|
+
{
|
|
198
|
+
...oauthCookieOptions,
|
|
199
|
+
...overrides?.redirect_to?.attributes
|
|
200
|
+
},
|
|
201
|
+
overrides?.redirect_to?.attributes?.strategy ?? "secure"
|
|
202
|
+
)
|
|
203
|
+
},
|
|
204
|
+
redirect_uri: {
|
|
205
|
+
name: `${securePrefix}${prefix}.${overrides?.redirect_uri?.name ?? "redirect_uri"}`,
|
|
206
|
+
attributes: defineSecureCookieOptions(
|
|
207
|
+
useSecure,
|
|
208
|
+
{
|
|
209
|
+
...oauthCookieOptions,
|
|
210
|
+
...overrides?.redirect_uri?.attributes
|
|
211
|
+
},
|
|
212
|
+
overrides?.redirect_uri?.attributes?.strategy ?? "secure"
|
|
213
|
+
)
|
|
214
|
+
},
|
|
215
|
+
code_verifier: {
|
|
216
|
+
name: `${securePrefix}${prefix}.${overrides?.code_verifier?.name ?? "code_verifier"}`,
|
|
217
|
+
attributes: defineSecureCookieOptions(
|
|
218
|
+
useSecure,
|
|
219
|
+
{
|
|
220
|
+
...oauthCookieOptions,
|
|
221
|
+
...overrides?.code_verifier?.attributes
|
|
222
|
+
},
|
|
223
|
+
overrides?.code_verifier?.attributes?.strategy ?? "secure"
|
|
224
|
+
)
|
|
187
225
|
}
|
|
188
|
-
}
|
|
226
|
+
};
|
|
227
|
+
};
|
|
189
228
|
// Annotate the CommonJS export names for ESM import in node:
|
|
190
|
-
0 &&
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
parse,
|
|
205
|
-
secureCookieOptions,
|
|
206
|
-
setCookie,
|
|
207
|
-
})
|
|
229
|
+
0 && (module.exports = {
|
|
230
|
+
COOKIE_NAME,
|
|
231
|
+
createCookieStore,
|
|
232
|
+
createSessionCookie,
|
|
233
|
+
defaultCookieOptions,
|
|
234
|
+
defaultHostCookieConfig,
|
|
235
|
+
defaultSecureCookieConfig,
|
|
236
|
+
defaultStandardCookieConfig,
|
|
237
|
+
defineSecureCookieOptions,
|
|
238
|
+
expiredCookieAttributes,
|
|
239
|
+
getCookie,
|
|
240
|
+
getSetCookie,
|
|
241
|
+
setCookie
|
|
242
|
+
});
|
package/dist/cookie.d.ts
CHANGED
|
@@ -1,75 +1,63 @@
|
|
|
1
|
-
import { SerializeOptions } from
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import "./schemas.js"
|
|
8
|
-
import "zod/v4/core"
|
|
1
|
+
import { SerializeOptions } from '@aura-stack/router/cookie';
|
|
2
|
+
import { JWTPayload } from '@aura-stack/jose/jose';
|
|
3
|
+
import { A as AuthRuntimeConfig, C as CookieConfig, a as CookieStoreConfig } from './index-EqsoyjrF.js';
|
|
4
|
+
import 'zod/v4';
|
|
5
|
+
import './schemas.js';
|
|
6
|
+
import './@types/utility.js';
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* Prefix for all cookies set by Aura Auth.
|
|
12
10
|
*/
|
|
13
|
-
declare const COOKIE_NAME = "aura-auth"
|
|
11
|
+
declare const COOKIE_NAME = "aura-auth";
|
|
14
12
|
/**
|
|
15
13
|
* Default cookie options used by Aura Auth.
|
|
16
14
|
*/
|
|
17
|
-
declare const defaultCookieOptions: SerializeOptions
|
|
15
|
+
declare const defaultCookieOptions: SerializeOptions;
|
|
16
|
+
declare const defaultStandardCookieConfig: SerializeOptions;
|
|
18
17
|
/**
|
|
19
|
-
* Default cookie options for "
|
|
20
|
-
*/
|
|
21
|
-
declare const defaultCookieConfig: CookieConfig
|
|
22
|
-
declare const defaultStandardCookieConfig: CookieConfigInternal
|
|
23
|
-
/**
|
|
24
|
-
* Default cookie options for "secure" cookies.
|
|
18
|
+
* Default cookie options for "__Secure-" cookies.
|
|
25
19
|
* @see https://httpwg.org/http-extensions/draft-ietf-httpbis-rfc6265bis.html#name-the-__secure-prefix
|
|
26
20
|
*/
|
|
27
|
-
declare const defaultSecureCookieConfig:
|
|
21
|
+
declare const defaultSecureCookieConfig: SerializeOptions;
|
|
28
22
|
/**
|
|
29
|
-
* Default cookie options for "
|
|
23
|
+
* Default cookie options for "__Host-" cookies.
|
|
30
24
|
* @see https://httpwg.org/http-extensions/draft-ietf-httpbis-rfc6265bis.html#name-the-__host-prefix
|
|
31
25
|
*/
|
|
32
|
-
declare const defaultHostCookieConfig:
|
|
33
|
-
/**
|
|
34
|
-
* Cookie options for expired cookies.
|
|
35
|
-
*/
|
|
36
|
-
declare const expiredCookieOptions: SerializeOptions
|
|
37
|
-
declare const defineDefaultCookieOptions: (options?: CookieConfigInternal) => CookieConfigInternal
|
|
26
|
+
declare const defaultHostCookieConfig: SerializeOptions;
|
|
38
27
|
/**
|
|
39
|
-
* Set a cookie with the given name, value and `
|
|
28
|
+
* Set a cookie with the given name, value and `SerializeOptions`; supports secure
|
|
40
29
|
* cookies with the `__Secure-` and `__Host-` prefixes.
|
|
41
30
|
*
|
|
42
31
|
* Cookie attributes are serialized in the following order:
|
|
43
32
|
* Expires, Max-Age, Domain, Path, Secure, HttpOnly, SameSite, Partitioned, Priority.
|
|
44
33
|
*/
|
|
45
|
-
declare const setCookie: (cookieName:
|
|
34
|
+
declare const setCookie: (cookieName: string, value: string, options?: SerializeOptions) => string;
|
|
35
|
+
declare const expiredCookieAttributes: SerializeOptions;
|
|
46
36
|
/**
|
|
47
37
|
* Get a cookie by name from the request.
|
|
48
38
|
*
|
|
49
39
|
* @param request The incoming request object
|
|
50
40
|
* @param cookie Cookie name to retrieve
|
|
51
|
-
* @
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
* @returns The value of the cookie or throw an error if not found
|
|
42
|
+
*/
|
|
43
|
+
declare const getCookie: (request: Request, cookieName: string) => string;
|
|
44
|
+
/**
|
|
45
|
+
* Get a Set-Cookie header value by cookie name from the response.
|
|
46
|
+
*
|
|
47
|
+
* @param response The response object
|
|
48
|
+
* @param cookieName Cookie name to retrieve
|
|
49
|
+
* @returns The value of the Set-Cookie header or throw an error if not found
|
|
54
50
|
*/
|
|
55
|
-
declare const
|
|
56
|
-
petition: Request | Response,
|
|
57
|
-
cookie: LiteralUnion<CookieName>,
|
|
58
|
-
options?: CookieConfigInternal,
|
|
59
|
-
optional?: boolean
|
|
60
|
-
) => string
|
|
51
|
+
declare const getSetCookie: (response: Response, cookieName: string) => string | undefined;
|
|
61
52
|
/**
|
|
62
53
|
* Create a session cookie containing a signed and encrypted JWT, using the
|
|
63
54
|
* `@aura-stack/jose` package for the encoding.
|
|
64
55
|
*
|
|
56
|
+
* @param jose - Jose Instance
|
|
65
57
|
* @param session - The JWT payload to be encoded in the session cookie
|
|
66
58
|
* @returns The serialized session cookie string
|
|
67
59
|
*/
|
|
68
|
-
declare const createSessionCookie: (
|
|
69
|
-
session: JWTPayload,
|
|
70
|
-
cookieOptions: CookieConfigInternal,
|
|
71
|
-
jose: AuthRuntimeConfig["jose"]
|
|
72
|
-
) => Promise<string>
|
|
60
|
+
declare const createSessionCookie: (jose: AuthRuntimeConfig["jose"], session: JWTPayload) => Promise<string>;
|
|
73
61
|
/**
|
|
74
62
|
* Defines the cookie configuration based on the request security and cookie options passed
|
|
75
63
|
* in the Aura Auth configuration (`createAuth` function). This function ensures the correct
|
|
@@ -78,44 +66,18 @@ declare const createSessionCookie: (
|
|
|
78
66
|
*
|
|
79
67
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-Proto
|
|
80
68
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Forwarded
|
|
81
|
-
* @param
|
|
82
|
-
* @param
|
|
69
|
+
* @param useSecure Whether the request is secure (HTTPS)
|
|
70
|
+
* @param attributes The cookie attributes to be applied
|
|
71
|
+
* @param strategy The cookie strategy: "host", "secure", or "standard"
|
|
83
72
|
* @returns The finalized cookie options to be used for setting cookies
|
|
84
73
|
*/
|
|
85
|
-
declare const
|
|
86
|
-
request: Request,
|
|
87
|
-
cookieOptions: CookieConfig,
|
|
88
|
-
trustedProxyHeaders?: boolean
|
|
89
|
-
) => CookieConfigInternal
|
|
90
|
-
/**
|
|
91
|
-
* Expire a cookie by setting its value to an empty string and applying expired cookie options.
|
|
92
|
-
*
|
|
93
|
-
* @param name The name of the cookie to expire
|
|
94
|
-
* @param options cookie options obtained from secureCookieOptions
|
|
95
|
-
* @returns formatted cookie options for an expired cookie
|
|
96
|
-
*/
|
|
97
|
-
declare const expireCookie: (name: LiteralUnion<CookieName>, options: CookieConfigInternal) => string
|
|
74
|
+
declare const defineSecureCookieOptions: (useSecure: boolean, attributes: SerializeOptions, strategy: "host" | "secure" | "standard") => SerializeOptions;
|
|
98
75
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* @param
|
|
102
|
-
* @returns
|
|
76
|
+
* @param useSecure Whether the request is secure (HTTPS)
|
|
77
|
+
* @param prefix Optional prefix added to all cookie names
|
|
78
|
+
* @param overrides Optional overrides for individual cookie configurations
|
|
79
|
+
* @returns The complete cookie store configuration
|
|
103
80
|
*/
|
|
104
|
-
declare const
|
|
81
|
+
declare const createCookieStore: (useSecure: boolean, prefix?: string, overrides?: CookieConfig["overrides"]) => CookieStoreConfig;
|
|
105
82
|
|
|
106
|
-
export {
|
|
107
|
-
COOKIE_NAME,
|
|
108
|
-
createSessionCookie,
|
|
109
|
-
defaultCookieConfig,
|
|
110
|
-
defaultCookieOptions,
|
|
111
|
-
defaultHostCookieConfig,
|
|
112
|
-
defaultSecureCookieConfig,
|
|
113
|
-
defaultStandardCookieConfig,
|
|
114
|
-
defineDefaultCookieOptions,
|
|
115
|
-
expireCookie,
|
|
116
|
-
expiredCookieOptions,
|
|
117
|
-
getCookie,
|
|
118
|
-
oauthCookie,
|
|
119
|
-
secureCookieOptions,
|
|
120
|
-
setCookie,
|
|
121
|
-
}
|
|
83
|
+
export { COOKIE_NAME, createCookieStore, createSessionCookie, defaultCookieOptions, defaultHostCookieConfig, defaultSecureCookieConfig, defaultStandardCookieConfig, defineSecureCookieOptions, expiredCookieAttributes, getCookie, getSetCookie, setCookie };
|
package/dist/cookie.js
CHANGED
|
@@ -1,36 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
setCookie,
|
|
17
|
-
} from "./chunk-ZV4BH47P.js"
|
|
18
|
-
import "./chunk-6SM22VVJ.js"
|
|
19
|
-
import "./chunk-FJUDBLCP.js"
|
|
2
|
+
COOKIE_NAME,
|
|
3
|
+
createCookieStore,
|
|
4
|
+
createSessionCookie,
|
|
5
|
+
defaultCookieOptions,
|
|
6
|
+
defaultHostCookieConfig,
|
|
7
|
+
defaultSecureCookieConfig,
|
|
8
|
+
defaultStandardCookieConfig,
|
|
9
|
+
defineSecureCookieOptions,
|
|
10
|
+
expiredCookieAttributes,
|
|
11
|
+
getCookie,
|
|
12
|
+
getSetCookie,
|
|
13
|
+
setCookie
|
|
14
|
+
} from "./chunk-IMICRJ5U.js";
|
|
15
|
+
import "./chunk-RRLIF4PQ.js";
|
|
20
16
|
export {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
secureCookieOptions,
|
|
35
|
-
setCookie,
|
|
36
|
-
}
|
|
17
|
+
COOKIE_NAME,
|
|
18
|
+
createCookieStore,
|
|
19
|
+
createSessionCookie,
|
|
20
|
+
defaultCookieOptions,
|
|
21
|
+
defaultHostCookieConfig,
|
|
22
|
+
defaultSecureCookieConfig,
|
|
23
|
+
defaultStandardCookieConfig,
|
|
24
|
+
defineSecureCookieOptions,
|
|
25
|
+
expiredCookieAttributes,
|
|
26
|
+
getCookie,
|
|
27
|
+
getSetCookie,
|
|
28
|
+
setCookie
|
|
29
|
+
};
|