@aura-stack/auth 0.1.0-rc.7 → 0.1.0-rc.8
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
|
@@ -1,469 +1,496 @@
|
|
|
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/signIn/signIn.ts
|
|
31
|
-
var signIn_exports = {}
|
|
33
|
+
var signIn_exports = {}
|
|
32
34
|
__export(signIn_exports, {
|
|
33
|
-
|
|
34
|
-
})
|
|
35
|
-
module.exports = __toCommonJS(signIn_exports)
|
|
36
|
-
var import_zod = __toESM(require("zod"), 1)
|
|
37
|
-
var import_router2 = require("@aura-stack/router")
|
|
35
|
+
signInAction: () => signInAction,
|
|
36
|
+
})
|
|
37
|
+
module.exports = __toCommonJS(signIn_exports)
|
|
38
|
+
var import_zod = __toESM(require("zod"), 1)
|
|
39
|
+
var import_router2 = require("@aura-stack/router")
|
|
38
40
|
|
|
39
41
|
// src/response.ts
|
|
40
42
|
var AuraResponse = class extends Response {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
43
|
+
static json(body, init) {
|
|
44
|
+
return Response.json(body, init)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
45
47
|
|
|
46
48
|
// src/secure.ts
|
|
47
|
-
var import_node_crypto = __toESM(require("crypto"), 1)
|
|
49
|
+
var import_node_crypto = __toESM(require("crypto"), 1)
|
|
48
50
|
|
|
49
51
|
// src/utils.ts
|
|
50
|
-
var import_router = require("@aura-stack/router")
|
|
52
|
+
var import_router = require("@aura-stack/router")
|
|
51
53
|
|
|
52
54
|
// src/error.ts
|
|
53
55
|
var AuthError = class extends Error {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
56
|
+
constructor(type, message) {
|
|
57
|
+
super(message)
|
|
58
|
+
this.type = type
|
|
59
|
+
this.name = "AuthError"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
60
62
|
var InvalidRedirectToError = class extends AuthError {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
63
|
+
constructor(message = "The redirectTo parameter does not match the hosted origin.") {
|
|
64
|
+
super("invalid_redirect_to", message)
|
|
65
|
+
this.name = "InvalidRedirectToError"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
66
68
|
var isAuthError = (error) => {
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
+
return error instanceof AuthError
|
|
70
|
+
}
|
|
69
71
|
var ERROR_RESPONSE = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
72
|
+
AUTHORIZATION: {
|
|
73
|
+
INVALID_REQUEST: "invalid_request",
|
|
74
|
+
UNAUTHORIZED_CLIENT: "unauthorized_client",
|
|
75
|
+
ACCESS_DENIED: "access_denied",
|
|
76
|
+
UNSUPPORTED_RESPONSE_TYPE: "unsupported_response_type",
|
|
77
|
+
INVALID_SCOPE: "invalid_scope",
|
|
78
|
+
SERVER_ERROR: "server_error",
|
|
79
|
+
TEMPORARILY_UNAVAILABLE: "temporarily_unavailable",
|
|
80
|
+
},
|
|
81
|
+
ACCESS_TOKEN: {
|
|
82
|
+
INVALID_REQUEST: "invalid_request",
|
|
83
|
+
INVALID_CLIENT: "invalid_client",
|
|
84
|
+
INVALID_GRANT: "invalid_grant",
|
|
85
|
+
UNAUTHORIZED_CLIENT: "unauthorized_client",
|
|
86
|
+
UNSUPPORTED_GRANT_TYPE: "unsupported_grant_type",
|
|
87
|
+
INVALID_SCOPE: "invalid_scope",
|
|
88
|
+
},
|
|
89
|
+
}
|
|
88
90
|
|
|
89
91
|
// src/utils.ts
|
|
90
92
|
var toSnakeCase = (str) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
return str
|
|
94
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
95
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
|
|
96
|
+
.toLowerCase()
|
|
97
|
+
.replace(/^_+/, "")
|
|
98
|
+
}
|
|
93
99
|
var toUpperCase = (str) => {
|
|
94
|
-
|
|
95
|
-
}
|
|
100
|
+
return str.toUpperCase()
|
|
101
|
+
}
|
|
96
102
|
var toCastCase = (obj, type = "snake") => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
103
|
+
return Object.entries(obj).reduce((previous, [key, value]) => {
|
|
104
|
+
const newKey = type === "snake" ? toSnakeCase(key) : toUpperCase(key)
|
|
105
|
+
return { ...previous, [newKey]: value }
|
|
106
|
+
}, {})
|
|
107
|
+
}
|
|
102
108
|
var equals = (a, b) => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
109
|
+
if (a === null || b === null || a === void 0 || b === void 0) return false
|
|
110
|
+
return a === b
|
|
111
|
+
}
|
|
106
112
|
var sanitizeURL = (url2) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
113
|
+
try {
|
|
114
|
+
let decodedURL = decodeURIComponent(url2).trim()
|
|
115
|
+
const protocolMatch = decodedURL.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)/)
|
|
116
|
+
let protocol = ""
|
|
117
|
+
let rest = decodedURL
|
|
118
|
+
if (protocolMatch) {
|
|
119
|
+
protocol = protocolMatch[1]
|
|
120
|
+
rest = decodedURL.slice(protocol.length)
|
|
121
|
+
const slashIndex = rest.indexOf("/")
|
|
122
|
+
if (slashIndex === -1) {
|
|
123
|
+
return protocol + rest
|
|
124
|
+
}
|
|
125
|
+
const domain = rest.slice(0, slashIndex)
|
|
126
|
+
let path = rest
|
|
127
|
+
.slice(slashIndex)
|
|
128
|
+
.replace(/\/\.\.\//g, "/")
|
|
129
|
+
.replace(/\/\.\.$/, "")
|
|
130
|
+
.replace(/\.{2,}/g, "")
|
|
131
|
+
.replace(/\/{2,}/g, "/")
|
|
132
|
+
if (path !== "/" && path.endsWith("/")) {
|
|
133
|
+
path = path.replace(/\/+$/, "/")
|
|
134
|
+
} else if (path !== "/") {
|
|
135
|
+
path = path.replace(/\/+$/, "")
|
|
136
|
+
}
|
|
137
|
+
return protocol + domain + path
|
|
138
|
+
}
|
|
139
|
+
let sanitized = decodedURL
|
|
140
|
+
.replace(/\/\.\.\//g, "/")
|
|
141
|
+
.replace(/\/\.\.$/, "")
|
|
142
|
+
.replace(/\.{2,}/g, "")
|
|
143
|
+
.replace(/\/{2,}/g, "/")
|
|
144
|
+
if (sanitized !== "/" && sanitized.endsWith("/")) {
|
|
145
|
+
sanitized = sanitized.replace(/\/+$/, "/")
|
|
146
|
+
} else if (sanitized !== "/") {
|
|
147
|
+
sanitized = sanitized.replace(/\/+$/, "")
|
|
148
|
+
}
|
|
149
|
+
return sanitized
|
|
150
|
+
} catch {
|
|
151
|
+
return url2.trim()
|
|
133
152
|
}
|
|
134
|
-
|
|
135
|
-
} catch {
|
|
136
|
-
return url2.trim();
|
|
137
|
-
}
|
|
138
|
-
};
|
|
153
|
+
}
|
|
139
154
|
var getNormalizedOriginPath = (path) => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
155
|
+
try {
|
|
156
|
+
const url2 = new URL(path)
|
|
157
|
+
url2.hash = ""
|
|
158
|
+
url2.search = ""
|
|
159
|
+
return `${url2.origin}${url2.pathname}`
|
|
160
|
+
} catch {
|
|
161
|
+
return sanitizeURL(path)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
149
164
|
|
|
150
165
|
// src/secure.ts
|
|
151
166
|
var generateSecure = (length = 32) => {
|
|
152
|
-
|
|
153
|
-
}
|
|
167
|
+
return import_node_crypto.default.randomBytes(length).toString("base64url")
|
|
168
|
+
}
|
|
154
169
|
var createHash = (data, base = "hex") => {
|
|
155
|
-
|
|
156
|
-
}
|
|
170
|
+
return import_node_crypto.default.createHash("sha256").update(data).digest().toString(base)
|
|
171
|
+
}
|
|
157
172
|
var createPKCE = async (verifier) => {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
173
|
+
const codeVerifier = verifier ?? generateSecure(86)
|
|
174
|
+
const codeChallenge = createHash(codeVerifier, "base64url")
|
|
175
|
+
return { codeVerifier, codeChallenge, method: "S256" }
|
|
176
|
+
}
|
|
162
177
|
|
|
163
178
|
// src/cookie.ts
|
|
164
|
-
var import_cookie = require("cookie")
|
|
179
|
+
var import_cookie = require("cookie")
|
|
165
180
|
|
|
166
181
|
// src/assert.ts
|
|
167
182
|
var isValidURL = (value) => {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
183
|
+
if (value.includes("\r\n") || value.includes("\n") || value.includes("\r")) return false
|
|
184
|
+
const regex =
|
|
185
|
+
/^https?:\/\/(?:[a-zA-Z0-9._-]+|localhost|\[[0-9a-fA-F:]+\])(?::\d{1,5})?(?:\/[a-zA-Z0-9._~!$&'()*+,;=:@-]*)*\/?$/
|
|
186
|
+
return regex.test(value)
|
|
187
|
+
}
|
|
172
188
|
|
|
173
189
|
// src/cookie.ts
|
|
174
|
-
var import_cookie2 = require("cookie")
|
|
175
|
-
var COOKIE_NAME = "aura-auth"
|
|
190
|
+
var import_cookie2 = require("cookie")
|
|
191
|
+
var COOKIE_NAME = "aura-auth"
|
|
176
192
|
var defaultCookieOptions = {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
193
|
+
httpOnly: true,
|
|
194
|
+
sameSite: "lax",
|
|
195
|
+
path: "/",
|
|
196
|
+
maxAge: 60 * 60 * 24 * 15,
|
|
197
|
+
}
|
|
182
198
|
var defaultStandardCookieConfig = {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
199
|
+
secure: false,
|
|
200
|
+
httpOnly: true,
|
|
201
|
+
prefix: "",
|
|
202
|
+
}
|
|
187
203
|
var defaultSecureCookieConfig = {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
204
|
+
secure: true,
|
|
205
|
+
prefix: "__Secure-",
|
|
206
|
+
}
|
|
191
207
|
var defaultHostCookieConfig = {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
208
|
+
secure: true,
|
|
209
|
+
prefix: "__Host-",
|
|
210
|
+
path: "/",
|
|
211
|
+
domain: void 0,
|
|
212
|
+
}
|
|
197
213
|
var expiredCookieOptions = {
|
|
198
|
-
...defaultCookieOptions,
|
|
199
|
-
expires: /* @__PURE__ */ new Date(0),
|
|
200
|
-
maxAge: 0
|
|
201
|
-
};
|
|
202
|
-
var defineDefaultCookieOptions = (options2) => {
|
|
203
|
-
return {
|
|
204
|
-
name: options2?.name ?? COOKIE_NAME,
|
|
205
|
-
prefix: options2?.prefix ?? (options2?.secure ? "__Secure-" : ""),
|
|
206
214
|
...defaultCookieOptions,
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
215
|
+
expires: /* @__PURE__ */ new Date(0),
|
|
216
|
+
maxAge: 0,
|
|
217
|
+
}
|
|
218
|
+
var defineDefaultCookieOptions = (options2) => {
|
|
219
|
+
return {
|
|
220
|
+
name: options2?.name ?? COOKIE_NAME,
|
|
221
|
+
prefix: options2?.prefix ?? (options2?.secure ? "__Secure-" : ""),
|
|
222
|
+
...defaultCookieOptions,
|
|
223
|
+
...options2,
|
|
224
|
+
}
|
|
225
|
+
}
|
|
210
226
|
var setCookie = (cookieName, value, options2) => {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
227
|
+
const { prefix, name } = defineDefaultCookieOptions(options2)
|
|
228
|
+
const cookieNameWithPrefix = `${prefix}${name}.${cookieName}`
|
|
229
|
+
return (0, import_cookie.serialize)(cookieNameWithPrefix, value, {
|
|
230
|
+
...defaultCookieOptions,
|
|
231
|
+
...options2,
|
|
232
|
+
})
|
|
233
|
+
}
|
|
218
234
|
var secureCookieOptions = (request, cookieOptions, trustedProxyHeaders) => {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (!isSecure) {
|
|
230
|
-
const options2 = cookieOptions.options;
|
|
231
|
-
if (options2?.secure) {
|
|
232
|
-
console.warn(
|
|
233
|
-
"[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
|
|
234
|
-
);
|
|
235
|
+
const name = cookieOptions.name ?? COOKIE_NAME
|
|
236
|
+
const isSecure = trustedProxyHeaders
|
|
237
|
+
? request.url.startsWith("https://") ||
|
|
238
|
+
request.headers.get("X-Forwarded-Proto") === "https" ||
|
|
239
|
+
request.headers.get("Forwarded")?.includes("proto=https")
|
|
240
|
+
: request.url.startsWith("https://")
|
|
241
|
+
if (!cookieOptions.options?.httpOnly) {
|
|
242
|
+
console.warn(
|
|
243
|
+
"[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
|
|
244
|
+
)
|
|
235
245
|
}
|
|
236
|
-
if (
|
|
237
|
-
|
|
246
|
+
if (cookieOptions.options?.domain === "*") {
|
|
247
|
+
console.warn("[WARNING]: Cookie 'Domain' is set to '*', which is insecure. Avoid wildcard domains.")
|
|
238
248
|
}
|
|
239
|
-
if (
|
|
240
|
-
|
|
249
|
+
if (!isSecure) {
|
|
250
|
+
const options2 = cookieOptions.options
|
|
251
|
+
if (options2?.secure) {
|
|
252
|
+
console.warn(
|
|
253
|
+
"[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
if (options2?.sameSite == "none") {
|
|
257
|
+
console.warn("[WARNING]: SameSite=None without a secure connection can be blocked by browsers.")
|
|
258
|
+
}
|
|
259
|
+
if (process.env.NODE_ENV === "production") {
|
|
260
|
+
console.warn("[WARNING]: In production, ensure cookies are served over HTTPS to maintain security.")
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
...defaultCookieOptions,
|
|
264
|
+
...cookieOptions.options,
|
|
265
|
+
sameSite: options2?.sameSite === "none" ? "lax" : (options2?.sameSite ?? "lax"),
|
|
266
|
+
...defaultStandardCookieConfig,
|
|
267
|
+
name,
|
|
268
|
+
}
|
|
241
269
|
}
|
|
242
|
-
return
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
...defaultCookieOptions,
|
|
252
|
-
...cookieOptions.options,
|
|
253
|
-
...defaultHostCookieConfig,
|
|
254
|
-
name
|
|
255
|
-
} : { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name };
|
|
256
|
-
};
|
|
270
|
+
return cookieOptions.strategy === "host"
|
|
271
|
+
? {
|
|
272
|
+
...defaultCookieOptions,
|
|
273
|
+
...cookieOptions.options,
|
|
274
|
+
...defaultHostCookieConfig,
|
|
275
|
+
name,
|
|
276
|
+
}
|
|
277
|
+
: { ...defaultCookieOptions, ...cookieOptions.options, ...defaultSecureCookieConfig, name }
|
|
278
|
+
}
|
|
257
279
|
var oauthCookie = (options2) => {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
280
|
+
return {
|
|
281
|
+
...options2,
|
|
282
|
+
secure: options2.secure,
|
|
283
|
+
httpOnly: options2.httpOnly,
|
|
284
|
+
maxAge: 5 * 60,
|
|
285
|
+
expires: new Date(Date.now() + 5 * 60 * 1e3),
|
|
286
|
+
}
|
|
287
|
+
}
|
|
266
288
|
|
|
267
289
|
// src/schemas.ts
|
|
268
|
-
var import_v4 = require("zod/v4")
|
|
290
|
+
var import_v4 = require("zod/v4")
|
|
269
291
|
var OAuthProviderConfigSchema = (0, import_v4.object)({
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
})
|
|
292
|
+
authorizeURL: (0, import_v4.url)(),
|
|
293
|
+
accessToken: (0, import_v4.url)(),
|
|
294
|
+
scope: (0, import_v4.string)().optional(),
|
|
295
|
+
userInfo: (0, import_v4.url)(),
|
|
296
|
+
responseType: (0, import_v4.enum)(["code", "token", "id_token"]),
|
|
297
|
+
clientId: (0, import_v4.string)(),
|
|
298
|
+
clientSecret: (0, import_v4.string)(),
|
|
299
|
+
})
|
|
278
300
|
var OAuthAuthorization = OAuthProviderConfigSchema.extend({
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
})
|
|
301
|
+
redirectURI: (0, import_v4.string)(),
|
|
302
|
+
state: (0, import_v4.string)(),
|
|
303
|
+
codeChallenge: (0, import_v4.string)(),
|
|
304
|
+
codeChallengeMethod: (0, import_v4.enum)(["plain", "S256"]),
|
|
305
|
+
})
|
|
284
306
|
var OAuthAuthorizationResponse = (0, import_v4.object)({
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
})
|
|
307
|
+
state: (0, import_v4.string)(),
|
|
308
|
+
code: (0, import_v4.string)(),
|
|
309
|
+
})
|
|
288
310
|
var OAuthAuthorizationErrorResponse = (0, import_v4.object)({
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
})
|
|
311
|
+
error: (0, import_v4.enum)([
|
|
312
|
+
"invalid_request",
|
|
313
|
+
"unauthorized_client",
|
|
314
|
+
"access_denied",
|
|
315
|
+
"unsupported_response_type",
|
|
316
|
+
"invalid_scope",
|
|
317
|
+
"server_error",
|
|
318
|
+
"temporarily_unavailable",
|
|
319
|
+
]),
|
|
320
|
+
error_description: (0, import_v4.string)().optional(),
|
|
321
|
+
error_uri: (0, import_v4.string)().optional(),
|
|
322
|
+
state: (0, import_v4.string)(),
|
|
323
|
+
})
|
|
302
324
|
var OAuthAccessToken = OAuthProviderConfigSchema.extend({
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
})
|
|
325
|
+
redirectURI: (0, import_v4.string)(),
|
|
326
|
+
code: (0, import_v4.string)(),
|
|
327
|
+
codeVerifier: (0, import_v4.string)().min(43).max(128),
|
|
328
|
+
})
|
|
307
329
|
var OAuthAccessTokenResponse = (0, import_v4.object)({
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
})
|
|
330
|
+
access_token: (0, import_v4.string)(),
|
|
331
|
+
token_type: (0, import_v4.string)(),
|
|
332
|
+
expires_in: (0, import_v4.number)().optional(),
|
|
333
|
+
refresh_token: (0, import_v4.string)().optional(),
|
|
334
|
+
scope: (0, import_v4.string)().optional(),
|
|
335
|
+
})
|
|
314
336
|
var OAuthAccessTokenErrorResponse = (0, import_v4.object)({
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
})
|
|
337
|
+
error: (0, import_v4.enum)([
|
|
338
|
+
"invalid_request",
|
|
339
|
+
"invalid_client",
|
|
340
|
+
"invalid_grant",
|
|
341
|
+
"unauthorized_client",
|
|
342
|
+
"unsupported_grant_type",
|
|
343
|
+
"invalid_scope",
|
|
344
|
+
]),
|
|
345
|
+
error_description: (0, import_v4.string)().optional(),
|
|
346
|
+
error_uri: (0, import_v4.string)().optional(),
|
|
347
|
+
})
|
|
326
348
|
var OAuthErrorResponse = (0, import_v4.object)({
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
})
|
|
349
|
+
error: (0, import_v4.string)(),
|
|
350
|
+
error_description: (0, import_v4.string)().optional(),
|
|
351
|
+
})
|
|
330
352
|
|
|
331
353
|
// src/actions/signIn/authorization.ts
|
|
332
354
|
var createAuthorizationURL = (oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod) => {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
355
|
+
const parsed = OAuthAuthorization.safeParse({ ...oauthConfig, redirectURI, state, codeChallenge, codeChallengeMethod })
|
|
356
|
+
if (!parsed.success) {
|
|
357
|
+
throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR, "Invalid OAuth configuration")
|
|
358
|
+
}
|
|
359
|
+
const { authorizeURL, ...options2 } = parsed.data
|
|
360
|
+
const { userInfo, accessToken, clientSecret, ...required } = options2
|
|
361
|
+
const searchParams = new URLSearchParams(toCastCase(required))
|
|
362
|
+
return `${authorizeURL}?${searchParams}`
|
|
363
|
+
}
|
|
342
364
|
var getOriginURL = (request, trustedProxyHeaders) => {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
365
|
+
const headers = request.headers
|
|
366
|
+
if (trustedProxyHeaders) {
|
|
367
|
+
const protocol = headers.get("X-Forwarded-Proto") ?? headers.get("Forwarded")?.match(/proto=([^;]+)/i)?.[1] ?? "http"
|
|
368
|
+
const host =
|
|
369
|
+
headers.get("X-Forwarded-Host") ??
|
|
370
|
+
headers.get("Host") ??
|
|
371
|
+
headers.get("Forwarded")?.match(/host=([^;]+)/i)?.[1] ??
|
|
372
|
+
null
|
|
373
|
+
return new URL(`${protocol}://${host}${getNormalizedOriginPath(new URL(request.url).pathname)}`)
|
|
374
|
+
} else {
|
|
375
|
+
return new URL(getNormalizedOriginPath(request.url))
|
|
376
|
+
}
|
|
377
|
+
}
|
|
352
378
|
var createRedirectURI = (request, oauth, basePath, trustedProxyHeaders) => {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
379
|
+
const url2 = getOriginURL(request, trustedProxyHeaders)
|
|
380
|
+
return `${url2.origin}${basePath}/callback/${oauth}`
|
|
381
|
+
}
|
|
356
382
|
var createRedirectTo = (request, redirectTo, trustedProxyHeaders) => {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
383
|
+
try {
|
|
384
|
+
const headers = request.headers
|
|
385
|
+
const origin = headers.get("Origin")
|
|
386
|
+
const referer = headers.get("Referer")
|
|
387
|
+
let hostedURL = getOriginURL(request, trustedProxyHeaders)
|
|
388
|
+
if (redirectTo) {
|
|
389
|
+
if (redirectTo.startsWith("/")) {
|
|
390
|
+
return sanitizeURL(redirectTo)
|
|
391
|
+
}
|
|
392
|
+
const redirectToURL = new URL(sanitizeURL(getNormalizedOriginPath(redirectTo)))
|
|
393
|
+
if (!isValidURL(redirectTo) || !equals(redirectToURL.origin, hostedURL.origin)) {
|
|
394
|
+
throw new InvalidRedirectToError()
|
|
395
|
+
}
|
|
396
|
+
return sanitizeURL(redirectToURL.pathname)
|
|
397
|
+
}
|
|
398
|
+
if (referer) {
|
|
399
|
+
const refererURL = new URL(sanitizeURL(referer))
|
|
400
|
+
if (!isValidURL(referer) || !equals(refererURL.origin, hostedURL.origin)) {
|
|
401
|
+
throw new AuthError(
|
|
402
|
+
ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST,
|
|
403
|
+
"The referer of the request does not match the hosted origin."
|
|
404
|
+
)
|
|
405
|
+
}
|
|
406
|
+
return sanitizeURL(refererURL.pathname)
|
|
407
|
+
}
|
|
408
|
+
if (origin) {
|
|
409
|
+
const originURL = new URL(sanitizeURL(getNormalizedOriginPath(origin)))
|
|
410
|
+
if (!isValidURL(origin) || !equals(originURL.origin, hostedURL.origin)) {
|
|
411
|
+
throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).")
|
|
412
|
+
}
|
|
413
|
+
return sanitizeURL(originURL.pathname)
|
|
414
|
+
}
|
|
415
|
+
return "/"
|
|
416
|
+
} catch (error) {
|
|
417
|
+
if (isAuthError(error)) {
|
|
418
|
+
throw error
|
|
419
|
+
}
|
|
420
|
+
throw new AuthError(ERROR_RESPONSE.AUTHORIZATION.INVALID_REQUEST, "Invalid origin (potential CSRF).")
|
|
393
421
|
}
|
|
394
|
-
|
|
395
|
-
}
|
|
396
|
-
};
|
|
422
|
+
}
|
|
397
423
|
|
|
398
424
|
// src/actions/signIn/signIn.ts
|
|
399
425
|
var signInConfig = (oauth) => {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}
|
|
426
|
+
return (0, import_router2.createEndpointConfig)("/signIn/:oauth", {
|
|
427
|
+
schemas: {
|
|
428
|
+
params: import_zod.default.object({
|
|
429
|
+
oauth: import_zod.default.enum(Object.keys(oauth)),
|
|
430
|
+
redirectTo: import_zod.default.string().optional(),
|
|
431
|
+
}),
|
|
432
|
+
},
|
|
433
|
+
})
|
|
434
|
+
}
|
|
409
435
|
var signInAction = (oauth) => {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
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
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
}
|
|
436
|
+
return (0, import_router2.createEndpoint)(
|
|
437
|
+
"GET",
|
|
438
|
+
"/signIn/:oauth",
|
|
439
|
+
async (ctx) => {
|
|
440
|
+
const {
|
|
441
|
+
request,
|
|
442
|
+
params: { oauth: oauth2, redirectTo },
|
|
443
|
+
context: { oauth: providers, cookies, trustedProxyHeaders, basePath },
|
|
444
|
+
} = ctx
|
|
445
|
+
try {
|
|
446
|
+
const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders)
|
|
447
|
+
const state = generateSecure()
|
|
448
|
+
const redirectURI = createRedirectURI(request, oauth2, basePath, trustedProxyHeaders)
|
|
449
|
+
const stateCookie = setCookie("state", state, oauthCookie(cookieOptions))
|
|
450
|
+
const redirectURICookie = setCookie("redirect_uri", redirectURI, oauthCookie(cookieOptions))
|
|
451
|
+
const redirectToCookie = setCookie(
|
|
452
|
+
"redirect_to",
|
|
453
|
+
createRedirectTo(request, redirectTo, trustedProxyHeaders),
|
|
454
|
+
oauthCookie(cookieOptions)
|
|
455
|
+
)
|
|
456
|
+
const { codeVerifier, codeChallenge, method } = await createPKCE()
|
|
457
|
+
const codeVerifierCookie = setCookie("code_verifier", codeVerifier, oauthCookie(cookieOptions))
|
|
458
|
+
const authorization = createAuthorizationURL(providers[oauth2], redirectURI, state, codeChallenge, method)
|
|
459
|
+
const headers = new Headers()
|
|
460
|
+
headers.set("Location", authorization)
|
|
461
|
+
headers.append("Set-Cookie", stateCookie)
|
|
462
|
+
headers.append("Set-Cookie", redirectURICookie)
|
|
463
|
+
headers.append("Set-Cookie", redirectToCookie)
|
|
464
|
+
headers.append("Set-Cookie", codeVerifierCookie)
|
|
465
|
+
return Response.json(
|
|
466
|
+
{ oauth: oauth2 },
|
|
467
|
+
{
|
|
468
|
+
status: 302,
|
|
469
|
+
headers,
|
|
470
|
+
}
|
|
471
|
+
)
|
|
472
|
+
} catch (error) {
|
|
473
|
+
if (isAuthError(error)) {
|
|
474
|
+
const { type, message } = error
|
|
475
|
+
return AuraResponse.json(
|
|
476
|
+
{ error: type, error_description: message },
|
|
477
|
+
{ status: import_router2.statusCode.BAD_REQUEST }
|
|
478
|
+
)
|
|
479
|
+
}
|
|
480
|
+
return AuraResponse.json(
|
|
481
|
+
{
|
|
482
|
+
error: ERROR_RESPONSE.AUTHORIZATION.SERVER_ERROR,
|
|
483
|
+
error_description: "An unexpected error occurred",
|
|
484
|
+
},
|
|
485
|
+
{ status: import_router2.statusCode.INTERNAL_SERVER_ERROR }
|
|
486
|
+
)
|
|
487
|
+
}
|
|
488
|
+
},
|
|
489
|
+
signInConfig(oauth)
|
|
490
|
+
)
|
|
491
|
+
}
|
|
466
492
|
// Annotate the CommonJS export names for ESM import in node:
|
|
467
|
-
0 &&
|
|
468
|
-
|
|
469
|
-
|
|
493
|
+
0 &&
|
|
494
|
+
(module.exports = {
|
|
495
|
+
signInAction,
|
|
496
|
+
})
|