@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/chunk-EBPE35JT.js
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
// src/oauth/discord.ts
|
|
2
2
|
var discord = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
3
|
+
id: "discord",
|
|
4
|
+
name: "Discord",
|
|
5
|
+
authorizeURL: "https://discord.com/oauth2/authorize",
|
|
6
|
+
accessToken: "https://discord.com/api/oauth2/token",
|
|
7
|
+
userInfo: "https://discord.com/api/users/@me",
|
|
8
|
+
scope: "identify email",
|
|
9
|
+
responseType: "code",
|
|
10
|
+
profile(profile) {
|
|
11
|
+
let image = ""
|
|
12
|
+
if (profile.avatar === null) {
|
|
13
|
+
const index = profile.discriminator === "0" ? (BigInt(profile.id) >> 22n) % 6n : Number(profile.discriminator) % 5
|
|
14
|
+
image = `https://cdn.discordapp.com/embed/avatars/${index}.png`
|
|
15
|
+
} else {
|
|
16
|
+
const format = profile.avatar.startsWith("a_") ? "gif" : "png"
|
|
17
|
+
image = `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.${format}`
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
sub: profile.id,
|
|
21
|
+
// https://discord.com/developers/docs/change-log#display-names
|
|
22
|
+
name: profile.global_name ?? profile.username,
|
|
23
|
+
email: profile.email ?? "",
|
|
24
|
+
image,
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
export {
|
|
30
|
-
discord
|
|
31
|
-
};
|
|
29
|
+
export { discord }
|
package/dist/chunk-FIPU4MLT.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
// src/oauth/bitbucket.ts
|
|
2
2
|
var bitbucket = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
3
|
+
id: "bitbucket",
|
|
4
|
+
name: "Bitbucket",
|
|
5
|
+
authorizeURL: "https://bitbucket.org/site/oauth2/authorize",
|
|
6
|
+
accessToken: "https://bitbucket.org/site/oauth2/access_token",
|
|
7
|
+
userInfo: "https://api.bitbucket.org/2.0/user",
|
|
8
|
+
scope: "account email",
|
|
9
|
+
responseType: "code",
|
|
10
|
+
profile(profile) {
|
|
11
|
+
return {
|
|
12
|
+
sub: profile.uuid ?? profile.account_id,
|
|
13
|
+
name: profile.display_name ?? profile.nickname,
|
|
14
|
+
image: profile.links.avatar.href,
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
18
|
|
|
19
|
-
export {
|
|
20
|
-
bitbucket
|
|
21
|
-
};
|
|
19
|
+
export { bitbucket }
|
package/dist/chunk-FJUDBLCP.js
CHANGED
|
@@ -1,59 +1,52 @@
|
|
|
1
1
|
// src/error.ts
|
|
2
2
|
var AuthError = class extends Error {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
3
|
+
constructor(type, message) {
|
|
4
|
+
super(message)
|
|
5
|
+
this.type = type
|
|
6
|
+
this.name = "AuthError"
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
9
|
var InvalidCsrfTokenError = class extends AuthError {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
10
|
+
constructor(message = "The provided CSRF token is invalid or has expired") {
|
|
11
|
+
super("invalid_csrf_token", message)
|
|
12
|
+
this.name = "InvalidCsrfTokenError"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
15
|
var InvalidRedirectToError = class extends AuthError {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
16
|
+
constructor(message = "The redirectTo parameter does not match the hosted origin.") {
|
|
17
|
+
super("invalid_redirect_to", message)
|
|
18
|
+
this.name = "InvalidRedirectToError"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
21
|
var isAuthError = (error) => {
|
|
22
|
-
|
|
23
|
-
}
|
|
22
|
+
return error instanceof AuthError
|
|
23
|
+
}
|
|
24
24
|
var throwAuthError = (error, message) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
if (error instanceof Error) {
|
|
26
|
+
if (isAuthError(error)) {
|
|
27
|
+
throw error
|
|
28
|
+
}
|
|
29
|
+
throw new AuthError("invalid_request", error.message ?? message)
|
|
28
30
|
}
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
};
|
|
31
|
+
}
|
|
32
32
|
var ERROR_RESPONSE = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
33
|
+
AUTHORIZATION: {
|
|
34
|
+
INVALID_REQUEST: "invalid_request",
|
|
35
|
+
UNAUTHORIZED_CLIENT: "unauthorized_client",
|
|
36
|
+
ACCESS_DENIED: "access_denied",
|
|
37
|
+
UNSUPPORTED_RESPONSE_TYPE: "unsupported_response_type",
|
|
38
|
+
INVALID_SCOPE: "invalid_scope",
|
|
39
|
+
SERVER_ERROR: "server_error",
|
|
40
|
+
TEMPORARILY_UNAVAILABLE: "temporarily_unavailable",
|
|
41
|
+
},
|
|
42
|
+
ACCESS_TOKEN: {
|
|
43
|
+
INVALID_REQUEST: "invalid_request",
|
|
44
|
+
INVALID_CLIENT: "invalid_client",
|
|
45
|
+
INVALID_GRANT: "invalid_grant",
|
|
46
|
+
UNAUTHORIZED_CLIENT: "unauthorized_client",
|
|
47
|
+
UNSUPPORTED_GRANT_TYPE: "unsupported_grant_type",
|
|
48
|
+
INVALID_SCOPE: "invalid_scope",
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
51
|
|
|
52
|
-
export {
|
|
53
|
-
AuthError,
|
|
54
|
-
InvalidCsrfTokenError,
|
|
55
|
-
InvalidRedirectToError,
|
|
56
|
-
isAuthError,
|
|
57
|
-
throwAuthError,
|
|
58
|
-
ERROR_RESPONSE
|
|
59
|
-
};
|
|
52
|
+
export { AuthError, InvalidCsrfTokenError, InvalidRedirectToError, isAuthError, throwAuthError, ERROR_RESPONSE }
|
package/dist/chunk-FKRDCWBF.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
// src/oauth/figma.ts
|
|
2
2
|
var figma = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
3
|
+
id: "figma",
|
|
4
|
+
name: "Figma",
|
|
5
|
+
authorizeURL: "https://www.figma.com/oauth",
|
|
6
|
+
accessToken: "https://api.figma.com/v1/oauth/token",
|
|
7
|
+
userInfo: "https://api.figma.com/v1/me",
|
|
8
|
+
scope: "current_user:read",
|
|
9
|
+
responseType: "code",
|
|
10
|
+
profile(profile) {
|
|
11
|
+
return {
|
|
12
|
+
sub: profile.id,
|
|
13
|
+
name: profile.handle,
|
|
14
|
+
email: profile.email,
|
|
15
|
+
image: profile.img_url,
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
export {
|
|
21
|
-
figma
|
|
22
|
-
};
|
|
20
|
+
export { figma }
|
package/dist/chunk-GZU3RBTB.js
CHANGED
|
@@ -1,62 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-256KIVJL.js";
|
|
4
|
-
import {
|
|
5
|
-
InvalidCsrfTokenError
|
|
6
|
-
} from "./chunk-FJUDBLCP.js";
|
|
1
|
+
import { equals } from "./chunk-256KIVJL.js"
|
|
2
|
+
import { InvalidCsrfTokenError } from "./chunk-FJUDBLCP.js"
|
|
7
3
|
|
|
8
4
|
// src/secure.ts
|
|
9
|
-
import crypto from "crypto"
|
|
5
|
+
import crypto from "crypto"
|
|
10
6
|
var generateSecure = (length = 32) => {
|
|
11
|
-
|
|
12
|
-
}
|
|
7
|
+
return crypto.randomBytes(length).toString("base64url")
|
|
8
|
+
}
|
|
13
9
|
var createHash = (data, base = "hex") => {
|
|
14
|
-
|
|
15
|
-
}
|
|
10
|
+
return crypto.createHash("sha256").update(data).digest().toString(base)
|
|
11
|
+
}
|
|
16
12
|
var createPKCE = async (verifier) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
13
|
+
const codeVerifier = verifier ?? generateSecure(86)
|
|
14
|
+
const codeChallenge = createHash(codeVerifier, "base64url")
|
|
15
|
+
return { codeVerifier, codeChallenge, method: "S256" }
|
|
16
|
+
}
|
|
21
17
|
var createCSRF = async (jose, csrfCookie) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
try {
|
|
19
|
+
const token = generateSecure(32)
|
|
20
|
+
if (csrfCookie) {
|
|
21
|
+
await jose.verifyJWS(csrfCookie)
|
|
22
|
+
return csrfCookie
|
|
23
|
+
}
|
|
24
|
+
return jose.signJWS({ token })
|
|
25
|
+
} catch {
|
|
26
|
+
const token = generateSecure(32)
|
|
27
|
+
return jose.signJWS({ token })
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
-
} catch {
|
|
30
|
-
const token = generateSecure(32);
|
|
31
|
-
return jose.signJWS({ token });
|
|
32
|
-
}
|
|
33
|
-
};
|
|
29
|
+
}
|
|
34
30
|
var verifyCSRF = async (jose, cookie, header) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
try {
|
|
32
|
+
const { token: cookieToken } = await jose.verifyJWS(cookie)
|
|
33
|
+
const { token: headerToken } = await jose.verifyJWS(header)
|
|
34
|
+
const cookieBuffer = Buffer.from(cookieToken)
|
|
35
|
+
const headerBuffer = Buffer.from(headerToken)
|
|
36
|
+
if (!equals(headerBuffer.length, cookieBuffer.length)) {
|
|
37
|
+
throw new InvalidCsrfTokenError()
|
|
38
|
+
}
|
|
39
|
+
if (!crypto.timingSafeEqual(cookieBuffer, headerBuffer)) {
|
|
40
|
+
throw new InvalidCsrfTokenError()
|
|
41
|
+
}
|
|
42
|
+
return true
|
|
43
|
+
} catch {
|
|
44
|
+
throw new InvalidCsrfTokenError()
|
|
42
45
|
}
|
|
43
|
-
|
|
44
|
-
throw new InvalidCsrfTokenError();
|
|
45
|
-
}
|
|
46
|
-
return true;
|
|
47
|
-
} catch {
|
|
48
|
-
throw new InvalidCsrfTokenError();
|
|
49
|
-
}
|
|
50
|
-
};
|
|
46
|
+
}
|
|
51
47
|
var createDerivedSalt = (secret) => {
|
|
52
|
-
|
|
53
|
-
}
|
|
48
|
+
return crypto.createHash("sha256").update(secret).update("aura-auth-salt").digest("hex")
|
|
49
|
+
}
|
|
54
50
|
|
|
55
|
-
export {
|
|
56
|
-
generateSecure,
|
|
57
|
-
createHash,
|
|
58
|
-
createPKCE,
|
|
59
|
-
createCSRF,
|
|
60
|
-
verifyCSRF,
|
|
61
|
-
createDerivedSalt
|
|
62
|
-
};
|
|
51
|
+
export { generateSecure, createHash, createPKCE, createCSRF, verifyCSRF, createDerivedSalt }
|
package/dist/chunk-HGJ4TXY4.js
CHANGED
|
@@ -1,137 +1,105 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
getCookie,
|
|
11
|
-
secureCookieOptions,
|
|
12
|
-
setCookie
|
|
13
|
-
} from "./chunk-ZV4BH47P.js";
|
|
14
|
-
import {
|
|
15
|
-
cacheControl
|
|
16
|
-
} from "./chunk-STHEPPUZ.js";
|
|
17
|
-
import {
|
|
18
|
-
createCSRF
|
|
19
|
-
} from "./chunk-GZU3RBTB.js";
|
|
20
|
-
import {
|
|
21
|
-
equals,
|
|
22
|
-
isValidRelativePath,
|
|
23
|
-
sanitizeURL
|
|
24
|
-
} from "./chunk-256KIVJL.js";
|
|
25
|
-
import {
|
|
26
|
-
AuthError,
|
|
27
|
-
ERROR_RESPONSE,
|
|
28
|
-
isAuthError
|
|
29
|
-
} from "./chunk-FJUDBLCP.js";
|
|
30
|
-
import {
|
|
31
|
-
AuraResponse
|
|
32
|
-
} from "./chunk-JAPMIE6S.js";
|
|
33
|
-
import {
|
|
34
|
-
OAuthAuthorizationErrorResponse,
|
|
35
|
-
OAuthAuthorizationResponse
|
|
36
|
-
} from "./chunk-HMRKN75I.js";
|
|
1
|
+
import { getUserInfo } from "./chunk-RLT4RFKV.js"
|
|
2
|
+
import { createAccessToken } from "./chunk-UJJ7R56J.js"
|
|
3
|
+
import { createSessionCookie, expireCookie, getCookie, secureCookieOptions, setCookie } from "./chunk-ZV4BH47P.js"
|
|
4
|
+
import { cacheControl } from "./chunk-STHEPPUZ.js"
|
|
5
|
+
import { createCSRF } from "./chunk-GZU3RBTB.js"
|
|
6
|
+
import { equals, isValidRelativePath, sanitizeURL } from "./chunk-256KIVJL.js"
|
|
7
|
+
import { AuthError, ERROR_RESPONSE, isAuthError } from "./chunk-FJUDBLCP.js"
|
|
8
|
+
import { AuraResponse } from "./chunk-JAPMIE6S.js"
|
|
9
|
+
import { OAuthAuthorizationErrorResponse, OAuthAuthorizationResponse } from "./chunk-HMRKN75I.js"
|
|
37
10
|
|
|
38
11
|
// src/actions/callback/callback.ts
|
|
39
|
-
import z from "zod"
|
|
40
|
-
import { createEndpoint, createEndpointConfig, statusCode } from "@aura-stack/router"
|
|
12
|
+
import z from "zod"
|
|
13
|
+
import { createEndpoint, createEndpointConfig, statusCode } from "@aura-stack/router"
|
|
41
14
|
var callbackConfig = (oauth) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
var callbackAction = (oauth) => {
|
|
62
|
-
return createEndpoint(
|
|
63
|
-
"GET",
|
|
64
|
-
"/callback/:oauth",
|
|
65
|
-
async (ctx) => {
|
|
66
|
-
const {
|
|
67
|
-
request,
|
|
68
|
-
params: { oauth: oauth2 },
|
|
69
|
-
searchParams: { code, state },
|
|
70
|
-
context: { oauth: providers, cookies, jose, trustedProxyHeaders }
|
|
71
|
-
} = ctx;
|
|
72
|
-
try {
|
|
73
|
-
const oauthConfig = providers[oauth2];
|
|
74
|
-
const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders);
|
|
75
|
-
const cookieState = getCookie(request, "state", cookieOptions);
|
|
76
|
-
const cookieRedirectTo = getCookie(request, "redirect_to", cookieOptions);
|
|
77
|
-
const cookieRedirectURI = getCookie(request, "redirect_uri", cookieOptions);
|
|
78
|
-
const codeVerifier = getCookie(request, "code_verifier", cookieOptions);
|
|
79
|
-
if (!equals(cookieState, state)) {
|
|
80
|
-
throw new AuthError(ERROR_RESPONSE.ACCESS_TOKEN.INVALID_REQUEST, "Mismatching state");
|
|
81
|
-
}
|
|
82
|
-
const accessToken = await createAccessToken(oauthConfig, cookieRedirectURI, code, codeVerifier);
|
|
83
|
-
const sanitized = sanitizeURL(cookieRedirectTo);
|
|
84
|
-
if (!isValidRelativePath(sanitized)) {
|
|
85
|
-
throw new AuthError(
|
|
86
|
-
ERROR_RESPONSE.ACCESS_TOKEN.INVALID_REQUEST,
|
|
87
|
-
"Invalid redirect path. Potential open redirect attack detected."
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
const headers = new Headers(cacheControl);
|
|
91
|
-
headers.set("Location", sanitized);
|
|
92
|
-
const userInfo = await getUserInfo(oauthConfig, accessToken.access_token);
|
|
93
|
-
const sessionCookie = await createSessionCookie(userInfo, cookieOptions, jose);
|
|
94
|
-
const csrfToken = await createCSRF(jose);
|
|
95
|
-
const csrfCookie = setCookie(
|
|
96
|
-
"csrfToken",
|
|
97
|
-
csrfToken,
|
|
98
|
-
secureCookieOptions(
|
|
99
|
-
request,
|
|
100
|
-
{
|
|
101
|
-
...cookies,
|
|
102
|
-
strategy: "host"
|
|
15
|
+
return createEndpointConfig("/callback/:oauth", {
|
|
16
|
+
schemas: {
|
|
17
|
+
searchParams: OAuthAuthorizationResponse,
|
|
18
|
+
params: z.object({
|
|
19
|
+
oauth: z.enum(Object.keys(oauth)),
|
|
20
|
+
}),
|
|
21
|
+
},
|
|
22
|
+
middlewares: [
|
|
23
|
+
(ctx) => {
|
|
24
|
+
const response = OAuthAuthorizationErrorResponse.safeParse(ctx.searchParams)
|
|
25
|
+
if (response.success) {
|
|
26
|
+
const { error, error_description } = response.data
|
|
27
|
+
throw new AuthError(error, error_description ?? "OAuth Authorization Error")
|
|
28
|
+
}
|
|
29
|
+
return ctx
|
|
103
30
|
},
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
133
|
-
|
|
31
|
+
],
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
var callbackAction = (oauth) => {
|
|
35
|
+
return createEndpoint(
|
|
36
|
+
"GET",
|
|
37
|
+
"/callback/:oauth",
|
|
38
|
+
async (ctx) => {
|
|
39
|
+
const {
|
|
40
|
+
request,
|
|
41
|
+
params: { oauth: oauth2 },
|
|
42
|
+
searchParams: { code, state },
|
|
43
|
+
context: { oauth: providers, cookies, jose, trustedProxyHeaders },
|
|
44
|
+
} = ctx
|
|
45
|
+
try {
|
|
46
|
+
const oauthConfig = providers[oauth2]
|
|
47
|
+
const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders)
|
|
48
|
+
const cookieState = getCookie(request, "state", cookieOptions)
|
|
49
|
+
const cookieRedirectTo = getCookie(request, "redirect_to", cookieOptions)
|
|
50
|
+
const cookieRedirectURI = getCookie(request, "redirect_uri", cookieOptions)
|
|
51
|
+
const codeVerifier = getCookie(request, "code_verifier", cookieOptions)
|
|
52
|
+
if (!equals(cookieState, state)) {
|
|
53
|
+
throw new AuthError(ERROR_RESPONSE.ACCESS_TOKEN.INVALID_REQUEST, "Mismatching state")
|
|
54
|
+
}
|
|
55
|
+
const accessToken = await createAccessToken(oauthConfig, cookieRedirectURI, code, codeVerifier)
|
|
56
|
+
const sanitized = sanitizeURL(cookieRedirectTo)
|
|
57
|
+
if (!isValidRelativePath(sanitized)) {
|
|
58
|
+
throw new AuthError(
|
|
59
|
+
ERROR_RESPONSE.ACCESS_TOKEN.INVALID_REQUEST,
|
|
60
|
+
"Invalid redirect path. Potential open redirect attack detected."
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
const headers = new Headers(cacheControl)
|
|
64
|
+
headers.set("Location", sanitized)
|
|
65
|
+
const userInfo = await getUserInfo(oauthConfig, accessToken.access_token)
|
|
66
|
+
const sessionCookie = await createSessionCookie(userInfo, cookieOptions, jose)
|
|
67
|
+
const csrfToken = await createCSRF(jose)
|
|
68
|
+
const csrfCookie = setCookie(
|
|
69
|
+
"csrfToken",
|
|
70
|
+
csrfToken,
|
|
71
|
+
secureCookieOptions(
|
|
72
|
+
request,
|
|
73
|
+
{
|
|
74
|
+
...cookies,
|
|
75
|
+
strategy: "host",
|
|
76
|
+
},
|
|
77
|
+
trustedProxyHeaders
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
headers.set("Set-Cookie", sessionCookie)
|
|
81
|
+
headers.append("Set-Cookie", expireCookie("state", cookieOptions))
|
|
82
|
+
headers.append("Set-Cookie", expireCookie("redirect_uri", cookieOptions))
|
|
83
|
+
headers.append("Set-Cookie", expireCookie("redirect_to", cookieOptions))
|
|
84
|
+
headers.append("Set-Cookie", expireCookie("code_verifier", cookieOptions))
|
|
85
|
+
headers.append("Set-Cookie", csrfCookie)
|
|
86
|
+
return Response.json({ oauth: oauth2 }, { status: 302, headers })
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (isAuthError(error)) {
|
|
89
|
+
const { type, message } = error
|
|
90
|
+
return AuraResponse.json({ error: type, error_description: message }, { status: statusCode.BAD_REQUEST })
|
|
91
|
+
}
|
|
92
|
+
return AuraResponse.json(
|
|
93
|
+
{
|
|
94
|
+
error: ERROR_RESPONSE.ACCESS_TOKEN.INVALID_CLIENT,
|
|
95
|
+
error_description: "An unexpected error occurred",
|
|
96
|
+
},
|
|
97
|
+
{ status: statusCode.INTERNAL_SERVER_ERROR }
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
callbackConfig(oauth)
|
|
102
|
+
)
|
|
103
|
+
}
|
|
134
104
|
|
|
135
|
-
export {
|
|
136
|
-
callbackAction
|
|
137
|
-
};
|
|
105
|
+
export { callbackAction }
|