@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/index.cjs
CHANGED
|
@@ -1,1125 +1,1130 @@
|
|
|
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/index.ts
|
|
33
|
-
var index_exports = {}
|
|
31
|
+
var index_exports = {};
|
|
34
32
|
__export(index_exports, {
|
|
35
|
-
|
|
36
|
-
})
|
|
37
|
-
module.exports = __toCommonJS(index_exports)
|
|
38
|
-
var import_config2 = require("dotenv/config")
|
|
39
|
-
var import_router7 = require("@aura-stack/router")
|
|
33
|
+
createAuth: () => createAuth
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
var import_config2 = require("dotenv/config");
|
|
37
|
+
var import_router7 = require("@aura-stack/router");
|
|
40
38
|
|
|
41
39
|
// src/utils.ts
|
|
42
|
-
var import_router = require("@aura-stack/router")
|
|
40
|
+
var import_router = require("@aura-stack/router");
|
|
43
41
|
|
|
44
|
-
// src/
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
var
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
UNAUTHORIZED_CLIENT: "unauthorized_client",
|
|
90
|
-
UNSUPPORTED_GRANT_TYPE: "unsupported_grant_type",
|
|
91
|
-
INVALID_SCOPE: "invalid_scope",
|
|
92
|
-
},
|
|
93
|
-
}
|
|
42
|
+
// src/errors.ts
|
|
43
|
+
var OAuthProtocolError = class extends Error {
|
|
44
|
+
type = "OAUTH_PROTOCOL_ERROR";
|
|
45
|
+
error;
|
|
46
|
+
errorURI;
|
|
47
|
+
constructor(error, description, errorURI, options2) {
|
|
48
|
+
super(description, options2);
|
|
49
|
+
this.error = error;
|
|
50
|
+
this.errorURI = errorURI;
|
|
51
|
+
this.name = new.target.name;
|
|
52
|
+
Error.captureStackTrace(this, new.target);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var AuthInternalError = class extends Error {
|
|
56
|
+
type = "AUTH_INTERNAL_ERROR";
|
|
57
|
+
code;
|
|
58
|
+
constructor(code, message, options2) {
|
|
59
|
+
super(message, options2);
|
|
60
|
+
this.code = code;
|
|
61
|
+
this.name = new.target.name;
|
|
62
|
+
Error.captureStackTrace(this, new.target);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var AuthSecurityError = class extends Error {
|
|
66
|
+
type = "AUTH_SECURITY_ERROR";
|
|
67
|
+
code;
|
|
68
|
+
constructor(code, message, options2) {
|
|
69
|
+
super(message, options2);
|
|
70
|
+
this.code = code;
|
|
71
|
+
this.name = new.target.name;
|
|
72
|
+
Error.captureStackTrace(this, new.target);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var isNativeError = (error) => {
|
|
76
|
+
return error instanceof Error;
|
|
77
|
+
};
|
|
78
|
+
var isOAuthProtocolError = (error) => {
|
|
79
|
+
return error instanceof OAuthProtocolError;
|
|
80
|
+
};
|
|
81
|
+
var isAuthInternalError = (error) => {
|
|
82
|
+
return error instanceof AuthInternalError;
|
|
83
|
+
};
|
|
84
|
+
var isAuthSecurityError = (error) => {
|
|
85
|
+
return error instanceof AuthSecurityError;
|
|
86
|
+
};
|
|
94
87
|
|
|
95
88
|
// src/utils.ts
|
|
96
89
|
var toSnakeCase = (str) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
|
|
100
|
-
.toLowerCase()
|
|
101
|
-
.replace(/^_+/, "")
|
|
102
|
-
}
|
|
90
|
+
return str.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().replace(/^_+/, "");
|
|
91
|
+
};
|
|
103
92
|
var toUpperCase = (str) => {
|
|
104
|
-
|
|
105
|
-
}
|
|
93
|
+
return str.toUpperCase();
|
|
94
|
+
};
|
|
106
95
|
var toCastCase = (obj, type = "snake") => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
96
|
+
return Object.entries(obj).reduce((previous, [key, value]) => {
|
|
97
|
+
const newKey = type === "snake" ? toSnakeCase(key) : toUpperCase(key);
|
|
98
|
+
return { ...previous, [newKey]: value };
|
|
99
|
+
}, {});
|
|
100
|
+
};
|
|
112
101
|
var equals = (a, b) => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
var sanitizeURL = (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
path = path.replace(/\/+$/, "/")
|
|
138
|
-
} else if (path !== "/") {
|
|
139
|
-
path = path.replace(/\/+$/, "")
|
|
140
|
-
}
|
|
141
|
-
return protocol + domain + path
|
|
142
|
-
}
|
|
143
|
-
let sanitized = decodedURL
|
|
144
|
-
.replace(/\/\.\.\//g, "/")
|
|
145
|
-
.replace(/\/\.\.$/, "")
|
|
146
|
-
.replace(/\.{2,}/g, "")
|
|
147
|
-
.replace(/\/{2,}/g, "/")
|
|
148
|
-
if (sanitized !== "/" && sanitized.endsWith("/")) {
|
|
149
|
-
sanitized = sanitized.replace(/\/+$/, "/")
|
|
150
|
-
} else if (sanitized !== "/") {
|
|
151
|
-
sanitized = sanitized.replace(/\/+$/, "")
|
|
152
|
-
}
|
|
153
|
-
return sanitized
|
|
154
|
-
} catch {
|
|
155
|
-
return url2.trim()
|
|
102
|
+
if (a === null || b === null || a === void 0 || b === void 0) return false;
|
|
103
|
+
return a === b;
|
|
104
|
+
};
|
|
105
|
+
var sanitizeURL = (url) => {
|
|
106
|
+
try {
|
|
107
|
+
let decodedURL = decodeURIComponent(url).trim();
|
|
108
|
+
const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/);
|
|
109
|
+
let protocol = "";
|
|
110
|
+
let rest = decodedURL;
|
|
111
|
+
if (protocolMatch) {
|
|
112
|
+
protocol = protocolMatch[1];
|
|
113
|
+
rest = decodedURL.slice(protocol.length);
|
|
114
|
+
const slashIndex = rest.indexOf("/");
|
|
115
|
+
if (slashIndex === -1) {
|
|
116
|
+
return protocol + rest;
|
|
117
|
+
}
|
|
118
|
+
const domain = rest.slice(0, slashIndex);
|
|
119
|
+
let path = rest.slice(slashIndex).replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
|
|
120
|
+
if (path !== "/" && path.endsWith("/")) {
|
|
121
|
+
path = path.replace(/\/+$/, "/");
|
|
122
|
+
} else if (path !== "/") {
|
|
123
|
+
path = path.replace(/\/+$/, "");
|
|
124
|
+
}
|
|
125
|
+
return protocol + domain + path;
|
|
156
126
|
}
|
|
157
|
-
}
|
|
127
|
+
let sanitized = decodedURL.replace(/\/\.\.\//g, "/").replace(/\/\.\.$/, "").replace(/\.{2,}/g, "").replace(/\/{2,}/g, "/");
|
|
128
|
+
if (sanitized !== "/" && sanitized.endsWith("/")) {
|
|
129
|
+
sanitized = sanitized.replace(/\/+$/, "/");
|
|
130
|
+
} else if (sanitized !== "/") {
|
|
131
|
+
sanitized = sanitized.replace(/\/+$/, "");
|
|
132
|
+
}
|
|
133
|
+
return sanitized;
|
|
134
|
+
} catch {
|
|
135
|
+
return url.trim();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
158
138
|
var isValidRelativePath = (path) => {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
139
|
+
if (!path || typeof path !== "string") return false;
|
|
140
|
+
if (!path.startsWith("/") || path.includes("://") || path.includes("\r") || path.includes("\n")) return false;
|
|
141
|
+
if (/[\x00-\x1F\x7F]/.test(path) || path.includes("\0")) return false;
|
|
142
|
+
const sanitized = sanitizeURL(path);
|
|
143
|
+
if (sanitized.includes("..")) return false;
|
|
144
|
+
return true;
|
|
145
|
+
};
|
|
166
146
|
var onErrorHandler = (error) => {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
147
|
+
if ((0, import_router.isRouterError)(error)) {
|
|
148
|
+
const { message, status, statusText } = error;
|
|
149
|
+
return Response.json({ type: "ROUTER_ERROR", code: "ROUTER_INTERNAL_ERROR", message }, { status, statusText });
|
|
150
|
+
}
|
|
151
|
+
if ((0, import_router.isInvalidZodSchemaError)(error)) {
|
|
152
|
+
return Response.json({ type: "ROUTER_ERROR", code: "INVALID_REQUEST", message: error.errors }, { status: 422 });
|
|
153
|
+
}
|
|
154
|
+
if (isOAuthProtocolError(error)) {
|
|
155
|
+
const { error: errorCode, message, type, errorURI } = error;
|
|
156
|
+
return Response.json(
|
|
157
|
+
{
|
|
158
|
+
type,
|
|
159
|
+
error: errorCode,
|
|
160
|
+
error_description: message,
|
|
161
|
+
error_uri: errorURI
|
|
162
|
+
},
|
|
163
|
+
{ status: 400 }
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
if (isAuthInternalError(error) || isAuthSecurityError(error)) {
|
|
167
|
+
const { type, code, message } = error;
|
|
168
|
+
return Response.json(
|
|
169
|
+
{
|
|
170
|
+
type,
|
|
171
|
+
code,
|
|
172
|
+
message
|
|
173
|
+
},
|
|
174
|
+
{ status: 400 }
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
return Response.json({ type: "SERVER_ERROR", code: "server_error", message: "An unexpected error occurred" }, { status: 500 });
|
|
178
|
+
};
|
|
177
179
|
var getNormalizedOriginPath = (path) => {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
180
|
+
try {
|
|
181
|
+
const url = new URL(path);
|
|
182
|
+
url.hash = "";
|
|
183
|
+
url.search = "";
|
|
184
|
+
return `${url.origin}${url.pathname}`;
|
|
185
|
+
} catch {
|
|
186
|
+
return sanitizeURL(path);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
187
189
|
var toISOString = (date) => {
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
+
return new Date(date).toISOString();
|
|
191
|
+
};
|
|
192
|
+
var useSecureCookies = (request, trustedProxyHeaders) => {
|
|
193
|
+
return trustedProxyHeaders ? request.url.startsWith("https://") || request.headers.get("X-Forwarded-Proto") === "https" || (request.headers.get("Forwarded")?.includes("proto=https") ?? false) : request.url.startsWith("https://");
|
|
194
|
+
};
|
|
195
|
+
var formatZodError = (error) => {
|
|
196
|
+
if (!error.issues || error.issues.length === 0) {
|
|
197
|
+
return {};
|
|
198
|
+
}
|
|
199
|
+
return error.issues.reduce((previous, issue) => {
|
|
200
|
+
const key = issue.path.join(".");
|
|
201
|
+
return {
|
|
202
|
+
...previous,
|
|
203
|
+
[key]: {
|
|
204
|
+
code: issue.code,
|
|
205
|
+
message: issue.message
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}, {});
|
|
209
|
+
};
|
|
190
210
|
|
|
191
211
|
// src/jose.ts
|
|
192
|
-
var import_config = require("dotenv/config")
|
|
193
|
-
var import_jose = require("@aura-stack/jose")
|
|
212
|
+
var import_config = require("dotenv/config");
|
|
213
|
+
var import_jose = require("@aura-stack/jose");
|
|
214
|
+
|
|
215
|
+
// src/secure.ts
|
|
216
|
+
var import_node_crypto = __toESM(require("crypto"), 1);
|
|
217
|
+
|
|
218
|
+
// src/assert.ts
|
|
219
|
+
var isValidURL = (value) => {
|
|
220
|
+
if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false;
|
|
221
|
+
const regex = /^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/;
|
|
222
|
+
return regex.test(value);
|
|
223
|
+
};
|
|
224
|
+
var isJWTPayloadWithToken = (payload) => {
|
|
225
|
+
return typeof payload === "object" && payload !== null && "token" in payload && typeof payload?.token === "string";
|
|
226
|
+
};
|
|
194
227
|
|
|
195
228
|
// src/secure.ts
|
|
196
|
-
var import_node_crypto = __toESM(require("crypto"), 1)
|
|
197
229
|
var generateSecure = (length = 32) => {
|
|
198
|
-
|
|
199
|
-
}
|
|
230
|
+
return import_node_crypto.default.randomBytes(length).toString("base64url");
|
|
231
|
+
};
|
|
200
232
|
var createHash = (data, base = "hex") => {
|
|
201
|
-
|
|
202
|
-
}
|
|
233
|
+
return import_node_crypto.default.createHash("sha256").update(data).digest().toString(base);
|
|
234
|
+
};
|
|
203
235
|
var createPKCE = async (verifier) => {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
236
|
+
const codeVerifier = verifier ?? generateSecure(86);
|
|
237
|
+
const codeChallenge = createHash(codeVerifier, "base64url");
|
|
238
|
+
return { codeVerifier, codeChallenge, method: "S256" };
|
|
239
|
+
};
|
|
208
240
|
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 })
|
|
241
|
+
try {
|
|
242
|
+
const token = generateSecure(32);
|
|
243
|
+
if (csrfCookie) {
|
|
244
|
+
await jose.verifyJWS(csrfCookie);
|
|
245
|
+
return csrfCookie;
|
|
219
246
|
}
|
|
220
|
-
}
|
|
247
|
+
return jose.signJWS({ token });
|
|
248
|
+
} catch {
|
|
249
|
+
const token = generateSecure(32);
|
|
250
|
+
return jose.signJWS({ token });
|
|
251
|
+
}
|
|
252
|
+
};
|
|
221
253
|
var verifyCSRF = async (jose, cookie, header) => {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
throw new InvalidCsrfTokenError()
|
|
254
|
+
try {
|
|
255
|
+
const cookiePayload = await jose.verifyJWS(cookie);
|
|
256
|
+
const headerPayload = await jose.verifyJWS(header);
|
|
257
|
+
if (!isJWTPayloadWithToken(cookiePayload)) {
|
|
258
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Cookie payload missing token field.");
|
|
259
|
+
}
|
|
260
|
+
if (!isJWTPayloadWithToken(headerPayload)) {
|
|
261
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "Header payload missing token field.");
|
|
262
|
+
}
|
|
263
|
+
const cookieBuffer = Buffer.from(cookiePayload.token);
|
|
264
|
+
const headerBuffer = Buffer.from(headerPayload.token);
|
|
265
|
+
if (!equals(headerBuffer.length, cookieBuffer.length)) {
|
|
266
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
236
267
|
}
|
|
237
|
-
|
|
268
|
+
if (!import_node_crypto.default.timingSafeEqual(cookieBuffer, headerBuffer)) {
|
|
269
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
270
|
+
}
|
|
271
|
+
return true;
|
|
272
|
+
} catch {
|
|
273
|
+
throw new AuthSecurityError("CSRF_TOKEN_INVALID", "The CSRF tokens do not match.");
|
|
274
|
+
}
|
|
275
|
+
};
|
|
238
276
|
var createDerivedSalt = (secret) => {
|
|
239
|
-
|
|
240
|
-
}
|
|
277
|
+
return import_node_crypto.default.createHash("sha256").update(secret).update("aura-auth-salt").digest("hex");
|
|
278
|
+
};
|
|
241
279
|
|
|
242
280
|
// src/jose.ts
|
|
243
281
|
var createJoseInstance = (secret) => {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
var isValidURL = (value) => {
|
|
269
|
-
if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false
|
|
270
|
-
const regex =
|
|
271
|
-
/^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/
|
|
272
|
-
return regex.test(value)
|
|
273
|
-
}
|
|
282
|
+
const env = process.env;
|
|
283
|
+
secret ??= env.AURA_AUTH_SECRET ?? env.AUTH_SECRET;
|
|
284
|
+
if (!secret) {
|
|
285
|
+
throw new AuthInternalError(
|
|
286
|
+
"JOSE_INITIALIZATION_FAILED",
|
|
287
|
+
"AURA_AUTH_SECRET environment variable is not set and no secret was provided."
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
const salt = env.AURA_AUTH_SALT ?? env.AUTH_SALT ?? createDerivedSalt(secret);
|
|
291
|
+
const { derivedKey: derivedSigningKey } = (0, import_jose.createDeriveKey)(secret, salt, "signing");
|
|
292
|
+
const { derivedKey: derivedEncryptionKey } = (0, import_jose.createDeriveKey)(secret, salt, "encryption");
|
|
293
|
+
const { derivedKey: derivedCsrfTokenKey } = (0, import_jose.createDeriveKey)(secret, salt, "csrfToken");
|
|
294
|
+
const { decodeJWT, encodeJWT } = (0, import_jose.createJWT)({ jws: derivedSigningKey, jwe: derivedEncryptionKey });
|
|
295
|
+
const { signJWS, verifyJWS } = (0, import_jose.createJWS)(derivedCsrfTokenKey);
|
|
296
|
+
const { encryptJWE, decryptJWE } = (0, import_jose.createJWE)(derivedEncryptionKey);
|
|
297
|
+
return {
|
|
298
|
+
decodeJWT,
|
|
299
|
+
encodeJWT,
|
|
300
|
+
signJWS,
|
|
301
|
+
verifyJWS,
|
|
302
|
+
encryptJWE,
|
|
303
|
+
decryptJWE
|
|
304
|
+
};
|
|
305
|
+
};
|
|
274
306
|
|
|
275
307
|
// src/cookie.ts
|
|
276
|
-
var
|
|
277
|
-
var COOKIE_NAME = "aura-auth"
|
|
308
|
+
var import_cookie = require("@aura-stack/router/cookie");
|
|
309
|
+
var COOKIE_NAME = "aura-auth";
|
|
278
310
|
var defaultCookieOptions = {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
var defaultCookieConfig = {
|
|
285
|
-
strategy: "standard",
|
|
286
|
-
name: COOKIE_NAME,
|
|
287
|
-
options: defaultCookieOptions,
|
|
288
|
-
}
|
|
311
|
+
httpOnly: true,
|
|
312
|
+
sameSite: "lax",
|
|
313
|
+
path: "/",
|
|
314
|
+
maxAge: 60 * 60 * 24 * 15
|
|
315
|
+
};
|
|
289
316
|
var defaultStandardCookieConfig = {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
317
|
+
secure: false,
|
|
318
|
+
httpOnly: true
|
|
319
|
+
};
|
|
294
320
|
var defaultSecureCookieConfig = {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
321
|
+
secure: true,
|
|
322
|
+
httpOnly: true
|
|
323
|
+
};
|
|
298
324
|
var defaultHostCookieConfig = {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
var
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
return {
|
|
311
|
-
name: options2?.name ?? COOKIE_NAME,
|
|
312
|
-
prefix: options2?.prefix ?? (options2?.secure ? "__Secure-" : ""),
|
|
313
|
-
...defaultCookieOptions,
|
|
314
|
-
...options2,
|
|
315
|
-
}
|
|
316
|
-
}
|
|
325
|
+
secure: true,
|
|
326
|
+
httpOnly: true,
|
|
327
|
+
path: "/",
|
|
328
|
+
domain: void 0
|
|
329
|
+
};
|
|
330
|
+
var oauthCookieOptions = {
|
|
331
|
+
httpOnly: true,
|
|
332
|
+
maxAge: 5 * 60,
|
|
333
|
+
sameSite: "lax",
|
|
334
|
+
expires: new Date(Date.now() + 5 * 60 * 1e3)
|
|
335
|
+
};
|
|
317
336
|
var setCookie = (cookieName, value, options2) => {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
var getCookie = (
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
337
|
+
return (0, import_cookie.serialize)(cookieName, value, options2);
|
|
338
|
+
};
|
|
339
|
+
var expiredCookieAttributes = {
|
|
340
|
+
...defaultCookieOptions,
|
|
341
|
+
expires: /* @__PURE__ */ new Date(0),
|
|
342
|
+
maxAge: 0
|
|
343
|
+
};
|
|
344
|
+
var getCookie = (request, cookieName) => {
|
|
345
|
+
const cookies = request.headers.get("Cookie");
|
|
346
|
+
if (!cookies) {
|
|
347
|
+
throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
|
|
348
|
+
}
|
|
349
|
+
const value = (0, import_cookie.parse)(cookies)[cookieName];
|
|
350
|
+
if (!value) {
|
|
351
|
+
throw new AuthInternalError("COOKIE_NOT_FOUND", `Cookie "${cookieName}" not found. There is no active session`);
|
|
352
|
+
}
|
|
353
|
+
return value;
|
|
354
|
+
};
|
|
355
|
+
var createSessionCookie = async (jose, session) => {
|
|
356
|
+
try {
|
|
357
|
+
const encoded = await jose.encodeJWT(session);
|
|
358
|
+
return encoded;
|
|
359
|
+
} catch (error) {
|
|
360
|
+
throw new AuthInternalError("INVALID_JWT_TOKEN", "Failed to create session cookie", { cause: error });
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
var defineSecureCookieOptions = (useSecure, attributes, strategy) => {
|
|
364
|
+
if (!attributes.httpOnly) {
|
|
365
|
+
console.warn(
|
|
366
|
+
"[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
if (attributes.domain === "*") {
|
|
370
|
+
attributes.domain = void 0;
|
|
371
|
+
console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.");
|
|
372
|
+
}
|
|
373
|
+
if (!useSecure) {
|
|
374
|
+
if (attributes.secure) {
|
|
375
|
+
console.warn(
|
|
376
|
+
"[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
|
|
377
|
+
);
|
|
332
378
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (value === void 0) {
|
|
337
|
-
if (optional) {
|
|
338
|
-
return ""
|
|
339
|
-
}
|
|
340
|
-
throw new AuthError("invalid_request", `Cookie "${cookie}" not found. There is no active session`)
|
|
379
|
+
if (attributes.sameSite == "none") {
|
|
380
|
+
attributes.sameSite = "lax";
|
|
381
|
+
console.warn("[WARNING]: SameSite=None requires Secure attribute. Changing SameSite to 'Lax'.");
|
|
341
382
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
var createSessionCookie = async (session, cookieOptions, jose) => {
|
|
345
|
-
try {
|
|
346
|
-
const encoded = await jose.encodeJWT(session)
|
|
347
|
-
return setCookie("sessionToken", encoded, cookieOptions)
|
|
348
|
-
} catch (error) {
|
|
349
|
-
throw new AuthError("server_error", "Failed to create session cookie", { cause: error })
|
|
383
|
+
if (process.env.NODE_ENV === "production") {
|
|
384
|
+
console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.");
|
|
350
385
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const name = cookieOptions.name ?? COOKIE_NAME
|
|
354
|
-
const isSecure = trustedProxyHeaders
|
|
355
|
-
? request.url.startsWith("https://") ||
|
|
356
|
-
request.headers.get("X-Forwarded-Proto") === "https" ||
|
|
357
|
-
request.headers.get("Forwarded")?.includes("proto=https")
|
|
358
|
-
: request.url.startsWith("https://")
|
|
359
|
-
if (!cookieOptions.options?.httpOnly) {
|
|
360
|
-
console.warn(
|
|
361
|
-
"[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
|
|
362
|
-
)
|
|
386
|
+
if (strategy === "host") {
|
|
387
|
+
console.warn("[WARNING]: __Host- cookies require a secure context. Falling back to standard cookie settings.");
|
|
363
388
|
}
|
|
364
|
-
if (cookieOptions.options?.domain === "*") {
|
|
365
|
-
console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.")
|
|
366
|
-
}
|
|
367
|
-
if (!isSecure) {
|
|
368
|
-
const options2 = cookieOptions.options
|
|
369
|
-
if (options2?.secure) {
|
|
370
|
-
console.warn(
|
|
371
|
-
"[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
|
|
372
|
-
)
|
|
373
|
-
}
|
|
374
|
-
if (options2?.sameSite == "none") {
|
|
375
|
-
console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.")
|
|
376
|
-
}
|
|
377
|
-
if (process.env.NODE_ENV === "production") {
|
|
378
|
-
console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.")
|
|
379
|
-
}
|
|
380
|
-
return {
|
|
381
|
-
...defaultCookieOptions,
|
|
382
|
-
...cookieOptions.options,
|
|
383
|
-
sameSite: options2?.sameSite === "none" ? "lax" : (options2?.sameSite ?? "lax"),
|
|
384
|
-
...defaultStandardCookieConfig,
|
|
385
|
-
name,
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
return cookieOptions.strategy === "host"
|
|
389
|
-
? {
|
|
390
|
-
...defaultCookieOptions,
|
|
391
|
-
...cookieOptions.options,
|
|
392
|
-
...defaultHostCookieConfig,
|
|
393
|
-
name,
|
|
394
|
-
}
|
|
395
|
-
: { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name }
|
|
396
|
-
}
|
|
397
|
-
var expireCookie = (name, options2) => {
|
|
398
|
-
return setCookie(name, "", { ...options2, ...expiredCookieOptions })
|
|
399
|
-
}
|
|
400
|
-
var oauthCookie = (options2) => {
|
|
401
389
|
return {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
390
|
+
...defaultCookieOptions,
|
|
391
|
+
...attributes,
|
|
392
|
+
...defaultStandardCookieConfig
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
return strategy === "host" ? {
|
|
396
|
+
...defaultCookieOptions,
|
|
397
|
+
...attributes,
|
|
398
|
+
...defaultHostCookieConfig
|
|
399
|
+
} : { ...defaultCookieOptions, ...attributes, ...defaultSecureCookieConfig };
|
|
400
|
+
};
|
|
401
|
+
var createCookieStore = (useSecure, prefix, overrides) => {
|
|
402
|
+
prefix ??= COOKIE_NAME;
|
|
403
|
+
const securePrefix = useSecure ? "__Secure-" : "";
|
|
404
|
+
const hostPrefix = useSecure ? "__Host-" : "";
|
|
405
|
+
return {
|
|
406
|
+
sessionToken: {
|
|
407
|
+
name: `${securePrefix}${prefix}.${overrides?.sessionToken?.name ?? "sessionToken"}`,
|
|
408
|
+
attributes: defineSecureCookieOptions(
|
|
409
|
+
useSecure,
|
|
410
|
+
{
|
|
411
|
+
...defaultCookieOptions,
|
|
412
|
+
...overrides?.sessionToken?.attributes
|
|
413
|
+
},
|
|
414
|
+
overrides?.sessionToken?.attributes?.strategy ?? "secure"
|
|
415
|
+
)
|
|
416
|
+
},
|
|
417
|
+
state: {
|
|
418
|
+
name: `${securePrefix}${prefix}.${overrides?.state?.name ?? "state"}`,
|
|
419
|
+
attributes: defineSecureCookieOptions(
|
|
420
|
+
useSecure,
|
|
421
|
+
{
|
|
422
|
+
...oauthCookieOptions,
|
|
423
|
+
...overrides?.state?.attributes
|
|
424
|
+
},
|
|
425
|
+
overrides?.state?.attributes?.strategy ?? "secure"
|
|
426
|
+
)
|
|
427
|
+
},
|
|
428
|
+
csrfToken: {
|
|
429
|
+
name: `${hostPrefix}${prefix}.${overrides?.csrfToken?.name ?? "csrfToken"}`,
|
|
430
|
+
attributes: defineSecureCookieOptions(
|
|
431
|
+
useSecure,
|
|
432
|
+
{
|
|
433
|
+
...overrides?.csrfToken?.attributes,
|
|
434
|
+
...defaultHostCookieConfig
|
|
435
|
+
},
|
|
436
|
+
overrides?.csrfToken?.attributes?.strategy ?? "host"
|
|
437
|
+
)
|
|
438
|
+
},
|
|
439
|
+
redirect_to: {
|
|
440
|
+
name: `${securePrefix}${prefix}.${overrides?.redirect_to?.name ?? "redirect_to"}`,
|
|
441
|
+
attributes: defineSecureCookieOptions(
|
|
442
|
+
useSecure,
|
|
443
|
+
{
|
|
444
|
+
...oauthCookieOptions,
|
|
445
|
+
...overrides?.redirect_to?.attributes
|
|
446
|
+
},
|
|
447
|
+
overrides?.redirect_to?.attributes?.strategy ?? "secure"
|
|
448
|
+
)
|
|
449
|
+
},
|
|
450
|
+
redirect_uri: {
|
|
451
|
+
name: `${securePrefix}${prefix}.${overrides?.redirect_uri?.name ?? "redirect_uri"}`,
|
|
452
|
+
attributes: defineSecureCookieOptions(
|
|
453
|
+
useSecure,
|
|
454
|
+
{
|
|
455
|
+
...oauthCookieOptions,
|
|
456
|
+
...overrides?.redirect_uri?.attributes
|
|
457
|
+
},
|
|
458
|
+
overrides?.redirect_uri?.attributes?.strategy ?? "secure"
|
|
459
|
+
)
|
|
460
|
+
},
|
|
461
|
+
code_verifier: {
|
|
462
|
+
name: `${securePrefix}${prefix}.${overrides?.code_verifier?.name ?? "code_verifier"}`,
|
|
463
|
+
attributes: defineSecureCookieOptions(
|
|
464
|
+
useSecure,
|
|
465
|
+
{
|
|
466
|
+
...oauthCookieOptions,
|
|
467
|
+
...overrides?.code_verifier?.attributes
|
|
468
|
+
},
|
|
469
|
+
overrides?.code_verifier?.attributes?.strategy ?? "secure"
|
|
470
|
+
)
|
|
407
471
|
}
|
|
408
|
-
}
|
|
472
|
+
};
|
|
473
|
+
};
|
|
409
474
|
|
|
410
475
|
// src/oauth/github.ts
|
|
411
476
|
var github = {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}
|
|
477
|
+
id: "github",
|
|
478
|
+
name: "GitHub",
|
|
479
|
+
authorizeURL: "https://github.com/login/oauth/authorize",
|
|
480
|
+
accessToken: "https://github.com/login/oauth/access_token",
|
|
481
|
+
userInfo: "https://api.github.com/user",
|
|
482
|
+
scope: "read:user user:email",
|
|
483
|
+
responseType: "code"
|
|
484
|
+
};
|
|
420
485
|
|
|
421
486
|
// src/oauth/bitbucket.ts
|
|
422
487
|
var bitbucket = {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
488
|
+
id: "bitbucket",
|
|
489
|
+
name: "Bitbucket",
|
|
490
|
+
authorizeURL: "https://bitbucket.org/site/oauth2/authorize",
|
|
491
|
+
accessToken: "https://bitbucket.org/site/oauth2/access_token",
|
|
492
|
+
userInfo: "https://api.bitbucket.org/2.0/user",
|
|
493
|
+
scope: "account email",
|
|
494
|
+
responseType: "code",
|
|
495
|
+
profile(profile) {
|
|
496
|
+
return {
|
|
497
|
+
sub: profile.uuid ?? profile.account_id,
|
|
498
|
+
name: profile.display_name ?? profile.nickname,
|
|
499
|
+
image: profile.links.avatar.href
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
};
|
|
438
503
|
|
|
439
504
|
// src/oauth/figma.ts
|
|
440
505
|
var figma = {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
506
|
+
id: "figma",
|
|
507
|
+
name: "Figma",
|
|
508
|
+
authorizeURL: "https://www.figma.com/oauth",
|
|
509
|
+
accessToken: "https://api.figma.com/v1/oauth/token",
|
|
510
|
+
userInfo: "https://api.figma.com/v1/me",
|
|
511
|
+
scope: "current_user:read",
|
|
512
|
+
responseType: "code",
|
|
513
|
+
profile(profile) {
|
|
514
|
+
return {
|
|
515
|
+
sub: profile.id,
|
|
516
|
+
name: profile.handle,
|
|
517
|
+
email: profile.email,
|
|
518
|
+
image: profile.img_url
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
};
|
|
457
522
|
|
|
458
523
|
// src/oauth/discord.ts
|
|
459
524
|
var discord = {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
}
|
|
525
|
+
id: "discord",
|
|
526
|
+
name: "Discord",
|
|
527
|
+
authorizeURL: "https://discord.com/oauth2/authorize",
|
|
528
|
+
accessToken: "https://discord.com/api/oauth2/token",
|
|
529
|
+
userInfo: "https://discord.com/api/users/@me",
|
|
530
|
+
scope: "identify email",
|
|
531
|
+
responseType: "code",
|
|
532
|
+
profile(profile) {
|
|
533
|
+
let image = "";
|
|
534
|
+
if (profile.avatar === null) {
|
|
535
|
+
const index = profile.discriminator === "0" ? (BigInt(profile.id) >> 22n) % 6n : Number(profile.discriminator) % 5;
|
|
536
|
+
image = `https://cdn.discordapp.com/embed/avatars/${index}.png`;
|
|
537
|
+
} else {
|
|
538
|
+
const format = profile.avatar.startsWith("a_") ? "gif" : "png";
|
|
539
|
+
image = `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.${format}`;
|
|
540
|
+
}
|
|
541
|
+
return {
|
|
542
|
+
sub: profile.id,
|
|
543
|
+
name: profile.global_name ?? profile.username,
|
|
544
|
+
email: profile.email ?? "",
|
|
545
|
+
image
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
};
|
|
485
549
|
|
|
486
550
|
// src/oauth/gitlab.ts
|
|
487
551
|
var gitlab = {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
552
|
+
id: "gitlab",
|
|
553
|
+
name: "GitLab",
|
|
554
|
+
authorizeURL: "https://gitlab.com/oauth/authorize",
|
|
555
|
+
accessToken: "https://gitlab.com/oauth/token",
|
|
556
|
+
userInfo: "https://gitlab.com/api/v4/user",
|
|
557
|
+
scope: "read_user",
|
|
558
|
+
responseType: "code",
|
|
559
|
+
profile(profile) {
|
|
560
|
+
return {
|
|
561
|
+
sub: profile.id.toString(),
|
|
562
|
+
name: profile.name ?? profile.username,
|
|
563
|
+
email: profile.email,
|
|
564
|
+
avatar: profile.avatar_url
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
};
|
|
504
568
|
|
|
505
569
|
// src/oauth/spotify.ts
|
|
506
570
|
var spotify = {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
}
|
|
571
|
+
id: "spotify",
|
|
572
|
+
name: "Spotify",
|
|
573
|
+
authorizeURL: "https://accounts.spotify.com/authorize",
|
|
574
|
+
accessToken: "https://accounts.spotify.com/api/token",
|
|
575
|
+
userInfo: "https://api.spotify.com/v1/me",
|
|
576
|
+
scope: "user-read-email user-read-private",
|
|
577
|
+
responseType: "token",
|
|
578
|
+
profile(profile) {
|
|
579
|
+
return {
|
|
580
|
+
sub: profile.id,
|
|
581
|
+
name: profile.display_name,
|
|
582
|
+
email: profile.email,
|
|
583
|
+
image: profile.images?.[0]?.url
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
};
|
|
523
587
|
|
|
524
588
|
// src/oauth/x.ts
|
|
525
589
|
var x = {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
return {
|
|
535
|
-
sub: data.id,
|
|
536
|
-
name: data.name,
|
|
537
|
-
image: data.profile_image_url,
|
|
538
|
-
email: "",
|
|
539
|
-
}
|
|
540
|
-
},
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
// src/oauth/index.ts
|
|
544
|
-
var builtInOAuthProviders = {
|
|
545
|
-
github,
|
|
546
|
-
bitbucket,
|
|
547
|
-
figma,
|
|
548
|
-
discord,
|
|
549
|
-
gitlab,
|
|
550
|
-
spotify,
|
|
551
|
-
x,
|
|
552
|
-
}
|
|
553
|
-
var defineOAuthEnvironment = (oauth) => {
|
|
554
|
-
const env = process.env
|
|
590
|
+
id: "x",
|
|
591
|
+
name: "X",
|
|
592
|
+
authorizeURL: "https://x.com/i/oauth2/authorize",
|
|
593
|
+
accessToken: "https://api.x.com/2/oauth2/token",
|
|
594
|
+
userInfo: "https://api.x.com/2/users/me?user.fields=profile_image_url",
|
|
595
|
+
scope: "users.read users.email tweet.read offline.access",
|
|
596
|
+
responseType: "code",
|
|
597
|
+
profile({ data }) {
|
|
555
598
|
return {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
const oauthConfig = builtInOAuthProviders[config2]
|
|
564
|
-
return {
|
|
565
|
-
...oauthConfig,
|
|
566
|
-
...definition,
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
return config2
|
|
570
|
-
}
|
|
571
|
-
var createBuiltInOAuthProviders = (oauth = []) => {
|
|
572
|
-
return oauth.reduce((previous, config2) => {
|
|
573
|
-
const oauthConfig = defineOAuthProviderConfig(config2)
|
|
574
|
-
return { ...previous, [oauthConfig.id]: oauthConfig }
|
|
575
|
-
}, {})
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
// src/actions/signIn/signIn.ts
|
|
579
|
-
var import_zod = __toESM(require("zod"), 1)
|
|
580
|
-
var import_router2 = require("@aura-stack/router")
|
|
599
|
+
sub: data.id,
|
|
600
|
+
name: data.name,
|
|
601
|
+
image: data.profile_image_url,
|
|
602
|
+
email: ""
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
};
|
|
581
606
|
|
|
582
|
-
// src/
|
|
583
|
-
var
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
607
|
+
// src/oauth/strava.ts
|
|
608
|
+
var strava = {
|
|
609
|
+
id: "strava",
|
|
610
|
+
name: "Strava",
|
|
611
|
+
authorizeURL: "https://www.strava.com/oauth/authorize",
|
|
612
|
+
accessToken: "https://www.strava.com/oauth/token",
|
|
613
|
+
userInfo: "https://www.strava.com/api/v3/athlete",
|
|
614
|
+
scope: "read",
|
|
615
|
+
responseType: "code",
|
|
616
|
+
profile(profile) {
|
|
617
|
+
return {
|
|
618
|
+
sub: profile.id.toString(),
|
|
619
|
+
name: `${profile.firstname} ${profile.lastname}`,
|
|
620
|
+
image: profile.profile,
|
|
621
|
+
email: ""
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
};
|
|
588
625
|
|
|
589
626
|
// src/schemas.ts
|
|
590
|
-
var import_v4 = require("zod/v4")
|
|
627
|
+
var import_v4 = require("zod/v4");
|
|
591
628
|
var OAuthProviderConfigSchema = (0, import_v4.object)({
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
})
|
|
629
|
+
authorizeURL: (0, import_v4.httpUrl)(),
|
|
630
|
+
accessToken: (0, import_v4.httpUrl)(),
|
|
631
|
+
scope: (0, import_v4.string)().optional(),
|
|
632
|
+
userInfo: (0, import_v4.httpUrl)(),
|
|
633
|
+
responseType: (0, import_v4.enum)(["code", "token", "id_token"]),
|
|
634
|
+
clientId: (0, import_v4.string)(),
|
|
635
|
+
clientSecret: (0, import_v4.string)()
|
|
636
|
+
});
|
|
600
637
|
var OAuthAuthorization = OAuthProviderConfigSchema.extend({
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
})
|
|
638
|
+
redirectURI: (0, import_v4.string)(),
|
|
639
|
+
state: (0, import_v4.string)(),
|
|
640
|
+
codeChallenge: (0, import_v4.string)(),
|
|
641
|
+
codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"])
|
|
642
|
+
});
|
|
606
643
|
var OAuthAuthorizationResponse = (0, import_v4.object)({
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
})
|
|
644
|
+
state: (0, import_v4.string)("Missing state parameter in the OAuth authorization response."),
|
|
645
|
+
code: (0, import_v4.string)("Missing code parameter in the OAuth authorization response.")
|
|
646
|
+
});
|
|
610
647
|
var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
})
|
|
648
|
+
error: (0, import_v4.enum)([
|
|
649
|
+
"invalid_request",
|
|
650
|
+
"unauthorized_client",
|
|
651
|
+
"access_denied",
|
|
652
|
+
"unsupported_response_type",
|
|
653
|
+
"invalid_scope",
|
|
654
|
+
"server_error",
|
|
655
|
+
"temporarily_unavailable"
|
|
656
|
+
]),
|
|
657
|
+
error_description: (0, import_v4.string)().optional(),
|
|
658
|
+
error_uri: (0, import_v4.string)().optional(),
|
|
659
|
+
state: (0, import_v4.string)()
|
|
660
|
+
});
|
|
624
661
|
var OAuthAccessToken = OAuthProviderConfigSchema.extend({
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
})
|
|
662
|
+
redirectURI: (0, import_v4.string)(),
|
|
663
|
+
code: (0, import_v4.string)(),
|
|
664
|
+
codeVerifier: (0, import_v4.string)().min(43).max(128)
|
|
665
|
+
});
|
|
629
666
|
var OAuthAccessTokenResponse = (0, import_v4.object)({
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
})
|
|
667
|
+
access_token: (0, import_v4.string)(),
|
|
668
|
+
token_type: (0, import_v4.string)(),
|
|
669
|
+
expires_in: (0, import_v4.number)().optional(),
|
|
670
|
+
refresh_token: (0, import_v4.string)().optional(),
|
|
671
|
+
scope: (0, import_v4.string)().optional()
|
|
672
|
+
});
|
|
636
673
|
var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
})
|
|
674
|
+
error: (0, import_v4.enum)([
|
|
675
|
+
"invalid_request",
|
|
676
|
+
"invalid_client",
|
|
677
|
+
"invalid_grant",
|
|
678
|
+
"unauthorized_client",
|
|
679
|
+
"unsupported_grant_type",
|
|
680
|
+
"invalid_scope"
|
|
681
|
+
]),
|
|
682
|
+
error_description: (0, import_v4.string)().optional(),
|
|
683
|
+
error_uri: (0, import_v4.string)().optional()
|
|
684
|
+
});
|
|
648
685
|
var OAuthErrorResponse = (0, import_v4.object)({
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
})
|
|
686
|
+
error: (0, import_v4.string)(),
|
|
687
|
+
error_description: (0, import_v4.string)().optional()
|
|
688
|
+
});
|
|
689
|
+
var OAuthEnvSchema = (0, import_v4.object)({
|
|
690
|
+
clientId: import_v4.z.string().min(1, "OAuth Client ID is required in the environment variables."),
|
|
691
|
+
clientSecret: import_v4.z.string().min(1, "OAuth Client Secret is required in the environment variables.")
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
// src/oauth/index.ts
|
|
695
|
+
var builtInOAuthProviders = {
|
|
696
|
+
github,
|
|
697
|
+
bitbucket,
|
|
698
|
+
figma,
|
|
699
|
+
discord,
|
|
700
|
+
gitlab,
|
|
701
|
+
spotify,
|
|
702
|
+
x,
|
|
703
|
+
strava
|
|
704
|
+
};
|
|
705
|
+
var defineOAuthEnvironment = (oauth) => {
|
|
706
|
+
const env = process.env;
|
|
707
|
+
const clientIdSuffix = `${oauth.toUpperCase()}_CLIENT_ID`;
|
|
708
|
+
const clientSecretSuffix = `${oauth.toUpperCase()}_CLIENT_SECRET`;
|
|
709
|
+
const loadEnvs = OAuthEnvSchema.safeParse({
|
|
710
|
+
clientId: env[`AURA_AUTH_${clientIdSuffix}`] ?? env[`AUTH_${clientIdSuffix}`] ?? env[`${clientIdSuffix}`],
|
|
711
|
+
clientSecret: env[`AURA_AUTH_${clientSecretSuffix}`] ?? env[`AUTH_${clientSecretSuffix}`] ?? env[`${clientSecretSuffix}`]
|
|
712
|
+
});
|
|
713
|
+
if (!loadEnvs.success) {
|
|
714
|
+
const msg = JSON.stringify(formatZodError(loadEnvs.error), null, 2);
|
|
715
|
+
throw new AuthInternalError("INVALID_ENVIRONMENT_CONFIGURATION", msg);
|
|
716
|
+
}
|
|
717
|
+
return loadEnvs.data;
|
|
718
|
+
};
|
|
719
|
+
var defineOAuthProviderConfig = (config2) => {
|
|
720
|
+
if (typeof config2 === "string") {
|
|
721
|
+
const definition = defineOAuthEnvironment(config2);
|
|
722
|
+
const oauthConfig = builtInOAuthProviders[config2];
|
|
723
|
+
return {
|
|
724
|
+
...oauthConfig,
|
|
725
|
+
...definition
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
return config2;
|
|
729
|
+
};
|
|
730
|
+
var createBuiltInOAuthProviders = (oauth = []) => {
|
|
731
|
+
return oauth.reduce((previous, config2) => {
|
|
732
|
+
const oauthConfig = defineOAuthProviderConfig(config2);
|
|
733
|
+
return { ...previous, [oauthConfig.id]: oauthConfig };
|
|
734
|
+
}, {});
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
// src/actions/signIn/signIn.ts
|
|
738
|
+
var import_zod = __toESM(require("zod"), 1);
|
|
739
|
+
var import_router2 = require("@aura-stack/router");
|
|
652
740
|
|
|
653
741
|
// src/actions/signIn/authorization.ts
|
|
654
742
|
var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
}
|
|
743
|
+
const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod });
|
|
744
|
+
if (!parsed.success) {
|
|
745
|
+
const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
|
|
746
|
+
throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
|
|
747
|
+
}
|
|
748
|
+
const { authorizeURL, ...options2 } = parsed.data;
|
|
749
|
+
const { userInfo, accessToken, clientSecret, ...required } = options2;
|
|
750
|
+
const searchParams = new URLSearchParams(toCastCase(required));
|
|
751
|
+
return `${authorizeURL}?${searchParams}`;
|
|
752
|
+
};
|
|
664
753
|
var getOriginURL = (request, trustedProxyHeaders) => {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
} else {
|
|
675
|
-
return new URL(getNormalizedOriginPath(request.url))
|
|
676
|
-
}
|
|
677
|
-
}
|
|
754
|
+
const headers = request.headers;
|
|
755
|
+
if (trustedProxyHeaders) {
|
|
756
|
+
const protocol = headers.get("X-Forwarded-Proto") ?? headers.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? "http";
|
|
757
|
+
const host = headers.get("X-Forwarded-Host") ?? headers.get("Host") ?? headers.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ?? null;
|
|
758
|
+
return new URL(`${protocol}://${host}${getNormalizedOriginPath(new URL(request.url).pathname)}`);
|
|
759
|
+
} else {
|
|
760
|
+
return new URL(getNormalizedOriginPath(request.url));
|
|
761
|
+
}
|
|
762
|
+
};
|
|
678
763
|
var createRedirectURI = (request, oauth, basePath, trustedProxyHeaders) => {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
}
|
|
764
|
+
const url = getOriginURL(request, trustedProxyHeaders);
|
|
765
|
+
return `${url.origin}${basePath}/callback/${oauth}`;
|
|
766
|
+
};
|
|
682
767
|
var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
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
|
-
if (isAuthError(error)) {
|
|
718
|
-
throw error
|
|
719
|
-
}
|
|
720
|
-
throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).")
|
|
768
|
+
try {
|
|
769
|
+
const headers = request.headers;
|
|
770
|
+
const origin = headers.get("Origin");
|
|
771
|
+
const referer = headers.get("Referer");
|
|
772
|
+
let hostedURL = getOriginURL(request, trustedProxyHeaders);
|
|
773
|
+
if (redirectTo) {
|
|
774
|
+
if (redirectTo.startsWith("/")) {
|
|
775
|
+
return sanitizeURL(redirectTo);
|
|
776
|
+
}
|
|
777
|
+
const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)));
|
|
778
|
+
if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
|
|
779
|
+
throw new AuthSecurityError(
|
|
780
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
781
|
+
"The redirectTo parameter does not match the hosted origin."
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
return sanitizeURL(redirectToURL.pathname);
|
|
785
|
+
}
|
|
786
|
+
if (referer) {
|
|
787
|
+
const refererURL = new URL(sanitizeURL(referer));
|
|
788
|
+
if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
|
|
789
|
+
throw new AuthSecurityError(
|
|
790
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
791
|
+
"The referer of the request does not match the hosted origin."
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
return sanitizeURL(refererURL.pathname);
|
|
795
|
+
}
|
|
796
|
+
if (origin) {
|
|
797
|
+
const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)));
|
|
798
|
+
if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
|
|
799
|
+
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
800
|
+
}
|
|
801
|
+
return sanitizeURL(originURL.pathname);
|
|
721
802
|
}
|
|
722
|
-
|
|
803
|
+
return "/";
|
|
804
|
+
} catch (error) {
|
|
805
|
+
if (isAuthSecurityError(error)) {
|
|
806
|
+
throw error;
|
|
807
|
+
}
|
|
808
|
+
throw new AuthSecurityError("POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED", "Invalid origin (potential CSRF).");
|
|
809
|
+
}
|
|
810
|
+
};
|
|
723
811
|
|
|
724
812
|
// src/actions/signIn/signIn.ts
|
|
725
813
|
var signInConfig = (oauth) => {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
}
|
|
814
|
+
return (0, import_router2.createEndpointConfig)("/signIn/:oauth", {
|
|
815
|
+
schemas: {
|
|
816
|
+
params: import_zod.default.object({
|
|
817
|
+
oauth: import_zod.default.enum(Object.keys(oauth), "The OAuth provider is not supported or invalid."),
|
|
818
|
+
redirectTo: import_zod.default.string().optional()
|
|
819
|
+
})
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
};
|
|
735
823
|
var signInAction = (oauth) => {
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
headers.append("Set-Cookie", redirectToCookie)
|
|
764
|
-
headers.append("Set-Cookie", codeVerifierCookie)
|
|
765
|
-
return Response.json(
|
|
766
|
-
{ oauth: oauth2 },
|
|
767
|
-
{
|
|
768
|
-
status: 302,
|
|
769
|
-
headers,
|
|
770
|
-
}
|
|
771
|
-
)
|
|
772
|
-
} catch (error) {
|
|
773
|
-
if (isAuthError(error)) {
|
|
774
|
-
const { type, message } = error
|
|
775
|
-
return AuraResponse.json(
|
|
776
|
-
{ error: type, error_description: message },
|
|
777
|
-
{ status: import_router2.statusCode.BAD_REQUEST }
|
|
778
|
-
)
|
|
779
|
-
}
|
|
780
|
-
return AuraResponse.json(
|
|
781
|
-
{
|
|
782
|
-
error: ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR,
|
|
783
|
-
error_description: "An unexpected error occurred",
|
|
784
|
-
},
|
|
785
|
-
{ status: import_router2.statusCode.INTERNAL_SERVER_ERROR }
|
|
786
|
-
)
|
|
787
|
-
}
|
|
788
|
-
},
|
|
789
|
-
signInConfig(oauth)
|
|
790
|
-
)
|
|
791
|
-
}
|
|
824
|
+
return (0, import_router2.createEndpoint)(
|
|
825
|
+
"GET",
|
|
826
|
+
"/signIn/:oauth",
|
|
827
|
+
async (ctx) => {
|
|
828
|
+
const {
|
|
829
|
+
request,
|
|
830
|
+
headers: headersBuilder,
|
|
831
|
+
params: { oauth: oauth2, redirectTo },
|
|
832
|
+
context: { oauth: providers, cookies, trustedProxyHeaders, basePath }
|
|
833
|
+
} = ctx;
|
|
834
|
+
const state = generateSecure();
|
|
835
|
+
const redirectURI = createRedirectURI(request, oauth2, basePath, trustedProxyHeaders);
|
|
836
|
+
const redirectToValue = createRedirectTo(request, redirectTo, trustedProxyHeaders);
|
|
837
|
+
const { codeVerifier, codeChallenge, method } = await createPKCE();
|
|
838
|
+
const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method);
|
|
839
|
+
const headers = headersBuilder.setHeader("Location", authorization).setCookie(cookies.state.name, state, cookies.state.attributes).setCookie(cookies.redirect_uri.name, redirectURI, cookies.redirect_uri.attributes).setCookie(cookies.redirect_to.name, redirectToValue, cookies.redirect_to.attributes).setCookie(cookies.code_verifier.name, codeVerifier, cookies.code_verifier.attributes).toHeaders();
|
|
840
|
+
return Response.json(
|
|
841
|
+
{ oauth: oauth2 },
|
|
842
|
+
{
|
|
843
|
+
status: 302,
|
|
844
|
+
headers
|
|
845
|
+
}
|
|
846
|
+
);
|
|
847
|
+
},
|
|
848
|
+
signInConfig(oauth)
|
|
849
|
+
);
|
|
850
|
+
};
|
|
792
851
|
|
|
793
852
|
// src/actions/callback/callback.ts
|
|
794
|
-
var import_zod2 = __toESM(require("zod"), 1)
|
|
795
|
-
var import_router3 = require("@aura-stack/router")
|
|
853
|
+
var import_zod2 = __toESM(require("zod"), 1);
|
|
854
|
+
var import_router3 = require("@aura-stack/router");
|
|
796
855
|
|
|
797
856
|
// src/headers.ts
|
|
798
857
|
var cacheControl = {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
}
|
|
858
|
+
"Cache-Control": "no-store",
|
|
859
|
+
Pragma: "no-cache",
|
|
860
|
+
Expires: "0",
|
|
861
|
+
Vary: "Cookie"
|
|
862
|
+
};
|
|
804
863
|
|
|
805
864
|
// src/actions/callback/userinfo.ts
|
|
806
865
|
var getDefaultUserInfo = (profile) => {
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
}
|
|
866
|
+
const sub = generateSecure(16);
|
|
867
|
+
return {
|
|
868
|
+
sub: profile?.id ?? profile?.sub ?? sub,
|
|
869
|
+
email: profile?.email,
|
|
870
|
+
name: profile?.name ?? profile?.username ?? profile?.nickname,
|
|
871
|
+
image: profile?.image ?? profile?.picture
|
|
872
|
+
};
|
|
873
|
+
};
|
|
815
874
|
var getUserInfo = async (oauthConfig, accessToken) => {
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
875
|
+
const userinfoEndpoint = oauthConfig.userInfo;
|
|
876
|
+
try {
|
|
877
|
+
const response = await fetch(userinfoEndpoint, {
|
|
878
|
+
method: "GET",
|
|
879
|
+
headers: {
|
|
880
|
+
Accept: "application/json",
|
|
881
|
+
Authorization: `Bearer ${accessToken}`
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
const json = await response.json();
|
|
885
|
+
const { success, data } = OAuthErrorResponse.safeParse(json);
|
|
886
|
+
if (success) {
|
|
887
|
+
throw new OAuthProtocolError(
|
|
888
|
+
data.error,
|
|
889
|
+
data?.error_description ?? "An error occurred while fetching user information."
|
|
890
|
+
);
|
|
891
|
+
}
|
|
892
|
+
return oauthConfig?.profile ? oauthConfig.profile(json) : getDefaultUserInfo(json);
|
|
893
|
+
} catch (error) {
|
|
894
|
+
if (isOAuthProtocolError(error)) {
|
|
895
|
+
throw error;
|
|
833
896
|
}
|
|
834
|
-
|
|
897
|
+
if (isNativeError(error)) {
|
|
898
|
+
throw new OAuthProtocolError("invalid_request", error.message, "", { cause: error });
|
|
899
|
+
}
|
|
900
|
+
throw new OAuthProtocolError("invalid_request", "Failed to fetch user information.", "", { cause: error });
|
|
901
|
+
}
|
|
902
|
+
};
|
|
835
903
|
|
|
836
904
|
// src/actions/callback/access-token.ts
|
|
837
905
|
var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) => {
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
return token.data
|
|
869
|
-
} catch (error) {
|
|
870
|
-
throw throwAuthError(error, "Failed to create access token")
|
|
906
|
+
const parsed = OAuthAccessToken.safeParse({ ...oauthConfig, redirectURI, code, codeVerifier });
|
|
907
|
+
if (!parsed.success) {
|
|
908
|
+
const msg = JSON.stringify(formatZodError(parsed.error), null, 2);
|
|
909
|
+
throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", msg);
|
|
910
|
+
}
|
|
911
|
+
const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data;
|
|
912
|
+
try {
|
|
913
|
+
const response = await fetch(accessToken, {
|
|
914
|
+
method: "POST",
|
|
915
|
+
headers: {
|
|
916
|
+
Accept: "application/json",
|
|
917
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
918
|
+
},
|
|
919
|
+
body: new URLSearchParams({
|
|
920
|
+
client_id: clientId,
|
|
921
|
+
client_secret: clientSecret,
|
|
922
|
+
code: codeParsed,
|
|
923
|
+
redirect_uri: redirectParsed,
|
|
924
|
+
grant_type: "authorization_code",
|
|
925
|
+
code_verifier: codeVerifier
|
|
926
|
+
}).toString()
|
|
927
|
+
});
|
|
928
|
+
const json = await response.json();
|
|
929
|
+
const token = OAuthAccessTokenResponse.safeParse(json);
|
|
930
|
+
if (!token.success) {
|
|
931
|
+
const { success, data } = OAuthAccessTokenErrorResponse.safeParse(json);
|
|
932
|
+
if (!success) {
|
|
933
|
+
throw new OAuthProtocolError("INVALID_REQUEST", "Invalid access token response format");
|
|
934
|
+
}
|
|
935
|
+
throw new OAuthProtocolError(data.error, data?.error_description ?? "Failed to retrieve access token");
|
|
871
936
|
}
|
|
872
|
-
|
|
937
|
+
return token.data;
|
|
938
|
+
} catch (error) {
|
|
939
|
+
throw error;
|
|
940
|
+
}
|
|
941
|
+
};
|
|
873
942
|
|
|
874
943
|
// src/actions/callback/callback.ts
|
|
875
944
|
var callbackConfig = (oauth) => {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
}
|
|
945
|
+
return (0, import_router3.createEndpointConfig)("/callback/:oauth", {
|
|
946
|
+
schemas: {
|
|
947
|
+
searchParams: OAuthAuthorizationResponse,
|
|
948
|
+
params: import_zod2.default.object({
|
|
949
|
+
oauth: import_zod2.default.enum(Object.keys(oauth), "The OAuth provider is not supported or invalid.")
|
|
950
|
+
})
|
|
951
|
+
},
|
|
952
|
+
middlewares: [
|
|
953
|
+
(ctx) => {
|
|
954
|
+
const response = OAuthAuthorizationErrorResponse.safeParse(ctx.searchParams);
|
|
955
|
+
if (response.success) {
|
|
956
|
+
const { error, error_description } = response.data;
|
|
957
|
+
throw new OAuthProtocolError(error, error_description ?? "OAuth Authorization Error");
|
|
958
|
+
}
|
|
959
|
+
return ctx;
|
|
960
|
+
}
|
|
961
|
+
]
|
|
962
|
+
});
|
|
963
|
+
};
|
|
895
964
|
var callbackAction = (oauth) => {
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
{
|
|
935
|
-
...cookies,
|
|
936
|
-
strategy: "host",
|
|
937
|
-
},
|
|
938
|
-
trustedProxyHeaders
|
|
939
|
-
)
|
|
940
|
-
)
|
|
941
|
-
headers.set("Set-Cookie", sessionCookie)
|
|
942
|
-
headers.append("Set-Cookie", expireCookie("state", cookieOptions))
|
|
943
|
-
headers.append("Set-Cookie", expireCookie("redirect_uri", cookieOptions))
|
|
944
|
-
headers.append("Set-Cookie", expireCookie("redirect_to", cookieOptions))
|
|
945
|
-
headers.append("Set-Cookie", expireCookie("code_verifier", cookieOptions))
|
|
946
|
-
headers.append("Set-Cookie", csrfCookie)
|
|
947
|
-
return Response.json({ oauth: oauth2 }, { status: 302, headers })
|
|
948
|
-
} catch (error) {
|
|
949
|
-
if (isAuthError(error)) {
|
|
950
|
-
const { type, message } = error
|
|
951
|
-
return AuraResponse.json(
|
|
952
|
-
{ error: type, error_description: message },
|
|
953
|
-
{ status: import_router3.statusCode.BAD_REQUEST }
|
|
954
|
-
)
|
|
955
|
-
}
|
|
956
|
-
return AuraResponse.json(
|
|
957
|
-
{
|
|
958
|
-
error: ERROR_RESPONSE.ACCESS_TOKEN.INVALID_CLIENT,
|
|
959
|
-
error_description: "An unexpected error occurred",
|
|
960
|
-
},
|
|
961
|
-
{ status: import_router3.statusCode.INTERNAL_SERVER_ERROR }
|
|
962
|
-
)
|
|
963
|
-
}
|
|
964
|
-
},
|
|
965
|
-
callbackConfig(oauth)
|
|
966
|
-
)
|
|
967
|
-
}
|
|
965
|
+
return (0, import_router3.createEndpoint)(
|
|
966
|
+
"GET",
|
|
967
|
+
"/callback/:oauth",
|
|
968
|
+
async (ctx) => {
|
|
969
|
+
const {
|
|
970
|
+
request,
|
|
971
|
+
params: { oauth: oauth2 },
|
|
972
|
+
searchParams: { code, state },
|
|
973
|
+
context: { oauth: providers, cookies, jose }
|
|
974
|
+
} = ctx;
|
|
975
|
+
const oauthConfig = providers[oauth2];
|
|
976
|
+
const cookieState = getCookie(request, cookies.state.name);
|
|
977
|
+
const cookieRedirectTo = getCookie(request, cookies.redirect_to.name);
|
|
978
|
+
const cookieRedirectURI = getCookie(request, cookies.redirect_uri.name);
|
|
979
|
+
const codeVerifier = getCookie(request, cookies.code_verifier.name);
|
|
980
|
+
if (!equals(cookieState, state)) {
|
|
981
|
+
throw new AuthSecurityError(
|
|
982
|
+
"MISMATCHING_STATE",
|
|
983
|
+
"The provided state passed in the OAuth response does not match the stored state."
|
|
984
|
+
);
|
|
985
|
+
}
|
|
986
|
+
const accessToken = await createAccessToken(oauthConfig, cookieRedirectURI, code, codeVerifier);
|
|
987
|
+
const sanitized = sanitizeURL(cookieRedirectTo);
|
|
988
|
+
if (!isValidRelativePath(sanitized)) {
|
|
989
|
+
throw new AuthSecurityError(
|
|
990
|
+
"POTENTIAL_OPEN_REDIRECT_ATTACK_DETECTED",
|
|
991
|
+
"Invalid redirect path. Potential open redirect attack detected."
|
|
992
|
+
);
|
|
993
|
+
}
|
|
994
|
+
const userInfo = await getUserInfo(oauthConfig, accessToken.access_token);
|
|
995
|
+
const sessionCookie = await createSessionCookie(jose, userInfo);
|
|
996
|
+
const csrfToken = await createCSRF(jose);
|
|
997
|
+
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.redirect_uri.name, "", expiredCookieAttributes).setCookie(cookies.redirect_to.name, "", expiredCookieAttributes).setCookie(cookies.code_verifier.name, "", expiredCookieAttributes).toHeaders();
|
|
998
|
+
return Response.json({ oauth: oauth2 }, { status: 302, headers });
|
|
999
|
+
},
|
|
1000
|
+
callbackConfig(oauth)
|
|
1001
|
+
);
|
|
1002
|
+
};
|
|
968
1003
|
|
|
969
1004
|
// src/actions/session/session.ts
|
|
970
|
-
var import_router4 = require("@aura-stack/router")
|
|
1005
|
+
var import_router4 = require("@aura-stack/router");
|
|
971
1006
|
var sessionAction = (0, import_router4.createEndpoint)("GET", "/session", async (ctx) => {
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
return Response.json({ authenticated: false, message: "Unauthorized" }, { status: 401, headers })
|
|
988
|
-
}
|
|
989
|
-
})
|
|
1007
|
+
const {
|
|
1008
|
+
request,
|
|
1009
|
+
context: { jose, cookies }
|
|
1010
|
+
} = ctx;
|
|
1011
|
+
try {
|
|
1012
|
+
const session = getCookie(request, cookies.sessionToken.name);
|
|
1013
|
+
const decoded = await jose.decodeJWT(session);
|
|
1014
|
+
const { exp, iat, jti, nbf, ...user } = decoded;
|
|
1015
|
+
const headers = new Headers(cacheControl);
|
|
1016
|
+
return Response.json({ user, expires: toISOString(exp * 1e3) }, { headers });
|
|
1017
|
+
} catch (error) {
|
|
1018
|
+
const headers = new import_router4.HeadersBuilder(cacheControl).setCookie(cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
|
|
1019
|
+
return Response.json({ authenticated: false, message: "Unauthorized" }, { status: 401, headers });
|
|
1020
|
+
}
|
|
1021
|
+
});
|
|
990
1022
|
|
|
991
1023
|
// src/actions/signOut/signOut.ts
|
|
992
|
-
var import_zod3 = __toESM(require("zod"), 1)
|
|
993
|
-
var import_router5 = require("@aura-stack/router")
|
|
1024
|
+
var import_zod3 = __toESM(require("zod"), 1);
|
|
1025
|
+
var import_router5 = require("@aura-stack/router");
|
|
994
1026
|
var config = (0, import_router5.createEndpointConfig)({
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
})
|
|
1027
|
+
schemas: {
|
|
1028
|
+
searchParams: import_zod3.default.object({
|
|
1029
|
+
token_type_hint: import_zod3.default.literal("session_token"),
|
|
1030
|
+
redirectTo: import_zod3.default.string().optional()
|
|
1031
|
+
})
|
|
1032
|
+
}
|
|
1033
|
+
});
|
|
1002
1034
|
var signOutAction = (0, import_router5.createEndpoint)(
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
responseHeaders.append("Location", location)
|
|
1039
|
-
return Response.json(
|
|
1040
|
-
{ message: "Signed out successfully" },
|
|
1041
|
-
{ status: import_router5.statusCode.ACCEPTED, headers: responseHeaders }
|
|
1042
|
-
)
|
|
1043
|
-
} catch (error) {
|
|
1044
|
-
if (error instanceof InvalidCsrfTokenError) {
|
|
1045
|
-
return AuraResponse.json(
|
|
1046
|
-
{
|
|
1047
|
-
error: "invalid_csrf_token",
|
|
1048
|
-
error_description: "The provided CSRF token is invalid or has expired",
|
|
1049
|
-
},
|
|
1050
|
-
{ status: import_router5.statusCode.UNAUTHORIZED }
|
|
1051
|
-
)
|
|
1052
|
-
}
|
|
1053
|
-
if (error instanceof InvalidRedirectToError) {
|
|
1054
|
-
const { type, message } = error
|
|
1055
|
-
return AuraResponse.json(
|
|
1056
|
-
{
|
|
1057
|
-
error: type,
|
|
1058
|
-
error_description: message,
|
|
1059
|
-
},
|
|
1060
|
-
{ status: import_router5.statusCode.BAD_REQUEST }
|
|
1061
|
-
)
|
|
1062
|
-
}
|
|
1063
|
-
return AuraResponse.json(
|
|
1064
|
-
{
|
|
1065
|
-
error: "invalid_session_token",
|
|
1066
|
-
error_description: "The provided sessionToken is invalid or has already expired",
|
|
1067
|
-
},
|
|
1068
|
-
{ status: import_router5.statusCode.UNAUTHORIZED }
|
|
1069
|
-
)
|
|
1070
|
-
}
|
|
1071
|
-
},
|
|
1072
|
-
config
|
|
1073
|
-
)
|
|
1035
|
+
"POST",
|
|
1036
|
+
"/signOut",
|
|
1037
|
+
async (ctx) => {
|
|
1038
|
+
const {
|
|
1039
|
+
request,
|
|
1040
|
+
headers,
|
|
1041
|
+
searchParams: { redirectTo },
|
|
1042
|
+
context: { jose, cookies }
|
|
1043
|
+
} = ctx;
|
|
1044
|
+
const session = headers.getCookie(cookies.sessionToken.name);
|
|
1045
|
+
const csrfToken = headers.getCookie(cookies.csrfToken.name);
|
|
1046
|
+
const header = headers.getHeader("X-CSRF-Token");
|
|
1047
|
+
if (!session) {
|
|
1048
|
+
throw new AuthSecurityError("SESSION_TOKEN_MISSING", "The sessionToken is missing.");
|
|
1049
|
+
}
|
|
1050
|
+
if (!csrfToken) {
|
|
1051
|
+
throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF token is missing.");
|
|
1052
|
+
}
|
|
1053
|
+
if (!header) {
|
|
1054
|
+
throw new AuthSecurityError("CSRF_TOKEN_MISSING", "The CSRF header is missing.");
|
|
1055
|
+
}
|
|
1056
|
+
await verifyCSRF(jose, csrfToken, header);
|
|
1057
|
+
await jose.decodeJWT(session);
|
|
1058
|
+
const normalizedOriginPath = getNormalizedOriginPath(request.url);
|
|
1059
|
+
const location = createRedirectTo(
|
|
1060
|
+
new Request(normalizedOriginPath, {
|
|
1061
|
+
headers: headers.toHeaders()
|
|
1062
|
+
}),
|
|
1063
|
+
redirectTo
|
|
1064
|
+
);
|
|
1065
|
+
const headersList = new import_router5.HeadersBuilder(cacheControl).setHeader("Location", location).setCookie(cookies.csrfToken.name, "", expiredCookieAttributes).setCookie(cookies.sessionToken.name, "", expiredCookieAttributes).toHeaders();
|
|
1066
|
+
return Response.json({ message: "Signed out successfully" }, { status: import_router5.statusCode.ACCEPTED, headers: headersList });
|
|
1067
|
+
},
|
|
1068
|
+
config
|
|
1069
|
+
);
|
|
1074
1070
|
|
|
1075
1071
|
// src/actions/csrfToken/csrfToken.ts
|
|
1076
|
-
var import_router6 = require("@aura-stack/router")
|
|
1072
|
+
var import_router6 = require("@aura-stack/router");
|
|
1073
|
+
var getCSRFToken = (request, cookieName) => {
|
|
1074
|
+
try {
|
|
1075
|
+
return getCookie(request, cookieName);
|
|
1076
|
+
} catch {
|
|
1077
|
+
return void 0;
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1077
1080
|
var csrfTokenAction = (0, import_router6.createEndpoint)("GET", "/csrfToken", async (ctx) => {
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
})
|
|
1081
|
+
const {
|
|
1082
|
+
request,
|
|
1083
|
+
context: { jose, cookies }
|
|
1084
|
+
} = ctx;
|
|
1085
|
+
const token = getCSRFToken(request, cookies.csrfToken.name);
|
|
1086
|
+
const csrfToken = await createCSRF(jose, token);
|
|
1087
|
+
const headers = new Headers(cacheControl);
|
|
1088
|
+
headers.append("Set-Cookie", setCookie(cookies.csrfToken.name, csrfToken, cookies.csrfToken.attributes));
|
|
1089
|
+
return Response.json({ csrfToken }, { headers });
|
|
1090
|
+
});
|
|
1089
1091
|
|
|
1090
1092
|
// src/index.ts
|
|
1091
1093
|
var createInternalConfig = (authConfig) => {
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
}
|
|
1094
|
+
const useSecure = authConfig?.trustedProxyHeaders ?? false;
|
|
1095
|
+
return {
|
|
1096
|
+
basePath: authConfig?.basePath ?? "/auth",
|
|
1097
|
+
onError: onErrorHandler,
|
|
1098
|
+
context: {
|
|
1099
|
+
oauth: createBuiltInOAuthProviders(authConfig?.oauth),
|
|
1100
|
+
cookies: createCookieStore(useSecure, authConfig?.cookies?.prefix, authConfig?.cookies?.overrides ?? {}),
|
|
1101
|
+
jose: createJoseInstance(authConfig?.secret),
|
|
1102
|
+
secret: authConfig?.secret,
|
|
1103
|
+
basePath: authConfig?.basePath ?? "/auth",
|
|
1104
|
+
trustedProxyHeaders: useSecure
|
|
1105
|
+
},
|
|
1106
|
+
middlewares: [
|
|
1107
|
+
(ctx) => {
|
|
1108
|
+
const useSecure2 = useSecureCookies(ctx.request, ctx.context.trustedProxyHeaders);
|
|
1109
|
+
const cookies = createCookieStore(useSecure2, authConfig?.cookies?.prefix, authConfig?.cookies?.overrides ?? {});
|
|
1110
|
+
ctx.context.cookies = cookies;
|
|
1111
|
+
return ctx;
|
|
1112
|
+
}
|
|
1113
|
+
]
|
|
1114
|
+
};
|
|
1115
|
+
};
|
|
1104
1116
|
var createAuth = (authConfig) => {
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
)
|
|
1116
|
-
return {
|
|
1117
|
-
handlers: router,
|
|
1118
|
-
jose: config2.context.jose,
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1117
|
+
const config2 = createInternalConfig(authConfig);
|
|
1118
|
+
const router = (0, import_router7.createRouter)(
|
|
1119
|
+
[signInAction(config2.context.oauth), callbackAction(config2.context.oauth), sessionAction, signOutAction, csrfTokenAction],
|
|
1120
|
+
config2
|
|
1121
|
+
);
|
|
1122
|
+
return {
|
|
1123
|
+
handlers: router,
|
|
1124
|
+
jose: config2.context.jose
|
|
1125
|
+
};
|
|
1126
|
+
};
|
|
1121
1127
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1122
|
-
0 &&
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
})
|
|
1128
|
+
0 && (module.exports = {
|
|
1129
|
+
createAuth
|
|
1130
|
+
});
|