@aura-stack/auth 0.1.0-rc.9 → 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.cjs +15 -15
- package/dist/@types/index.d.ts +7 -31
- package/dist/@types/index.js +1 -1
- package/dist/@types/router.d.cjs +1 -1
- package/dist/@types/router.d.d.ts +7 -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 +176 -155
- package/dist/actions/callback/access-token.d.ts +15 -20
- package/dist/actions/callback/access-token.js +10 -4
- package/dist/actions/callback/callback.cjs +394 -490
- package/dist/actions/callback/callback.d.ts +10 -12
- package/dist/actions/callback/callback.js +16 -12
- package/dist/actions/callback/userinfo.cjs +166 -145
- package/dist/actions/callback/userinfo.d.ts +9 -9
- package/dist/actions/callback/userinfo.js +12 -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 +652 -814
- package/dist/actions/index.d.ts +13 -13
- package/dist/actions/index.js +34 -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 +254 -263
- package/dist/actions/signIn/authorization.d.ts +12 -18
- package/dist/actions/signIn/authorization.js +16 -6
- package/dist/actions/signIn/signIn.cjs +320 -456
- package/dist/actions/signIn/signIn.d.ts +10 -10
- package/dist/actions/signIn/signIn.js +13 -10
- package/dist/actions/signOut/signOut.cjs +304 -473
- 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 +13 -4
- package/dist/assert.js +12 -2
- package/dist/chunk-3EUWD5BB.js +63 -0
- package/dist/chunk-42XB3YCW.js +19 -17
- package/dist/chunk-6R2YZ4AC.js +22 -0
- package/dist/chunk-A3N4PVAT.js +70 -0
- package/dist/chunk-B737EUJV.js +22 -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-EMKJA2GJ.js +89 -0
- package/dist/chunk-FIPU4MLT.js +18 -16
- package/dist/chunk-FKRDCWBF.js +19 -17
- package/dist/chunk-GA2SMTJO.js +58 -0
- package/dist/chunk-HP34YGGJ.js +22 -0
- package/dist/chunk-HT4YLL7N.js +35 -0
- package/dist/chunk-IKHPGFCW.js +11 -9
- package/dist/chunk-IUYZQTJV.js +30 -0
- package/dist/chunk-IVET23KF.js +58 -0
- package/dist/chunk-JVFTCTTE.js +33 -0
- package/dist/chunk-KRNOMBXQ.js +19 -17
- package/dist/chunk-KSWLO5ZU.js +102 -0
- package/dist/chunk-N2APGLXA.js +71 -0
- package/dist/chunk-N4SX7TZT.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-W6LG7BFW.js +197 -0
- package/dist/chunk-YRCB5FLE.js +79 -0
- package/dist/chunk-ZNCZVF6U.js +14 -0
- package/dist/cookie.cjs +222 -187
- package/dist/cookie.d.ts +39 -76
- package/dist/cookie.js +27 -34
- package/dist/errors.cjs +85 -0
- package/dist/errors.d.ts +49 -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-DkaLJFn8.d.ts +679 -0
- package/dist/index.cjs +1074 -1007
- package/dist/index.d.ts +10 -31
- package/dist/index.js +85 -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 +7 -7
- package/dist/oauth/bitbucket.js +6 -2
- package/dist/oauth/discord.cjs +47 -48
- package/dist/oauth/discord.d.ts +7 -7
- package/dist/oauth/discord.js +6 -2
- package/dist/oauth/figma.cjs +39 -39
- package/dist/oauth/figma.d.ts +7 -7
- package/dist/oauth/figma.js +6 -2
- package/dist/oauth/github.cjs +31 -31
- package/dist/oauth/github.d.ts +7 -7
- package/dist/oauth/github.js +6 -2
- package/dist/oauth/gitlab.cjs +39 -39
- package/dist/oauth/gitlab.d.ts +7 -7
- package/dist/oauth/gitlab.js +6 -2
- package/dist/oauth/index.cjs +350 -180
- package/dist/oauth/index.d.ts +7 -26
- package/dist/oauth/index.js +51 -9
- 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.cjs +39 -39
- package/dist/oauth/spotify.d.ts +7 -7
- package/dist/oauth/spotify.js +6 -2
- 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.cjs +39 -39
- package/dist/oauth/x.d.ts +7 -7
- package/dist/oauth/x.js +6 -2
- package/dist/request.cjs +38 -0
- package/dist/request.d.ts +13 -0
- package/dist/request.js +6 -0
- package/dist/schemas.cjs +103 -97
- package/dist/schemas.d.ts +96 -126
- package/dist/schemas.js +20 -18
- package/dist/secure.cjs +106 -101
- package/dist/secure.d.ts +17 -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 +8 -7
- 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/index-DpfbvTZ_.d.ts +0 -597
- package/dist/response.cjs +0 -34
- package/dist/response.d.ts +0 -10
- package/dist/response.js +0 -2
package/dist/actions/index.cjs
CHANGED
|
@@ -1,891 +1,729 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
var __create = Object.create
|
|
3
|
-
var __defProp = Object.defineProperty
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __export = (target, all) => {
|
|
9
|
-
|
|
10
|
-
}
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
11
12
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
)
|
|
30
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod)
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
29
|
|
|
32
30
|
// src/actions/index.ts
|
|
33
|
-
var actions_exports = {}
|
|
31
|
+
var actions_exports = {};
|
|
34
32
|
__export(actions_exports, {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
})
|
|
41
|
-
module.exports = __toCommonJS(actions_exports)
|
|
33
|
+
callbackAction: () => callbackAction,
|
|
34
|
+
csrfTokenAction: () => csrfTokenAction,
|
|
35
|
+
sessionAction: () => sessionAction,
|
|
36
|
+
signInAction: () => signInAction,
|
|
37
|
+
signOutAction: () => signOutAction
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(actions_exports);
|
|
42
40
|
|
|
43
41
|
// src/actions/signIn/signIn.ts
|
|
44
|
-
var
|
|
45
|
-
var import_router2 = require("@aura-stack/router")
|
|
42
|
+
var import_zod2 = require("zod");
|
|
43
|
+
var import_router2 = require("@aura-stack/router");
|
|
46
44
|
|
|
47
|
-
// src/
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
// src/headers.ts
|
|
46
|
+
var cacheControl = {
|
|
47
|
+
"Cache-Control": "no-store",
|
|
48
|
+
Pragma: "no-cache",
|
|
49
|
+
Expires: "0",
|
|
50
|
+
Vary: "Cookie"
|
|
51
|
+
};
|
|
53
52
|
|
|
54
53
|
// src/secure.ts
|
|
55
|
-
var
|
|
54
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
56
55
|
|
|
57
56
|
// src/utils.ts
|
|
58
|
-
var import_router = require("@aura-stack/router")
|
|
57
|
+
var import_router = require("@aura-stack/router");
|
|
59
58
|
|
|
60
|
-
// src/
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
INVALID_REQUEST: "invalid_request",
|
|
103
|
-
INVALID_CLIENT: "invalid_client",
|
|
104
|
-
INVALID_GRANT: "invalid_grant",
|
|
105
|
-
UNAUTHORIZED_CLIENT: "unauthorized_client",
|
|
106
|
-
UNSUPPORTED_GRANT_TYPE: "unsupported_grant_type",
|
|
107
|
-
INVALID_SCOPE: "invalid_scope",
|
|
108
|
-
},
|
|
109
|
-
}
|
|
59
|
+
// src/errors.ts
|
|
60
|
+
var OAuthProtocolError = class extends Error {
|
|
61
|
+
type = "OAUTH_PROTOCOL_ERROR";
|
|
62
|
+
error;
|
|
63
|
+
errorURI;
|
|
64
|
+
constructor(error, description, errorURI, options2) {
|
|
65
|
+
super(description, options2);
|
|
66
|
+
this.error = error;
|
|
67
|
+
this.errorURI = errorURI;
|
|
68
|
+
this.name = new.target.name;
|
|
69
|
+
Error.captureStackTrace(this, new.target);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var AuthInternalError = class extends Error {
|
|
73
|
+
type = "AUTH_INTERNAL_ERROR";
|
|
74
|
+
code;
|
|
75
|
+
constructor(code, message, options2) {
|
|
76
|
+
super(message, options2);
|
|
77
|
+
this.code = code;
|
|
78
|
+
this.name = new.target.name;
|
|
79
|
+
Error.captureStackTrace(this, new.target);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var AuthSecurityError = class extends Error {
|
|
83
|
+
type = "AUTH_SECURITY_ERROR";
|
|
84
|
+
code;
|
|
85
|
+
constructor(code, message, options2) {
|
|
86
|
+
super(message, options2);
|
|
87
|
+
this.code = code;
|
|
88
|
+
this.name = new.target.name;
|
|
89
|
+
Error.captureStackTrace(this, new.target);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var isNativeError = (error) => {
|
|
93
|
+
return error instanceof Error;
|
|
94
|
+
};
|
|
95
|
+
var isOAuthProtocolError = (error) => {
|
|
96
|
+
return error instanceof OAuthProtocolError;
|
|
97
|
+
};
|
|
98
|
+
var isAuthSecurityError = (error) => {
|
|
99
|
+
return error instanceof AuthSecurityError;
|
|
100
|
+
};
|
|
110
101
|
|
|
111
102
|
// src/utils.ts
|
|
112
103
|
var toSnakeCase = (str) => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
|
|
116
|
-
.toLowerCase()
|
|
117
|
-
.replace(/^_+/, "")
|
|
118
|
-
}
|
|
104
|
+
return str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/^_+/, "");
|
|
105
|
+
};
|
|
119
106
|
var toUpperCase = (str) => {
|
|
120
|
-
|
|
121
|
-
}
|
|
107
|
+
return str.toUpperCase();
|
|
108
|
+
};
|
|
122
109
|
var toCastCase = (obj, type = "snake") => {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
110
|
+
return Object.entries(obj).reduce((previous, [key, value]) => {
|
|
111
|
+
const newKey = type === "snake" ? toSnakeCase(key) : toUpperCase(key);
|
|
112
|
+
return { ...previous, [newKey]: value };
|
|
113
|
+
}, {});
|
|
114
|
+
};
|
|
128
115
|
var equals = (a, b) => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
var sanitizeURL = (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
path = path.replace(/\/+$/, "/")
|
|
154
|
-
} else if (path !== "/") {
|
|
155
|
-
path = path.replace(/\/+$/, "")
|
|
156
|
-
}
|
|
157
|
-
return protocol + domain + path
|
|
158
|
-
}
|
|
159
|
-
let sanitized = decodedURL
|
|
160
|
-
.replace(/\/\.\.\//g, "/")
|
|
161
|
-
.replace(/\/\.\.$/, "")
|
|
162
|
-
.replace(/\.{2,}/g, "")
|
|
163
|
-
.replace(/\/{2,}/g, "/")
|
|
164
|
-
if (sanitized !== "/" && sanitized.endsWith("/")) {
|
|
165
|
-
sanitized = sanitized.replace(/\/+$/, "/")
|
|
166
|
-
} else if (sanitized !== "/") {
|
|
167
|
-
sanitized = sanitized.replace(/\/+$/, "")
|
|
168
|
-
}
|
|
169
|
-
return sanitized
|
|
170
|
-
} catch {
|
|
171
|
-
return url2.trim()
|
|
116
|
+
if (a === null || b === null || a === void 0 || b === void 0) return false;
|
|
117
|
+
return a === b;
|
|
118
|
+
};
|
|
119
|
+
var sanitizeURL = (url) => {
|
|
120
|
+
try {
|
|
121
|
+
let decodedURL = decodeURIComponent(url).trim();
|
|
122
|
+
const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
|
|
123
|
+
let protocol = "";
|
|
124
|
+
let rest = decodedURL;
|
|
125
|
+
if (protocolMatch) {
|
|
126
|
+
protocol = protocolMatch[1];
|
|
127
|
+
rest = decodedURL.slice(protocol.length);
|
|
128
|
+
const slashIndex = rest.indexOf("/");
|
|
129
|
+
if (slashIndex === -1) {
|
|
130
|
+
return protocol + rest;
|
|
131
|
+
}
|
|
132
|
+
const domain = rest.slice(0, slashIndex);
|
|
133
|
+
let path = rest.slice(slashIndex).replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
|
|
134
|
+
if (path !== "/" && path.endsWith("/")) {
|
|
135
|
+
path = path.replace(/\/+$/, "/");
|
|
136
|
+
} else if (path !== "/") {
|
|
137
|
+
path = path.replace(/\/+$/, "");
|
|
138
|
+
}
|
|
139
|
+
return protocol + domain + path;
|
|
172
140
|
}
|
|
173
|
-
}
|
|
141
|
+
let sanitized = decodedURL.replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
|
|
142
|
+
if (sanitized !== "/" && sanitized.endsWith("/")) {
|
|
143
|
+
sanitized = sanitized.replace(/\/+$/, "/");
|
|
144
|
+
} else if (sanitized !== "/") {
|
|
145
|
+
sanitized = sanitized.replace(/\/+$/, "");
|
|
146
|
+
}
|
|
147
|
+
return sanitized;
|
|
148
|
+
} catch {
|
|
149
|
+
return url.trim();
|
|
150
|
+
}
|
|
151
|
+
};
|
|
174
152
|
var isValidRelativePath = (path) => {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
153
|
+
if (!path || typeof path !== "string") return false;
|
|
154
|
+
if (!path.startsWith("/") || path.includes("://") || path.includes("\r") || path.includes("\n")) return false;
|
|
155
|
+
if (/[\x00-\x1F\x7F]/.test(path) || path.includes("\0")) return false;
|
|
156
|
+
const sanitized = sanitizeURL(path);
|
|
157
|
+
if (sanitized.includes("..")) return false;
|
|
158
|
+
return true;
|
|
159
|
+
};
|
|
182
160
|
var getNormalizedOriginPath = (path) => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
161
|
+
try {
|
|
162
|
+
const url = new URL(path);
|
|
163
|
+
url.hash = "";
|
|
164
|
+
url.search = "";
|
|
165
|
+
return `${url.origin}${url.pathname}`;
|
|
166
|
+
} catch {
|
|
167
|
+
return sanitizeURL(path);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
192
170
|
var toISOString = (date) => {
|
|
193
|
-
|
|
194
|
-
}
|
|
171
|
+
return new Date(date).toISOString();
|
|
172
|
+
};
|
|
173
|
+
var formatZodError = (error) => {
|
|
174
|
+
if (!error.issues || error.issues.length === 0) {
|
|
175
|
+
return {};
|
|
176
|
+
}
|
|
177
|
+
return error.issues.reduce((previous, issue) => {
|
|
178
|
+
const key = issue.path.join(".");
|
|
179
|
+
return {
|
|
180
|
+
...previous,
|
|
181
|
+
[key]: {
|
|
182
|
+
code: issue.code,
|
|
183
|
+
message: issue.message
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}, {});
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// src/assert.ts
|
|
190
|
+
var isValidURL = (value) => {
|
|
191
|
+
if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false;
|
|
192
|
+
const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/;
|
|
193
|
+
return regex.test(value);
|
|
194
|
+
};
|
|
195
|
+
var isJWTPayloadWithToken = (payload) => {
|
|
196
|
+
return typeof payload === "object" && payload !== null && "token" in payload && typeof payload?.token === "string";
|
|
197
|
+
};
|
|
195
198
|
|
|
196
199
|
// src/secure.ts
|
|
197
200
|
var generateSecure = (length = 32) => {
|
|
198
|
-
|
|
199
|
-
}
|
|
201
|
+
return import_crypto.default.randomBytes(length).toString("base64url");
|
|
202
|
+
};
|
|
200
203
|
var createHash = (data, base = "hex") => {
|
|
201
|
-
|
|
202
|
-
}
|
|
204
|
+
return import_crypto.default.createHash("sha256").update(data).digest().toString(base);
|
|
205
|
+
};
|
|
203
206
|
var createPKCE = async (verifier) => {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
207
|
+
const codeVerifier = verifier ?? generateSecure(86);
|
|
208
|
+
const codeChallenge = createHash(codeVerifier, "base64url");
|
|
209
|
+
return { codeVerifier, codeChallenge, method: "S256" };
|
|
210
|
+
};
|
|
208
211
|
var createCSRF = async (jose, csrfCookie) => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
return jose.signJWS({ token })
|
|
216
|
-
} catch {
|
|
217
|
-
const token = generateSecure(32)
|
|
218
|
-
return jose.signJWS({ token })
|
|
212
|
+
try {
|
|
213
|
+
const token = generateSecure(32);
|
|
214
|
+
if (csrfCookie) {
|
|
215
|
+
await jose.verifyJWS(csrfCookie);
|
|
216
|
+
return csrfCookie;
|
|
219
217
|
}
|
|
220
|
-
}
|
|
218
|
+
return jose.signJWS({ token });
|
|
219
|
+
} catch {
|
|
220
|
+
const token = generateSecure(32);
|
|
221
|
+
return jose.signJWS({ token });
|
|
222
|
+
}
|
|
223
|
+
};
|
|
221
224
|
var verifyCSRF = async (jose, cookie, header) => {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if (!equals(headerBuffer.length, cookieBuffer.length)) {
|
|
228
|
-
throw new InvalidCsrfTokenError()
|
|
229
|
-
}
|
|
230
|
-
if (!import_node_crypto.default.timingSafeEqual(cookieBuffer, headerBuffer)) {
|
|
231
|
-
throw new InvalidCsrfTokenError()
|
|
232
|
-
}
|
|
233
|
-
return true
|
|
234
|
-
} catch {
|
|
235
|
-
throw new InvalidCsrfTokenError()
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// src/cookie.ts
|
|
240
|
-
var import_cookie = require("cookie")
|
|
241
|
-
|
|
242
|
-
// src/assert.ts
|
|
243
|
-
var isRequest = (value) => {
|
|
244
|
-
return typeof Request !== "undefined" && value instanceof Request
|
|
245
|
-
}
|
|
246
|
-
var isValidURL = (value) => {
|
|
247
|
-
if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false
|
|
248
|
-
const regex =
|
|
249
|
-
/^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/
|
|
250
|
-
return regex.test(value)
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// src/cookie.ts
|
|
254
|
-
var import_cookie2 = require("cookie")
|
|
255
|
-
var COOKIE_NAME = "aura-auth"
|
|
256
|
-
var defaultCookieOptions = {
|
|
257
|
-
httpOnly: true,
|
|
258
|
-
sameSite: "lax",
|
|
259
|
-
path: "/",
|
|
260
|
-
maxAge: 60 * 60 * 24 * 15,
|
|
261
|
-
}
|
|
262
|
-
var defaultStandardCookieConfig = {
|
|
263
|
-
secure: false,
|
|
264
|
-
httpOnly: true,
|
|
265
|
-
prefix: "",
|
|
266
|
-
}
|
|
267
|
-
var defaultSecureCookieConfig = {
|
|
268
|
-
secure: true,
|
|
269
|
-
prefix: "__Secure-",
|
|
270
|
-
}
|
|
271
|
-
var defaultHostCookieConfig = {
|
|
272
|
-
secure: true,
|
|
273
|
-
prefix: "__Host-",
|
|
274
|
-
path: "/",
|
|
275
|
-
domain: void 0,
|
|
276
|
-
}
|
|
277
|
-
var expiredCookieOptions = {
|
|
278
|
-
...defaultCookieOptions,
|
|
279
|
-
expires: /* @__PURE__ */ new Date(0),
|
|
280
|
-
maxAge: 0,
|
|
281
|
-
}
|
|
282
|
-
var defineDefaultCookieOptions = (options2) => {
|
|
283
|
-
return {
|
|
284
|
-
name: options2?.name ?? COOKIE_NAME,
|
|
285
|
-
prefix: options2?.prefix ?? (options2?.secure ? "__Secure-" : ""),
|
|
286
|
-
...defaultCookieOptions,
|
|
287
|
-
...options2,
|
|
225
|
+
try {
|
|
226
|
+
const cookiePayload = await jose.verifyJWS(cookie);
|
|
227
|
+
const headerPayload = await jose.verifyJWS(header);
|
|
228
|
+
if (!isJWTPayloadWithToken(cookiePayload)) {
|
|
229
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Cookie payload missing token field.");
|
|
288
230
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const { prefix, name } = defineDefaultCookieOptions(options2)
|
|
292
|
-
const cookieNameWithPrefix = `${prefix}${name}.${cookieName}`
|
|
293
|
-
return (0, import_cookie.serialize)(cookieNameWithPrefix, value, {
|
|
294
|
-
...defaultCookieOptions,
|
|
295
|
-
...options2,
|
|
296
|
-
})
|
|
297
|
-
}
|
|
298
|
-
var getCookie = (petition, cookie, options2, optional = false) => {
|
|
299
|
-
const cookies = isRequest(petition) ? petition.headers.get("Cookie") : petition.headers.getSetCookie().join("; ")
|
|
300
|
-
if (!cookies) {
|
|
301
|
-
if (optional) {
|
|
302
|
-
return ""
|
|
303
|
-
}
|
|
304
|
-
throw new AuthError("invalid_request", "No cookies found. There is no active session")
|
|
231
|
+
if (!isJWTPayloadWithToken(headerPayload)) {
|
|
232
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Header payload missing token field.");
|
|
305
233
|
}
|
|
306
|
-
const
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
if (optional) {
|
|
311
|
-
return ""
|
|
312
|
-
}
|
|
313
|
-
throw new AuthError("invalid_request", `Cookie "${cookie}" not found. There is no active session`)
|
|
314
|
-
}
|
|
315
|
-
return value
|
|
316
|
-
}
|
|
317
|
-
var createSessionCookie = async (session, cookieOptions, jose) => {
|
|
318
|
-
try {
|
|
319
|
-
const encoded = await jose.encodeJWT(session)
|
|
320
|
-
return setCookie("sessionToken", encoded, cookieOptions)
|
|
321
|
-
} catch (error) {
|
|
322
|
-
throw new AuthError("server_error", "Failed to create session cookie", { cause: error })
|
|
234
|
+
const cookieBuffer = Buffer.from(cookiePayload.token);
|
|
235
|
+
const headerBuffer = Buffer.from(headerPayload.token);
|
|
236
|
+
if (!equals(headerBuffer.length, cookieBuffer.length)) {
|
|
237
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
323
238
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
const name = cookieOptions.name ?? COOKIE_NAME
|
|
327
|
-
const isSecure = trustedProxyHeaders
|
|
328
|
-
? request.url.startsWith("https://") ||
|
|
329
|
-
request.headers.get("X-Forwarded-Proto") === "https" ||
|
|
330
|
-
request.headers.get("Forwarded")?.includes("proto=https")
|
|
331
|
-
: request.url.startsWith("https://")
|
|
332
|
-
if (!cookieOptions.options?.httpOnly) {
|
|
333
|
-
console.warn(
|
|
334
|
-
"[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
|
|
335
|
-
)
|
|
239
|
+
if (!import_crypto.default.timingSafeEqual(cookieBuffer, headerBuffer)) {
|
|
240
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
336
241
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
if (options2?.secure) {
|
|
343
|
-
console.warn(
|
|
344
|
-
"[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
|
|
345
|
-
)
|
|
346
|
-
}
|
|
347
|
-
if (options2?.sameSite == "none") {
|
|
348
|
-
console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.")
|
|
349
|
-
}
|
|
350
|
-
if (process.env.NODE_ENV === "production") {
|
|
351
|
-
console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.")
|
|
352
|
-
}
|
|
353
|
-
return {
|
|
354
|
-
...defaultCookieOptions,
|
|
355
|
-
...cookieOptions.options,
|
|
356
|
-
sameSite: options2?.sameSite === "none" ? "lax" : (options2?.sameSite ?? "lax"),
|
|
357
|
-
...defaultStandardCookieConfig,
|
|
358
|
-
name,
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
return cookieOptions.strategy === "host"
|
|
362
|
-
? {
|
|
363
|
-
...defaultCookieOptions,
|
|
364
|
-
...cookieOptions.options,
|
|
365
|
-
...defaultHostCookieConfig,
|
|
366
|
-
name,
|
|
367
|
-
}
|
|
368
|
-
: { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name }
|
|
369
|
-
}
|
|
370
|
-
var expireCookie = (name, options2) => {
|
|
371
|
-
return setCookie(name, "", { ...options2, ...expiredCookieOptions })
|
|
372
|
-
}
|
|
373
|
-
var oauthCookie = (options2) => {
|
|
374
|
-
return {
|
|
375
|
-
...options2,
|
|
376
|
-
secure: options2.secure,
|
|
377
|
-
httpOnly: options2.httpOnly,
|
|
378
|
-
maxAge: 5 * 60,
|
|
379
|
-
expires: new Date(Date.now() + 5 * 60 * 1e3),
|
|
380
|
-
}
|
|
381
|
-
}
|
|
242
|
+
return true;
|
|
243
|
+
} catch {
|
|
244
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
245
|
+
}
|
|
246
|
+
};
|
|
382
247
|
|
|
383
248
|
// src/schemas.ts
|
|
384
|
-
var
|
|
385
|
-
var OAuthProviderConfigSchema = (0,
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
})
|
|
249
|
+
var import_zod = require("zod");
|
|
250
|
+
var OAuthProviderConfigSchema = (0, import_zod.object)({
|
|
251
|
+
authorizeURL: (0, import_zod.string)().url(),
|
|
252
|
+
accessToken: (0, import_zod.string)().url(),
|
|
253
|
+
scope: (0, import_zod.string)().optional(),
|
|
254
|
+
userInfo: (0, import_zod.string)().url(),
|
|
255
|
+
responseType: (0, import_zod.enum)(["code", "token", "id_token"]),
|
|
256
|
+
clientId: (0, import_zod.string)(),
|
|
257
|
+
clientSecret: (0, import_zod.string)()
|
|
258
|
+
});
|
|
394
259
|
var OAuthAuthorization = OAuthProviderConfigSchema.extend({
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
})
|
|
400
|
-
var OAuthAuthorizationResponse = (0,
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
})
|
|
404
|
-
var OAuthAuthorizationErrorResponse = (0,
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
})
|
|
260
|
+
redirectURI: (0, import_zod.string)(),
|
|
261
|
+
state: (0, import_zod.string)(),
|
|
262
|
+
codeChallenge: (0, import_zod.string)(),
|
|
263
|
+
codeChallengeMethod: (0, import_zod.enum)(["plain", "S256"])
|
|
264
|
+
});
|
|
265
|
+
var OAuthAuthorizationResponse = (0, import_zod.object)({
|
|
266
|
+
state: (0, import_zod.string)({ message: "Missing state parameter in the OAuth authorization response." }),
|
|
267
|
+
code: (0, import_zod.string)({ message: "Missing code parameter in the OAuth authorization response." })
|
|
268
|
+
});
|
|
269
|
+
var OAuthAuthorizationErrorResponse = (0, import_zod.object)({
|
|
270
|
+
error: (0, import_zod.enum)([
|
|
271
|
+
"invalid_request",
|
|
272
|
+
"unauthorized_client",
|
|
273
|
+
"access_denied",
|
|
274
|
+
"unsupported_response_type",
|
|
275
|
+
"invalid_scope",
|
|
276
|
+
"server_error",
|
|
277
|
+
"temporarily_unavailable"
|
|
278
|
+
]),
|
|
279
|
+
error_description: (0, import_zod.string)().optional(),
|
|
280
|
+
error_uri: (0, import_zod.string)().optional(),
|
|
281
|
+
state: (0, import_zod.string)()
|
|
282
|
+
});
|
|
418
283
|
var OAuthAccessToken = OAuthProviderConfigSchema.extend({
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
})
|
|
423
|
-
var OAuthAccessTokenResponse = (0,
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
})
|
|
430
|
-
var OAuthAccessTokenErrorResponse = (0,
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
})
|
|
442
|
-
var OAuthErrorResponse = (0,
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
})
|
|
284
|
+
redirectURI: (0, import_zod.string)(),
|
|
285
|
+
code: (0, import_zod.string)(),
|
|
286
|
+
codeVerifier: (0, import_zod.string)().min(43).max(128)
|
|
287
|
+
});
|
|
288
|
+
var OAuthAccessTokenResponse = (0, import_zod.object)({
|
|
289
|
+
access_token: (0, import_zod.string)(),
|
|
290
|
+
token_type: (0, import_zod.string)().optional(),
|
|
291
|
+
expires_in: (0, import_zod.number)().optional(),
|
|
292
|
+
refresh_token: (0, import_zod.string)().optional(),
|
|
293
|
+
scope: (0, import_zod.string)().optional().or((0, import_zod.null)())
|
|
294
|
+
});
|
|
295
|
+
var OAuthAccessTokenErrorResponse = (0, import_zod.object)({
|
|
296
|
+
error: (0, import_zod.enum)([
|
|
297
|
+
"invalid_request",
|
|
298
|
+
"invalid_client",
|
|
299
|
+
"invalid_grant",
|
|
300
|
+
"unauthorized_client",
|
|
301
|
+
"unsupported_grant_type",
|
|
302
|
+
"invalid_scope"
|
|
303
|
+
]),
|
|
304
|
+
error_description: (0, import_zod.string)().optional(),
|
|
305
|
+
error_uri: (0, import_zod.string)().optional()
|
|
306
|
+
});
|
|
307
|
+
var OAuthErrorResponse = (0, import_zod.object)({
|
|
308
|
+
error: (0, import_zod.string)(),
|
|
309
|
+
error_description: (0, import_zod.string)().optional()
|
|
310
|
+
});
|
|
311
|
+
var OAuthEnvSchema = (0, import_zod.object)({
|
|
312
|
+
clientId: import_zod.z.string().min(1, "OAuth Client ID is required in the environment variables."),
|
|
313
|
+
clientSecret: import_zod.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
|
|
314
|
+
});
|
|
446
315
|
|
|
447
316
|
// src/actions/signIn/authorization.ts
|
|
448
317
|
var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}
|
|
318
|
+
const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod });
|
|
319
|
+
if (!parsed.success) {
|
|
320
|
+
const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
|
|
321
|
+
throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
|
|
322
|
+
}
|
|
323
|
+
const { authorizeURL, ...options2 } = parsed.data;
|
|
324
|
+
const { userInfo, accessToken, clientSecret, ...required } = options2;
|
|
325
|
+
const searchParams = new URLSearchParams(toCastCase(required));
|
|
326
|
+
return `${authorizeURL}?${searchParams}`;
|
|
327
|
+
};
|
|
458
328
|
var getOriginURL = (request, trustedProxyHeaders) => {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
} else {
|
|
469
|
-
return new URL(getNormalizedOriginPath(request.url))
|
|
470
|
-
}
|
|
471
|
-
}
|
|
329
|
+
const headers = request.headers;
|
|
330
|
+
if (trustedProxyHeaders) {
|
|
331
|
+
const protocol = headers.get("X-Forwarded-Proto") ?? headers.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? "http";
|
|
332
|
+
const host = headers.get("X-Forwarded-Host") ?? headers.get("Host") ?? headers.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? null;
|
|
333
|
+
return new URL(`${protocol}://${host}${getNormalizedOriginPath(new URL(request.url).pathname)}`);
|
|
334
|
+
} else {
|
|
335
|
+
return new URL(getNormalizedOriginPath(request.url));
|
|
336
|
+
}
|
|
337
|
+
};
|
|
472
338
|
var createRedirectURI = (request, oauth, basePath, trustedProxyHeaders) => {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
}
|
|
339
|
+
const url = getOriginURL(request, trustedProxyHeaders);
|
|
340
|
+
return `${url.origin}${basePath}/callback/${oauth}`;
|
|
341
|
+
};
|
|
476
342
|
var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
if (isAuthError(error)) {
|
|
512
|
-
throw error
|
|
513
|
-
}
|
|
514
|
-
throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).")
|
|
343
|
+
try {
|
|
344
|
+
const headers = request.headers;
|
|
345
|
+
const origin = headers.get("Origin");
|
|
346
|
+
const referer = headers.get("Referer");
|
|
347
|
+
let hostedURL = getOriginURL(request, trustedProxyHeaders);
|
|
348
|
+
if (redirectTo) {
|
|
349
|
+
if (redirectTo.startsWith("/")) {
|
|
350
|
+
return sanitizeURL(redirectTo);
|
|
351
|
+
}
|
|
352
|
+
const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)));
|
|
353
|
+
if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
|
|
354
|
+
throw new AuthSecurityError(
|
|
355
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
356
|
+
"The redirectTo parameter does not match the hosted origin."
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
return sanitizeURL(redirectToURL.pathname);
|
|
360
|
+
}
|
|
361
|
+
if (referer) {
|
|
362
|
+
const refererURL = new URL(sanitizeURL(referer));
|
|
363
|
+
if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
|
|
364
|
+
throw new AuthSecurityError(
|
|
365
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
366
|
+
"The referer of the request does not match the hosted origin."
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
return sanitizeURL(refererURL.pathname);
|
|
370
|
+
}
|
|
371
|
+
if (origin) {
|
|
372
|
+
const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)));
|
|
373
|
+
if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
|
|
374
|
+
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
375
|
+
}
|
|
376
|
+
return sanitizeURL(originURL.pathname);
|
|
515
377
|
}
|
|
516
|
-
|
|
378
|
+
return "/";
|
|
379
|
+
} catch (error) {
|
|
380
|
+
if (isAuthSecurityError(error)) {
|
|
381
|
+
throw error;
|
|
382
|
+
}
|
|
383
|
+
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
384
|
+
}
|
|
385
|
+
};
|
|
517
386
|
|
|
518
387
|
// src/actions/signIn/signIn.ts
|
|
519
388
|
var signInConfig = (oauth) => {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
389
|
+
return (0, import_router2.createEndpointConfig)("/signIn/:oauth", {
|
|
390
|
+
schemas: {
|
|
391
|
+
params: import_zod2.z.object({
|
|
392
|
+
oauth: import_zod2.z.enum(
|
|
393
|
+
Object.keys(oauth),
|
|
394
|
+
"The OAuth provider is not supported or invalid."
|
|
395
|
+
)
|
|
396
|
+
}),
|
|
397
|
+
searchParams: import_zod2.z.object({
|
|
398
|
+
redirectTo: import_zod2.z.string().optional()
|
|
399
|
+
})
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
};
|
|
529
403
|
var signInAction = (oauth) => {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
headers.append("Set-Cookie", redirectToCookie)
|
|
558
|
-
headers.append("Set-Cookie", codeVerifierCookie)
|
|
559
|
-
return Response.json(
|
|
560
|
-
{ oauth: oauth2 },
|
|
561
|
-
{
|
|
562
|
-
status: 302,
|
|
563
|
-
headers,
|
|
564
|
-
}
|
|
565
|
-
)
|
|
566
|
-
} catch (error) {
|
|
567
|
-
if (isAuthError(error)) {
|
|
568
|
-
const { type, message } = error
|
|
569
|
-
return AuraResponse.json(
|
|
570
|
-
{ error: type, error_description: message },
|
|
571
|
-
{ status: import_router2.statusCode.BAD_REQUEST }
|
|
572
|
-
)
|
|
573
|
-
}
|
|
574
|
-
return AuraResponse.json(
|
|
575
|
-
{
|
|
576
|
-
error: ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR,
|
|
577
|
-
error_description: "An unexpected error occurred",
|
|
578
|
-
},
|
|
579
|
-
{ status: import_router2.statusCode.INTERNAL_SERVER_ERROR }
|
|
580
|
-
)
|
|
581
|
-
}
|
|
582
|
-
},
|
|
583
|
-
signInConfig(oauth)
|
|
584
|
-
)
|
|
585
|
-
}
|
|
404
|
+
return (0, import_router2.createEndpoint)(
|
|
405
|
+
"GET",
|
|
406
|
+
"/signIn/:oauth",
|
|
407
|
+
async (ctx) => {
|
|
408
|
+
const {
|
|
409
|
+
request,
|
|
410
|
+
params: { oauth: oauth2 },
|
|
411
|
+
searchParams: { redirectTo },
|
|
412
|
+
context: { oauth: providers, cookies, trustedProxyHeaders, basePath }
|
|
413
|
+
} = ctx;
|
|
414
|
+
const state = generateSecure();
|
|
415
|
+
const redirectURI = createRedirectURI(request, oauth2, basePath, trustedProxyHeaders);
|
|
416
|
+
const redirectToValue = createRedirectTo(request, redirectTo, trustedProxyHeaders);
|
|
417
|
+
const { codeVerifier, codeChallenge, method } = await createPKCE();
|
|
418
|
+
const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method);
|
|
419
|
+
const headers = new import_router2.HeadersBuilder(cacheControl).setHeader("Location", authorization).setCookie(cookies.state.name, state, cookies.state.attributes).setCookie(cookies.redirectURI.name, redirectURI, cookies.redirectURI.attributes).setCookie(cookies.redirectTo.name, redirectToValue, cookies.redirectTo.attributes).setCookie(cookies.codeVerifier.name, codeVerifier, cookies.codeVerifier.attributes).toHeaders();
|
|
420
|
+
return Response.json(
|
|
421
|
+
{ oauth: oauth2 },
|
|
422
|
+
{
|
|
423
|
+
status: 302,
|
|
424
|
+
headers
|
|
425
|
+
}
|
|
426
|
+
);
|
|
427
|
+
},
|
|
428
|
+
signInConfig(oauth)
|
|
429
|
+
);
|
|
430
|
+
};
|
|
586
431
|
|
|
587
432
|
// src/actions/callback/callback.ts
|
|
588
|
-
var
|
|
589
|
-
var import_router3 = require("@aura-stack/router")
|
|
433
|
+
var import_zod3 = require("zod");
|
|
434
|
+
var import_router3 = require("@aura-stack/router");
|
|
590
435
|
|
|
591
|
-
// src/
|
|
592
|
-
var
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
436
|
+
// src/request.ts
|
|
437
|
+
var fetchAsync = async (url, options2 = {}, timeout = 5e3) => {
|
|
438
|
+
const controller = new AbortController();
|
|
439
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
440
|
+
const response = await fetch(url, {
|
|
441
|
+
...options2,
|
|
442
|
+
signal: controller.signal
|
|
443
|
+
}).finally(() => clearTimeout(timeoutId));
|
|
444
|
+
return response;
|
|
445
|
+
};
|
|
598
446
|
|
|
599
447
|
// src/actions/callback/userinfo.ts
|
|
600
448
|
var getDefaultUserInfo = (profile) => {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
}
|
|
449
|
+
const sub = generateSecure(16);
|
|
450
|
+
return {
|
|
451
|
+
sub: profile?.id ?? profile?.sub ?? sub,
|
|
452
|
+
email: profile?.email,
|
|
453
|
+
name: profile?.name ?? profile?.username ?? profile?.nickname,
|
|
454
|
+
image: profile?.image ?? profile?.picture
|
|
455
|
+
};
|
|
456
|
+
};
|
|
609
457
|
var getUserInfo = async (oauthConfig, accessToken) => {
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
458
|
+
const userinfoEndpoint = oauthConfig.userInfo;
|
|
459
|
+
try {
|
|
460
|
+
const response = await fetchAsync(userinfoEndpoint, {
|
|
461
|
+
method: "GET",
|
|
462
|
+
headers: {
|
|
463
|
+
Accept: "application/json",
|
|
464
|
+
Authorization: `Bearer ${accessToken}`
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
const json = await response.json();
|
|
468
|
+
const { success, data } = OAuthErrorResponse.safeParse(json);
|
|
469
|
+
if (success) {
|
|
470
|
+
throw new OAuthProtocolError(
|
|
471
|
+
data.error,
|
|
472
|
+
data?.error_description ?? "An error occurred while fetching user information."
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
return oauthConfig?.profile ? oauthConfig.profile(json) : getDefaultUserInfo(json);
|
|
476
|
+
} catch (error) {
|
|
477
|
+
if (isOAuthProtocolError(error)) {
|
|
478
|
+
throw error;
|
|
627
479
|
}
|
|
628
|
-
|
|
480
|
+
if (isNativeError(error)) {
|
|
481
|
+
throw new OAuthProtocolError("invalid_request", error.message, "", { cause: error });
|
|
482
|
+
}
|
|
483
|
+
throw new OAuthProtocolError("invalid_request", "Failed to fetch user information.", "", { cause: error });
|
|
484
|
+
}
|
|
485
|
+
};
|
|
629
486
|
|
|
630
487
|
// src/actions/callback/access-token.ts
|
|
631
488
|
var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) => {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
return token.data
|
|
663
|
-
} catch (error) {
|
|
664
|
-
throw throwAuthError(error, "Failed to create access token")
|
|
489
|
+
const parsed = OAuthAccessToken.safeParse({ ...oauthConfig, redirectURI, code, codeVerifier });
|
|
490
|
+
if (!parsed.success) {
|
|
491
|
+
const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
|
|
492
|
+
throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
|
|
493
|
+
}
|
|
494
|
+
const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data;
|
|
495
|
+
try {
|
|
496
|
+
const response = await fetchAsync(accessToken, {
|
|
497
|
+
method: "POST",
|
|
498
|
+
headers: {
|
|
499
|
+
Accept: "application/json",
|
|
500
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
501
|
+
},
|
|
502
|
+
body: new URLSearchParams({
|
|
503
|
+
client_id: clientId,
|
|
504
|
+
client_secret: clientSecret,
|
|
505
|
+
code: codeParsed,
|
|
506
|
+
redirect_uri: redirectParsed,
|
|
507
|
+
grant_type: "authorization_code",
|
|
508
|
+
code_verifier: codeVerifier
|
|
509
|
+
}).toString()
|
|
510
|
+
});
|
|
511
|
+
const json = await response.json();
|
|
512
|
+
const token = OAuthAccessTokenResponse.safeParse(json);
|
|
513
|
+
if (!token.success) {
|
|
514
|
+
const { success, data } = OAuthAccessTokenErrorResponse.safeParse(json);
|
|
515
|
+
if (!success) {
|
|
516
|
+
throw new OAuthProtocolError("INVALID_REQUEST", "Invalid access token response format");
|
|
517
|
+
}
|
|
518
|
+
throw new OAuthProtocolError(data.error, data?.error_description ?? "Failed to retrieve access token");
|
|
665
519
|
}
|
|
666
|
-
|
|
520
|
+
return token.data;
|
|
521
|
+
} catch (error) {
|
|
522
|
+
throw error;
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
// src/cookie.ts
|
|
527
|
+
var import_cookie = require("@aura-stack/router/cookie");
|
|
528
|
+
var defaultCookieOptions = {
|
|
529
|
+
httpOnly: true,
|
|
530
|
+
sameSite: "lax",
|
|
531
|
+
path: "/",
|
|
532
|
+
maxAge: 60 * 60 * 24 * 15
|
|
533
|
+
};
|
|
534
|
+
var oauthCookieOptions = {
|
|
535
|
+
httpOnly: true,
|
|
536
|
+
maxAge: 5 * 60,
|
|
537
|
+
sameSite: "lax",
|
|
538
|
+
expires: new Date(Date.now() + 5 * 60 * 1e3)
|
|
539
|
+
};
|
|
540
|
+
var setCookie = (cookieName, value, options2) => {
|
|
541
|
+
return (0, import_cookie.serialize)(cookieName, value, options2);
|
|
542
|
+
};
|
|
543
|
+
var expiredCookieAttributes = {
|
|
544
|
+
...defaultCookieOptions,
|
|
545
|
+
expires: /* @__PURE__ */ new Date(0),
|
|
546
|
+
maxAge: 0
|
|
547
|
+
};
|
|
548
|
+
var getCookie = (request, cookieName) => {
|
|
549
|
+
const cookies = request.headers.get("Cookie");
|
|
550
|
+
if (!cookies) {
|
|
551
|
+
throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
|
|
552
|
+
}
|
|
553
|
+
const value = (0, import_cookie.parse)(cookies)[cookieName];
|
|
554
|
+
if (!value) {
|
|
555
|
+
throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found. There is no active session`);
|
|
556
|
+
}
|
|
557
|
+
return value;
|
|
558
|
+
};
|
|
559
|
+
var createSessionCookie = async (jose, session) => {
|
|
560
|
+
try {
|
|
561
|
+
const encoded = await jose.encodeJWT(session);
|
|
562
|
+
return encoded;
|
|
563
|
+
} catch (error) {
|
|
564
|
+
throw new AuthInternalError("INVALID_JWT_TOKEN", "Failed to create session cookie", { cause: error });
|
|
565
|
+
}
|
|
566
|
+
};
|
|
667
567
|
|
|
668
568
|
// src/actions/callback/callback.ts
|
|
669
569
|
var callbackConfig = (oauth) => {
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
570
|
+
return (0, import_router3.createEndpointConfig)("/callback/:oauth", {
|
|
571
|
+
schemas: {
|
|
572
|
+
params: import_zod3.z.object({
|
|
573
|
+
oauth: import_zod3.z.enum(
|
|
574
|
+
Object.keys(oauth),
|
|
575
|
+
"The OAuth provider is not supported or invalid."
|
|
576
|
+
)
|
|
577
|
+
}),
|
|
578
|
+
searchParams: import_zod3.z.object({
|
|
579
|
+
code: import_zod3.z.string("Missing code parameter in the OAuth authorization response."),
|
|
580
|
+
state: import_zod3.z.string("Missing state parameter in the OAuth authorization response.")
|
|
581
|
+
})
|
|
582
|
+
},
|
|
583
|
+
middlewares: [
|
|
584
|
+
(ctx) => {
|
|
585
|
+
const response = OAuthAuthorizationErrorResponse.safeParse(ctx.searchParams);
|
|
586
|
+
if (response.success) {
|
|
587
|
+
const { error, error_description } = response.data;
|
|
588
|
+
throw new OAuthProtocolError(error, error_description ?? "OAuth Authorization Error");
|
|
589
|
+
}
|
|
590
|
+
return ctx;
|
|
591
|
+
}
|
|
592
|
+
]
|
|
593
|
+
});
|
|
594
|
+
};
|
|
689
595
|
var callbackAction = (oauth) => {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
{
|
|
729
|
-
...cookies,
|
|
730
|
-
strategy: "host",
|
|
731
|
-
},
|
|
732
|
-
trustedProxyHeaders
|
|
733
|
-
)
|
|
734
|
-
)
|
|
735
|
-
headers.set("Set-Cookie", sessionCookie)
|
|
736
|
-
headers.append("Set-Cookie", expireCookie("state", cookieOptions))
|
|
737
|
-
headers.append("Set-Cookie", expireCookie("redirect_uri", cookieOptions))
|
|
738
|
-
headers.append("Set-Cookie", expireCookie("redirect_to", cookieOptions))
|
|
739
|
-
headers.append("Set-Cookie", expireCookie("code_verifier", cookieOptions))
|
|
740
|
-
headers.append("Set-Cookie", csrfCookie)
|
|
741
|
-
return Response.json({ oauth: oauth2 }, { status: 302, headers })
|
|
742
|
-
} catch (error) {
|
|
743
|
-
if (isAuthError(error)) {
|
|
744
|
-
const { type, message } = error
|
|
745
|
-
return AuraResponse.json(
|
|
746
|
-
{ error: type, error_description: message },
|
|
747
|
-
{ status: import_router3.statusCode.BAD_REQUEST }
|
|
748
|
-
)
|
|
749
|
-
}
|
|
750
|
-
return AuraResponse.json(
|
|
751
|
-
{
|
|
752
|
-
error: ERROR_RESPONSE.ACCESS_TOKEN.INVALID_CLIENT,
|
|
753
|
-
error_description: "An unexpected error occurred",
|
|
754
|
-
},
|
|
755
|
-
{ status: import_router3.statusCode.INTERNAL_SERVER_ERROR }
|
|
756
|
-
)
|
|
757
|
-
}
|
|
758
|
-
},
|
|
759
|
-
callbackConfig(oauth)
|
|
760
|
-
)
|
|
761
|
-
}
|
|
596
|
+
return (0, import_router3.createEndpoint)(
|
|
597
|
+
"GET",
|
|
598
|
+
"/callback/:oauth",
|
|
599
|
+
async (ctx) => {
|
|
600
|
+
const {
|
|
601
|
+
request,
|
|
602
|
+
params: { oauth: oauth2 },
|
|
603
|
+
searchParams: { code, state },
|
|
604
|
+
context: { oauth: providers, cookies, jose }
|
|
605
|
+
} = ctx;
|
|
606
|
+
const oauthConfig = providers[oauth2];
|
|
607
|
+
const cookieState = getCookie(request, cookies.state.name);
|
|
608
|
+
const cookieRedirectTo = getCookie(request, cookies.redirectTo.name);
|
|
609
|
+
const cookieRedirectURI = getCookie(request, cookies.redirectURI.name);
|
|
610
|
+
const codeVerifier = getCookie(request, cookies.codeVerifier.name);
|
|
611
|
+
if (!equals(cookieState, state)) {
|
|
612
|
+
throw new AuthSecurityError(
|
|
613
|
+
"MISMATCHING_STATE",
|
|
614
|
+
"The provided state passed in the OAuth response does not match the stored state."
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
const accessToken = await createAccessToken(oauthConfig, cookieRedirectURI, code, codeVerifier);
|
|
618
|
+
const sanitized = sanitizeURL(cookieRedirectTo);
|
|
619
|
+
if (!isValidRelativePath(sanitized)) {
|
|
620
|
+
throw new AuthSecurityError(
|
|
621
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
622
|
+
"Invalid redirect path. Potential open redirect attack detected."
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
const userInfo = await getUserInfo(oauthConfig, accessToken.access_token);
|
|
626
|
+
const sessionCookie = await createSessionCookie(jose, userInfo);
|
|
627
|
+
const csrfToken = await createCSRF(jose);
|
|
628
|
+
const headers = new import_router3.HeadersBuilder(cacheControl).setHeader("Location", sanitized).setCookie(cookies.sessionToken.name, sessionCookie, cookies.sessionToken.attributes).setCookie(cookies.csrfToken.name, csrfToken, cookies.csrfToken.attributes).setCookie(cookies.state.name, "", expiredCookieAttributes).setCookie(cookies.redirectURI.name, "", expiredCookieAttributes).setCookie(cookies.redirectTo.name, "", expiredCookieAttributes).setCookie(cookies.codeVerifier.name, "", expiredCookieAttributes).toHeaders();
|
|
629
|
+
return Response.json({ oauth: oauth2 }, { status: 302, headers });
|
|
630
|
+
},
|
|
631
|
+
callbackConfig(oauth)
|
|
632
|
+
);
|
|
633
|
+
};
|
|
762
634
|
|
|
763
635
|
// src/actions/session/session.ts
|
|
764
|
-
var import_router4 = require("@aura-stack/router")
|
|
636
|
+
var import_router4 = require("@aura-stack/router");
|
|
765
637
|
var sessionAction = (0, import_router4.createEndpoint)("GET", "/session", async (ctx) => {
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
return Response.json({ authenticated: false, message: "Unauthorized" }, { status: 401, headers })
|
|
782
|
-
}
|
|
783
|
-
})
|
|
638
|
+
const {
|
|
639
|
+
request,
|
|
640
|
+
context: { jose, cookies }
|
|
641
|
+
} = ctx;
|
|
642
|
+
try {
|
|
643
|
+
const session = getCookie(request, cookies.sessionToken.name);
|
|
644
|
+
const decoded = await jose.decodeJWT(session);
|
|
645
|
+
const { exp, iat, jti, nbf, ...user } = decoded;
|
|
646
|
+
const headers = new Headers(cacheControl);
|
|
647
|
+
return Response.json({ user, expires: toISOString(exp * 1e3) }, { headers });
|
|
648
|
+
} catch (error) {
|
|
649
|
+
const headers = new import_router4.HeadersBuilder(cacheControl).setCookie(cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
|
|
650
|
+
return Response.json({ authenticated: false, message: "Unauthorized" }, { status: 401, headers });
|
|
651
|
+
}
|
|
652
|
+
});
|
|
784
653
|
|
|
785
654
|
// src/actions/signOut/signOut.ts
|
|
786
|
-
var
|
|
787
|
-
var import_router5 = require("@aura-stack/router")
|
|
655
|
+
var import_zod4 = require("zod");
|
|
656
|
+
var import_router5 = require("@aura-stack/router");
|
|
788
657
|
var config = (0, import_router5.createEndpointConfig)({
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
})
|
|
658
|
+
schemas: {
|
|
659
|
+
searchParams: import_zod4.z.object({
|
|
660
|
+
token_type_hint: import_zod4.z.literal("session_token"),
|
|
661
|
+
redirectTo: import_zod4.z.string().optional()
|
|
662
|
+
})
|
|
663
|
+
}
|
|
664
|
+
});
|
|
796
665
|
var signOutAction = (0, import_router5.createEndpoint)(
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
responseHeaders.append("Location", location)
|
|
833
|
-
return Response.json(
|
|
834
|
-
{ message: "Signed out successfully" },
|
|
835
|
-
{ status: import_router5.statusCode.ACCEPTED, headers: responseHeaders }
|
|
836
|
-
)
|
|
837
|
-
} catch (error) {
|
|
838
|
-
if (error instanceof InvalidCsrfTokenError) {
|
|
839
|
-
return AuraResponse.json(
|
|
840
|
-
{
|
|
841
|
-
error: "invalid_csrf_token",
|
|
842
|
-
error_description: "The provided CSRF token is invalid or has expired",
|
|
843
|
-
},
|
|
844
|
-
{ status: import_router5.statusCode.UNAUTHORIZED }
|
|
845
|
-
)
|
|
846
|
-
}
|
|
847
|
-
if (error instanceof InvalidRedirectToError) {
|
|
848
|
-
const { type, message } = error
|
|
849
|
-
return AuraResponse.json(
|
|
850
|
-
{
|
|
851
|
-
error: type,
|
|
852
|
-
error_description: message,
|
|
853
|
-
},
|
|
854
|
-
{ status: import_router5.statusCode.BAD_REQUEST }
|
|
855
|
-
)
|
|
856
|
-
}
|
|
857
|
-
return AuraResponse.json(
|
|
858
|
-
{
|
|
859
|
-
error: "invalid_session_token",
|
|
860
|
-
error_description: "The provided sessionToken is invalid or has already expired",
|
|
861
|
-
},
|
|
862
|
-
{ status: import_router5.statusCode.UNAUTHORIZED }
|
|
863
|
-
)
|
|
864
|
-
}
|
|
865
|
-
},
|
|
866
|
-
config
|
|
867
|
-
)
|
|
666
|
+
"POST",
|
|
667
|
+
"/signOut",
|
|
668
|
+
async (ctx) => {
|
|
669
|
+
const {
|
|
670
|
+
request,
|
|
671
|
+
headers,
|
|
672
|
+
searchParams: { redirectTo },
|
|
673
|
+
context: { jose, cookies }
|
|
674
|
+
} = ctx;
|
|
675
|
+
const session = headers.getCookie(cookies.sessionToken.name);
|
|
676
|
+
const csrfToken = headers.getCookie(cookies.csrfToken.name);
|
|
677
|
+
const header = headers.getHeader("X-CSRF-Token");
|
|
678
|
+
if (!session) {
|
|
679
|
+
throw new AuthSecurityError("SESSION_TOKEN_MISSING", "The sessionToken is missing.");
|
|
680
|
+
}
|
|
681
|
+
if (!csrfToken) {
|
|
682
|
+
throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF token is missing.");
|
|
683
|
+
}
|
|
684
|
+
if (!header) {
|
|
685
|
+
throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF header is missing.");
|
|
686
|
+
}
|
|
687
|
+
await verifyCSRF(jose, csrfToken, header);
|
|
688
|
+
await jose.decodeJWT(session);
|
|
689
|
+
const normalizedOriginPath = getNormalizedOriginPath(request.url);
|
|
690
|
+
const location = createRedirectTo(
|
|
691
|
+
new Request(normalizedOriginPath, {
|
|
692
|
+
headers: headers.toHeaders()
|
|
693
|
+
}),
|
|
694
|
+
redirectTo
|
|
695
|
+
);
|
|
696
|
+
const headersList = new import_router5.HeadersBuilder(cacheControl).setHeader("Location", location).setCookie(cookies.csrfToken.name, "", expiredCookieAttributes).setCookie(cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
|
|
697
|
+
return Response.json({ message: "Signed out successfully" }, { status: import_router5.statusCode.ACCEPTED, headers: headersList });
|
|
698
|
+
},
|
|
699
|
+
config
|
|
700
|
+
);
|
|
868
701
|
|
|
869
702
|
// src/actions/csrfToken/csrfToken.ts
|
|
870
|
-
var import_router6 = require("@aura-stack/router")
|
|
703
|
+
var import_router6 = require("@aura-stack/router");
|
|
704
|
+
var getCSRFToken = (request, cookieName) => {
|
|
705
|
+
try {
|
|
706
|
+
return getCookie(request, cookieName);
|
|
707
|
+
} catch {
|
|
708
|
+
return void 0;
|
|
709
|
+
}
|
|
710
|
+
};
|
|
871
711
|
var csrfTokenAction = (0, import_router6.createEndpoint)("GET", "/csrfToken", async (ctx) => {
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
})
|
|
712
|
+
const {
|
|
713
|
+
request,
|
|
714
|
+
context: { jose, cookies }
|
|
715
|
+
} = ctx;
|
|
716
|
+
const token = getCSRFToken(request, cookies.csrfToken.name);
|
|
717
|
+
const csrfToken = await createCSRF(jose, token);
|
|
718
|
+
const headers = new Headers(cacheControl);
|
|
719
|
+
headers.append("Set-Cookie", setCookie(cookies.csrfToken.name, csrfToken, cookies.csrfToken.attributes));
|
|
720
|
+
return Response.json({ csrfToken }, { headers });
|
|
721
|
+
});
|
|
883
722
|
// Annotate the CommonJS export names for ESM import in node:
|
|
884
|
-
0 &&
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
})
|
|
723
|
+
0 && (module.exports = {
|
|
724
|
+
callbackAction,
|
|
725
|
+
csrfTokenAction,
|
|
726
|
+
sessionAction,
|
|
727
|
+
signInAction,
|
|
728
|
+
signOutAction
|
|
729
|
+
});
|