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