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