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