@hammadj/better-auth-core 1.5.0-beta.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/.turbo/turbo-build.log +266 -0
- package/.turbo/turbo-test.log +2 -0
- package/LICENSE.md +20 -0
- package/dist/api/index.d.mts +181 -0
- package/dist/api/index.mjs +34 -0
- package/dist/api/index.mjs.map +1 -0
- package/dist/async_hooks/index.d.mts +7 -0
- package/dist/async_hooks/index.mjs +22 -0
- package/dist/async_hooks/index.mjs.map +1 -0
- package/dist/async_hooks/pure.index.d.mts +7 -0
- package/dist/async_hooks/pure.index.mjs +35 -0
- package/dist/async_hooks/pure.index.mjs.map +1 -0
- package/dist/context/endpoint-context.d.mts +19 -0
- package/dist/context/endpoint-context.mjs +32 -0
- package/dist/context/endpoint-context.mjs.map +1 -0
- package/dist/context/global.d.mts +7 -0
- package/dist/context/global.mjs +38 -0
- package/dist/context/global.mjs.map +1 -0
- package/dist/context/index.d.mts +5 -0
- package/dist/context/index.mjs +6 -0
- package/dist/context/request-state.d.mts +26 -0
- package/dist/context/request-state.mjs +50 -0
- package/dist/context/request-state.mjs.map +1 -0
- package/dist/context/transaction.d.mts +25 -0
- package/dist/context/transaction.mjs +96 -0
- package/dist/context/transaction.mjs.map +1 -0
- package/dist/db/adapter/factory.d.mts +28 -0
- package/dist/db/adapter/factory.mjs +716 -0
- package/dist/db/adapter/factory.mjs.map +1 -0
- package/dist/db/adapter/get-default-field-name.d.mts +19 -0
- package/dist/db/adapter/get-default-field-name.mjs +39 -0
- package/dist/db/adapter/get-default-field-name.mjs.map +1 -0
- package/dist/db/adapter/get-default-model-name.d.mts +13 -0
- package/dist/db/adapter/get-default-model-name.mjs +33 -0
- package/dist/db/adapter/get-default-model-name.mjs.map +1 -0
- package/dist/db/adapter/get-field-attributes.d.mts +30 -0
- package/dist/db/adapter/get-field-attributes.mjs +40 -0
- package/dist/db/adapter/get-field-attributes.mjs.map +1 -0
- package/dist/db/adapter/get-field-name.d.mts +19 -0
- package/dist/db/adapter/get-field-name.mjs +34 -0
- package/dist/db/adapter/get-field-name.mjs.map +1 -0
- package/dist/db/adapter/get-id-field.d.mts +40 -0
- package/dist/db/adapter/get-id-field.mjs +68 -0
- package/dist/db/adapter/get-id-field.mjs.map +1 -0
- package/dist/db/adapter/get-model-name.d.mts +13 -0
- package/dist/db/adapter/get-model-name.mjs +24 -0
- package/dist/db/adapter/get-model-name.mjs.map +1 -0
- package/dist/db/adapter/index.d.mts +515 -0
- package/dist/db/adapter/index.mjs +10 -0
- package/dist/db/adapter/types.d.mts +140 -0
- package/dist/db/adapter/utils.d.mts +8 -0
- package/dist/db/adapter/utils.mjs +39 -0
- package/dist/db/adapter/utils.mjs.map +1 -0
- package/dist/db/get-tables.d.mts +9 -0
- package/dist/db/get-tables.mjs +267 -0
- package/dist/db/get-tables.mjs.map +1 -0
- package/dist/db/index.d.mts +10 -0
- package/dist/db/index.mjs +9 -0
- package/dist/db/plugin.d.mts +13 -0
- package/dist/db/schema/account.d.mts +27 -0
- package/dist/db/schema/account.mjs +20 -0
- package/dist/db/schema/account.mjs.map +1 -0
- package/dist/db/schema/rate-limit.d.mts +15 -0
- package/dist/db/schema/rate-limit.mjs +12 -0
- package/dist/db/schema/rate-limit.mjs.map +1 -0
- package/dist/db/schema/session.d.mts +22 -0
- package/dist/db/schema/session.mjs +15 -0
- package/dist/db/schema/session.mjs.map +1 -0
- package/dist/db/schema/shared.d.mts +11 -0
- package/dist/db/schema/shared.mjs +12 -0
- package/dist/db/schema/shared.mjs.map +1 -0
- package/dist/db/schema/user.d.mts +21 -0
- package/dist/db/schema/user.mjs +14 -0
- package/dist/db/schema/user.mjs.map +1 -0
- package/dist/db/schema/verification.d.mts +20 -0
- package/dist/db/schema/verification.mjs +13 -0
- package/dist/db/schema/verification.mjs.map +1 -0
- package/dist/db/type.d.mts +147 -0
- package/dist/env/color-depth.d.mts +5 -0
- package/dist/env/color-depth.mjs +89 -0
- package/dist/env/color-depth.mjs.map +1 -0
- package/dist/env/env-impl.d.mts +33 -0
- package/dist/env/env-impl.mjs +83 -0
- package/dist/env/env-impl.mjs.map +1 -0
- package/dist/env/index.d.mts +4 -0
- package/dist/env/index.mjs +5 -0
- package/dist/env/logger.d.mts +49 -0
- package/dist/env/logger.mjs +82 -0
- package/dist/env/logger.mjs.map +1 -0
- package/dist/error/codes.d.mts +199 -0
- package/dist/error/codes.mjs +57 -0
- package/dist/error/codes.mjs.map +1 -0
- package/dist/error/index.d.mts +20 -0
- package/dist/error/index.mjs +30 -0
- package/dist/error/index.mjs.map +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.mjs +1 -0
- package/dist/oauth2/client-credentials-token.d.mts +37 -0
- package/dist/oauth2/client-credentials-token.mjs +55 -0
- package/dist/oauth2/client-credentials-token.mjs.map +1 -0
- package/dist/oauth2/create-authorization-url.d.mts +46 -0
- package/dist/oauth2/create-authorization-url.mjs +43 -0
- package/dist/oauth2/create-authorization-url.mjs.map +1 -0
- package/dist/oauth2/index.d.mts +8 -0
- package/dist/oauth2/index.mjs +8 -0
- package/dist/oauth2/oauth-provider.d.mts +195 -0
- package/dist/oauth2/refresh-access-token.d.mts +36 -0
- package/dist/oauth2/refresh-access-token.mjs +59 -0
- package/dist/oauth2/refresh-access-token.mjs.map +1 -0
- package/dist/oauth2/utils.d.mts +8 -0
- package/dist/oauth2/utils.mjs +28 -0
- package/dist/oauth2/utils.mjs.map +1 -0
- package/dist/oauth2/validate-authorization-code.d.mts +56 -0
- package/dist/oauth2/validate-authorization-code.mjs +72 -0
- package/dist/oauth2/validate-authorization-code.mjs.map +1 -0
- package/dist/oauth2/verify.d.mts +43 -0
- package/dist/oauth2/verify.mjs +96 -0
- package/dist/oauth2/verify.mjs.map +1 -0
- package/dist/social-providers/apple.d.mts +120 -0
- package/dist/social-providers/apple.mjs +105 -0
- package/dist/social-providers/apple.mjs.map +1 -0
- package/dist/social-providers/atlassian.d.mts +73 -0
- package/dist/social-providers/atlassian.mjs +84 -0
- package/dist/social-providers/atlassian.mjs.map +1 -0
- package/dist/social-providers/cognito.d.mts +88 -0
- package/dist/social-providers/cognito.mjs +166 -0
- package/dist/social-providers/cognito.mjs.map +1 -0
- package/dist/social-providers/discord.d.mts +127 -0
- package/dist/social-providers/discord.mjs +65 -0
- package/dist/social-providers/discord.mjs.map +1 -0
- package/dist/social-providers/dropbox.d.mts +72 -0
- package/dist/social-providers/dropbox.mjs +76 -0
- package/dist/social-providers/dropbox.mjs.map +1 -0
- package/dist/social-providers/facebook.d.mts +82 -0
- package/dist/social-providers/facebook.mjs +121 -0
- package/dist/social-providers/facebook.mjs.map +1 -0
- package/dist/social-providers/figma.d.mts +64 -0
- package/dist/social-providers/figma.mjs +87 -0
- package/dist/social-providers/figma.mjs.map +1 -0
- package/dist/social-providers/github.d.mts +105 -0
- package/dist/social-providers/github.mjs +97 -0
- package/dist/social-providers/github.mjs.map +1 -0
- package/dist/social-providers/gitlab.d.mts +126 -0
- package/dist/social-providers/gitlab.mjs +83 -0
- package/dist/social-providers/gitlab.mjs.map +1 -0
- package/dist/social-providers/google.d.mts +100 -0
- package/dist/social-providers/google.mjs +109 -0
- package/dist/social-providers/google.mjs.map +1 -0
- package/dist/social-providers/huggingface.d.mts +86 -0
- package/dist/social-providers/huggingface.mjs +76 -0
- package/dist/social-providers/huggingface.mjs.map +1 -0
- package/dist/social-providers/index.d.mts +1725 -0
- package/dist/social-providers/index.mjs +77 -0
- package/dist/social-providers/index.mjs.map +1 -0
- package/dist/social-providers/kakao.d.mts +164 -0
- package/dist/social-providers/kakao.mjs +73 -0
- package/dist/social-providers/kakao.mjs.map +1 -0
- package/dist/social-providers/kick.d.mts +76 -0
- package/dist/social-providers/kick.mjs +72 -0
- package/dist/social-providers/kick.mjs.map +1 -0
- package/dist/social-providers/line.d.mts +108 -0
- package/dist/social-providers/line.mjs +114 -0
- package/dist/social-providers/line.mjs.map +1 -0
- package/dist/social-providers/linear.d.mts +71 -0
- package/dist/social-providers/linear.mjs +89 -0
- package/dist/social-providers/linear.mjs.map +1 -0
- package/dist/social-providers/linkedin.d.mts +70 -0
- package/dist/social-providers/linkedin.mjs +77 -0
- package/dist/social-providers/linkedin.mjs.map +1 -0
- package/dist/social-providers/microsoft-entra-id.d.mts +175 -0
- package/dist/social-providers/microsoft-entra-id.mjs +107 -0
- package/dist/social-providers/microsoft-entra-id.mjs.map +1 -0
- package/dist/social-providers/naver.d.mts +95 -0
- package/dist/social-providers/naver.mjs +68 -0
- package/dist/social-providers/naver.mjs.map +1 -0
- package/dist/social-providers/notion.d.mts +67 -0
- package/dist/social-providers/notion.mjs +76 -0
- package/dist/social-providers/notion.mjs.map +1 -0
- package/dist/social-providers/paybin.d.mts +74 -0
- package/dist/social-providers/paybin.mjs +86 -0
- package/dist/social-providers/paybin.mjs.map +1 -0
- package/dist/social-providers/paypal.d.mts +132 -0
- package/dist/social-providers/paypal.mjs +145 -0
- package/dist/social-providers/paypal.mjs.map +1 -0
- package/dist/social-providers/polar.d.mts +77 -0
- package/dist/social-providers/polar.mjs +74 -0
- package/dist/social-providers/polar.mjs.map +1 -0
- package/dist/social-providers/reddit.d.mts +65 -0
- package/dist/social-providers/reddit.mjs +84 -0
- package/dist/social-providers/reddit.mjs.map +1 -0
- package/dist/social-providers/roblox.d.mts +73 -0
- package/dist/social-providers/roblox.mjs +60 -0
- package/dist/social-providers/roblox.mjs.map +1 -0
- package/dist/social-providers/salesforce.d.mts +82 -0
- package/dist/social-providers/salesforce.mjs +92 -0
- package/dist/social-providers/salesforce.mjs.map +1 -0
- package/dist/social-providers/slack.d.mts +86 -0
- package/dist/social-providers/slack.mjs +69 -0
- package/dist/social-providers/slack.mjs.map +1 -0
- package/dist/social-providers/spotify.d.mts +66 -0
- package/dist/social-providers/spotify.mjs +72 -0
- package/dist/social-providers/spotify.mjs.map +1 -0
- package/dist/social-providers/tiktok.d.mts +171 -0
- package/dist/social-providers/tiktok.mjs +63 -0
- package/dist/social-providers/tiktok.mjs.map +1 -0
- package/dist/social-providers/twitch.d.mts +82 -0
- package/dist/social-providers/twitch.mjs +79 -0
- package/dist/social-providers/twitch.mjs.map +1 -0
- package/dist/social-providers/twitter.d.mts +129 -0
- package/dist/social-providers/twitter.mjs +88 -0
- package/dist/social-providers/twitter.mjs.map +1 -0
- package/dist/social-providers/vercel.d.mts +65 -0
- package/dist/social-providers/vercel.mjs +62 -0
- package/dist/social-providers/vercel.mjs.map +1 -0
- package/dist/social-providers/vk.d.mts +73 -0
- package/dist/social-providers/vk.mjs +84 -0
- package/dist/social-providers/vk.mjs.map +1 -0
- package/dist/social-providers/zoom.d.mts +173 -0
- package/dist/social-providers/zoom.mjs +73 -0
- package/dist/social-providers/zoom.mjs.map +1 -0
- package/dist/types/context.d.mts +267 -0
- package/dist/types/cookie.d.mts +16 -0
- package/dist/types/helper.d.mts +10 -0
- package/dist/types/index.d.mts +8 -0
- package/dist/types/init-options.d.mts +1314 -0
- package/dist/types/plugin-client.d.mts +112 -0
- package/dist/types/plugin.d.mts +125 -0
- package/dist/utils/db.d.mts +12 -0
- package/dist/utils/db.mjs +17 -0
- package/dist/utils/db.mjs.map +1 -0
- package/dist/utils/deprecate.d.mts +10 -0
- package/dist/utils/deprecate.mjs +18 -0
- package/dist/utils/deprecate.mjs.map +1 -0
- package/dist/utils/error-codes.d.mts +13 -0
- package/dist/utils/error-codes.mjs +12 -0
- package/dist/utils/error-codes.mjs.map +1 -0
- package/dist/utils/id.d.mts +5 -0
- package/dist/utils/id.mjs +10 -0
- package/dist/utils/id.mjs.map +1 -0
- package/dist/utils/ip.d.mts +55 -0
- package/dist/utils/ip.mjs +119 -0
- package/dist/utils/ip.mjs.map +1 -0
- package/dist/utils/json.d.mts +5 -0
- package/dist/utils/json.mjs +26 -0
- package/dist/utils/json.mjs.map +1 -0
- package/dist/utils/string.d.mts +5 -0
- package/dist/utils/string.mjs +8 -0
- package/dist/utils/string.mjs.map +1 -0
- package/dist/utils/url.d.mts +21 -0
- package/dist/utils/url.mjs +33 -0
- package/dist/utils/url.mjs.map +1 -0
- package/package.json +147 -0
- package/src/api/index.ts +106 -0
- package/src/async_hooks/index.ts +40 -0
- package/src/async_hooks/pure.index.ts +46 -0
- package/src/context/endpoint-context.ts +50 -0
- package/src/context/global.ts +57 -0
- package/src/context/index.ts +23 -0
- package/src/context/request-state.test.ts +94 -0
- package/src/context/request-state.ts +91 -0
- package/src/context/transaction.ts +136 -0
- package/src/db/adapter/factory.ts +1362 -0
- package/src/db/adapter/get-default-field-name.ts +59 -0
- package/src/db/adapter/get-default-model-name.ts +51 -0
- package/src/db/adapter/get-field-attributes.ts +62 -0
- package/src/db/adapter/get-field-name.ts +43 -0
- package/src/db/adapter/get-id-field.ts +141 -0
- package/src/db/adapter/get-model-name.ts +36 -0
- package/src/db/adapter/index.ts +554 -0
- package/src/db/adapter/types.ts +171 -0
- package/src/db/adapter/utils.ts +61 -0
- package/src/db/get-tables.ts +296 -0
- package/src/db/index.ts +18 -0
- package/src/db/plugin.ts +11 -0
- package/src/db/schema/account.ts +34 -0
- package/src/db/schema/rate-limit.ts +21 -0
- package/src/db/schema/session.ts +17 -0
- package/src/db/schema/shared.ts +7 -0
- package/src/db/schema/user.ts +16 -0
- package/src/db/schema/verification.ts +15 -0
- package/src/db/test/get-tables.test.ts +116 -0
- package/src/db/type.ts +180 -0
- package/src/env/color-depth.ts +172 -0
- package/src/env/env-impl.ts +124 -0
- package/src/env/index.ts +23 -0
- package/src/env/logger.test.ts +34 -0
- package/src/env/logger.ts +145 -0
- package/src/error/codes.ts +58 -0
- package/src/error/index.ts +35 -0
- package/src/index.ts +1 -0
- package/src/oauth2/client-credentials-token.ts +102 -0
- package/src/oauth2/create-authorization-url.ts +87 -0
- package/src/oauth2/index.ts +26 -0
- package/src/oauth2/oauth-provider.ts +222 -0
- package/src/oauth2/refresh-access-token.ts +124 -0
- package/src/oauth2/utils.ts +38 -0
- package/src/oauth2/validate-authorization-code.ts +149 -0
- package/src/oauth2/validate-token.test.ts +174 -0
- package/src/oauth2/verify.ts +221 -0
- package/src/social-providers/apple.ts +223 -0
- package/src/social-providers/atlassian.ts +132 -0
- package/src/social-providers/cognito.ts +279 -0
- package/src/social-providers/discord.ts +169 -0
- package/src/social-providers/dropbox.ts +112 -0
- package/src/social-providers/facebook.ts +206 -0
- package/src/social-providers/figma.ts +117 -0
- package/src/social-providers/github.ts +184 -0
- package/src/social-providers/gitlab.ts +155 -0
- package/src/social-providers/google.ts +199 -0
- package/src/social-providers/huggingface.ts +118 -0
- package/src/social-providers/index.ts +127 -0
- package/src/social-providers/kakao.ts +178 -0
- package/src/social-providers/kick.ts +109 -0
- package/src/social-providers/line.ts +169 -0
- package/src/social-providers/linear.ts +121 -0
- package/src/social-providers/linkedin.ts +110 -0
- package/src/social-providers/microsoft-entra-id.ts +259 -0
- package/src/social-providers/naver.ts +112 -0
- package/src/social-providers/notion.ts +108 -0
- package/src/social-providers/paybin.ts +122 -0
- package/src/social-providers/paypal.ts +263 -0
- package/src/social-providers/polar.ts +110 -0
- package/src/social-providers/reddit.ts +122 -0
- package/src/social-providers/roblox.ts +111 -0
- package/src/social-providers/salesforce.ts +159 -0
- package/src/social-providers/slack.ts +111 -0
- package/src/social-providers/spotify.ts +93 -0
- package/src/social-providers/tiktok.ts +209 -0
- package/src/social-providers/twitch.ts +111 -0
- package/src/social-providers/twitter.ts +198 -0
- package/src/social-providers/vercel.ts +87 -0
- package/src/social-providers/vk.ts +124 -0
- package/src/social-providers/zoom.ts +238 -0
- package/src/types/context.ts +396 -0
- package/src/types/cookie.ts +10 -0
- package/src/types/helper.ts +26 -0
- package/src/types/index.ts +32 -0
- package/src/types/init-options.ts +1529 -0
- package/src/types/plugin-client.ts +127 -0
- package/src/types/plugin.ts +157 -0
- package/src/utils/db.ts +20 -0
- package/src/utils/deprecate.test.ts +72 -0
- package/src/utils/deprecate.ts +21 -0
- package/src/utils/error-codes.ts +65 -0
- package/src/utils/id.ts +5 -0
- package/src/utils/ip.test.ts +255 -0
- package/src/utils/ip.ts +211 -0
- package/src/utils/json.ts +25 -0
- package/src/utils/string.ts +3 -0
- package/src/utils/url.ts +43 -0
- package/tsconfig.json +7 -0
- package/tsdown.config.ts +35 -0
- package/vitest.config.ts +3 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
|
|
3
|
+
import { decodeJwt, decodeProtectedHeader, importJWK, jwtVerify } from "jose";
|
|
4
|
+
import { APIError } from "../error";
|
|
5
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
6
|
+
import {
|
|
7
|
+
createAuthorizationURL,
|
|
8
|
+
refreshAccessToken,
|
|
9
|
+
validateAuthorizationCode,
|
|
10
|
+
} from "../oauth2";
|
|
11
|
+
export interface AppleProfile {
|
|
12
|
+
/**
|
|
13
|
+
* The subject registered claim identifies the principal that’s the subject
|
|
14
|
+
* of the identity token. Because this token is for your app, the value is
|
|
15
|
+
* the unique identifier for the user.
|
|
16
|
+
*/
|
|
17
|
+
sub: string;
|
|
18
|
+
/**
|
|
19
|
+
* A String value representing the user's email address.
|
|
20
|
+
* The email address is either the user's real email address or the proxy
|
|
21
|
+
* address, depending on their status private email relay service.
|
|
22
|
+
*/
|
|
23
|
+
email: string;
|
|
24
|
+
/**
|
|
25
|
+
* A string or Boolean value that indicates whether the service verifies
|
|
26
|
+
* the email. The value can either be a string ("true" or "false") or a
|
|
27
|
+
* Boolean (true or false). The system may not verify email addresses for
|
|
28
|
+
* Sign in with Apple at Work & School users, and this claim is "false" or
|
|
29
|
+
* false for those users.
|
|
30
|
+
*/
|
|
31
|
+
email_verified: true | "true";
|
|
32
|
+
/**
|
|
33
|
+
* A string or Boolean value that indicates whether the email that the user
|
|
34
|
+
* shares is the proxy address. The value can either be a string ("true" or
|
|
35
|
+
* "false") or a Boolean (true or false).
|
|
36
|
+
*/
|
|
37
|
+
is_private_email: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* An Integer value that indicates whether the user appears to be a real
|
|
40
|
+
* person. Use the value of this claim to mitigate fraud. The possible
|
|
41
|
+
* values are: 0 (or Unsupported), 1 (or Unknown), 2 (or LikelyReal). For
|
|
42
|
+
* more information, see ASUserDetectionStatus. This claim is present only
|
|
43
|
+
* in iOS 14 and later, macOS 11 and later, watchOS 7 and later, tvOS 14
|
|
44
|
+
* and later. The claim isn’t present or supported for web-based apps.
|
|
45
|
+
*/
|
|
46
|
+
real_user_status: number;
|
|
47
|
+
/**
|
|
48
|
+
* The user’s full name in the format provided during the authorization
|
|
49
|
+
* process.
|
|
50
|
+
*/
|
|
51
|
+
name: string;
|
|
52
|
+
/**
|
|
53
|
+
* The URL to the user's profile picture.
|
|
54
|
+
*/
|
|
55
|
+
picture: string;
|
|
56
|
+
user?: AppleNonConformUser | undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* This is the shape of the `user` query parameter that Apple sends the first
|
|
61
|
+
* time the user consents to the app.
|
|
62
|
+
* @see https://developer.apple.com/documentation/signinwithapplerestapi/request-an-authorization-to-the-sign-in-with-apple-server./
|
|
63
|
+
*/
|
|
64
|
+
export interface AppleNonConformUser {
|
|
65
|
+
name: {
|
|
66
|
+
firstName: string;
|
|
67
|
+
lastName: string;
|
|
68
|
+
};
|
|
69
|
+
email: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface AppleOptions extends ProviderOptions<AppleProfile> {
|
|
73
|
+
clientId: string;
|
|
74
|
+
appBundleIdentifier?: string | undefined;
|
|
75
|
+
audience?: (string | string[]) | undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const apple = (options: AppleOptions) => {
|
|
79
|
+
const tokenEndpoint = "https://appleid.apple.com/auth/token";
|
|
80
|
+
return {
|
|
81
|
+
id: "apple",
|
|
82
|
+
name: "Apple",
|
|
83
|
+
async createAuthorizationURL({ state, scopes, redirectURI }) {
|
|
84
|
+
const _scope = options.disableDefaultScope ? [] : ["email", "name"];
|
|
85
|
+
if (options.scope) _scope.push(...options.scope);
|
|
86
|
+
if (scopes) _scope.push(...scopes);
|
|
87
|
+
const url = await createAuthorizationURL({
|
|
88
|
+
id: "apple",
|
|
89
|
+
options,
|
|
90
|
+
authorizationEndpoint: "https://appleid.apple.com/auth/authorize",
|
|
91
|
+
scopes: _scope,
|
|
92
|
+
state,
|
|
93
|
+
redirectURI,
|
|
94
|
+
responseMode: "form_post",
|
|
95
|
+
responseType: "code id_token",
|
|
96
|
+
});
|
|
97
|
+
return url;
|
|
98
|
+
},
|
|
99
|
+
validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
|
|
100
|
+
return validateAuthorizationCode({
|
|
101
|
+
code,
|
|
102
|
+
codeVerifier,
|
|
103
|
+
redirectURI,
|
|
104
|
+
options,
|
|
105
|
+
tokenEndpoint,
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
async verifyIdToken(token, nonce) {
|
|
109
|
+
if (options.disableIdTokenSignIn) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
if (options.verifyIdToken) {
|
|
113
|
+
return options.verifyIdToken(token, nonce);
|
|
114
|
+
}
|
|
115
|
+
const decodedHeader = decodeProtectedHeader(token);
|
|
116
|
+
const { kid, alg: jwtAlg } = decodedHeader;
|
|
117
|
+
if (!kid || !jwtAlg) return false;
|
|
118
|
+
const publicKey = await getApplePublicKey(kid);
|
|
119
|
+
const { payload: jwtClaims } = await jwtVerify(token, publicKey, {
|
|
120
|
+
algorithms: [jwtAlg],
|
|
121
|
+
issuer: "https://appleid.apple.com",
|
|
122
|
+
audience:
|
|
123
|
+
options.audience && options.audience.length
|
|
124
|
+
? options.audience
|
|
125
|
+
: options.appBundleIdentifier
|
|
126
|
+
? options.appBundleIdentifier
|
|
127
|
+
: options.clientId,
|
|
128
|
+
maxTokenAge: "1h",
|
|
129
|
+
});
|
|
130
|
+
["email_verified", "is_private_email"].forEach((field) => {
|
|
131
|
+
if (jwtClaims[field] !== undefined) {
|
|
132
|
+
jwtClaims[field] = Boolean(jwtClaims[field]);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
if (nonce && jwtClaims.nonce !== nonce) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
return !!jwtClaims;
|
|
139
|
+
},
|
|
140
|
+
refreshAccessToken: options.refreshAccessToken
|
|
141
|
+
? options.refreshAccessToken
|
|
142
|
+
: async (refreshToken) => {
|
|
143
|
+
return refreshAccessToken({
|
|
144
|
+
refreshToken,
|
|
145
|
+
options: {
|
|
146
|
+
clientId: options.clientId,
|
|
147
|
+
clientKey: options.clientKey,
|
|
148
|
+
clientSecret: options.clientSecret,
|
|
149
|
+
},
|
|
150
|
+
tokenEndpoint: "https://appleid.apple.com/auth/token",
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
async getUserInfo(token) {
|
|
154
|
+
if (options.getUserInfo) {
|
|
155
|
+
return options.getUserInfo(token);
|
|
156
|
+
}
|
|
157
|
+
if (!token.idToken) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
const profile = decodeJwt<AppleProfile>(token.idToken);
|
|
161
|
+
if (!profile) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// TODO: " " masking will be removed when the name field is made optional
|
|
166
|
+
let name: string;
|
|
167
|
+
if (token.user?.name) {
|
|
168
|
+
const firstName = token.user.name.firstName || "";
|
|
169
|
+
const lastName = token.user.name.lastName || "";
|
|
170
|
+
const fullName = `${firstName} ${lastName}`.trim();
|
|
171
|
+
name = fullName || " ";
|
|
172
|
+
} else {
|
|
173
|
+
name = profile.name || " ";
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const emailVerified =
|
|
177
|
+
typeof profile.email_verified === "boolean"
|
|
178
|
+
? profile.email_verified
|
|
179
|
+
: profile.email_verified === "true";
|
|
180
|
+
const enrichedProfile = {
|
|
181
|
+
...profile,
|
|
182
|
+
name,
|
|
183
|
+
};
|
|
184
|
+
const userMap = await options.mapProfileToUser?.(enrichedProfile);
|
|
185
|
+
return {
|
|
186
|
+
user: {
|
|
187
|
+
id: profile.sub,
|
|
188
|
+
name: enrichedProfile.name,
|
|
189
|
+
emailVerified: emailVerified,
|
|
190
|
+
email: profile.email,
|
|
191
|
+
...userMap,
|
|
192
|
+
},
|
|
193
|
+
data: enrichedProfile,
|
|
194
|
+
};
|
|
195
|
+
},
|
|
196
|
+
options,
|
|
197
|
+
} satisfies OAuthProvider<AppleProfile>;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export const getApplePublicKey = async (kid: string) => {
|
|
201
|
+
const APPLE_BASE_URL = "https://appleid.apple.com";
|
|
202
|
+
const JWKS_APPLE_URI = "/auth/keys";
|
|
203
|
+
const { data } = await betterFetch<{
|
|
204
|
+
keys: Array<{
|
|
205
|
+
kid: string;
|
|
206
|
+
alg: string;
|
|
207
|
+
kty: string;
|
|
208
|
+
use: string;
|
|
209
|
+
n: string;
|
|
210
|
+
e: string;
|
|
211
|
+
}>;
|
|
212
|
+
}>(`${APPLE_BASE_URL}${JWKS_APPLE_URI}`);
|
|
213
|
+
if (!data?.keys) {
|
|
214
|
+
throw new APIError("BAD_REQUEST", {
|
|
215
|
+
message: "Keys not found",
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
const jwk = data.keys.find((key) => key.kid === kid);
|
|
219
|
+
if (!jwk) {
|
|
220
|
+
throw new Error(`JWK with kid ${kid} not found`);
|
|
221
|
+
}
|
|
222
|
+
return await importJWK(jwk, jwk.alg);
|
|
223
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import { logger } from "../env";
|
|
3
|
+
import { BetterAuthError } from "../error";
|
|
4
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
5
|
+
import {
|
|
6
|
+
createAuthorizationURL,
|
|
7
|
+
refreshAccessToken,
|
|
8
|
+
validateAuthorizationCode,
|
|
9
|
+
} from "../oauth2";
|
|
10
|
+
|
|
11
|
+
export interface AtlassianProfile {
|
|
12
|
+
account_type?: string | undefined;
|
|
13
|
+
account_id: string;
|
|
14
|
+
email?: string | undefined;
|
|
15
|
+
name: string;
|
|
16
|
+
picture?: string | undefined;
|
|
17
|
+
nickname?: string | undefined;
|
|
18
|
+
locale?: string | undefined;
|
|
19
|
+
extended_profile?:
|
|
20
|
+
| {
|
|
21
|
+
job_title?: string;
|
|
22
|
+
organization?: string;
|
|
23
|
+
department?: string;
|
|
24
|
+
location?: string;
|
|
25
|
+
}
|
|
26
|
+
| undefined;
|
|
27
|
+
}
|
|
28
|
+
export interface AtlassianOptions extends ProviderOptions<AtlassianProfile> {
|
|
29
|
+
clientId: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const atlassian = (options: AtlassianOptions) => {
|
|
33
|
+
return {
|
|
34
|
+
id: "atlassian",
|
|
35
|
+
name: "Atlassian",
|
|
36
|
+
|
|
37
|
+
async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
|
|
38
|
+
if (!options.clientId || !options.clientSecret) {
|
|
39
|
+
logger.error("Client Id and Secret are required for Atlassian");
|
|
40
|
+
throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
|
|
41
|
+
}
|
|
42
|
+
if (!codeVerifier) {
|
|
43
|
+
throw new BetterAuthError("codeVerifier is required for Atlassian");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const _scopes = options.disableDefaultScope
|
|
47
|
+
? []
|
|
48
|
+
: ["read:jira-user", "offline_access"];
|
|
49
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
50
|
+
if (scopes) _scopes.push(...scopes);
|
|
51
|
+
|
|
52
|
+
return createAuthorizationURL({
|
|
53
|
+
id: "atlassian",
|
|
54
|
+
options,
|
|
55
|
+
authorizationEndpoint: "https://auth.atlassian.com/authorize",
|
|
56
|
+
scopes: _scopes,
|
|
57
|
+
state,
|
|
58
|
+
codeVerifier,
|
|
59
|
+
redirectURI,
|
|
60
|
+
additionalParams: {
|
|
61
|
+
audience: "api.atlassian.com",
|
|
62
|
+
},
|
|
63
|
+
prompt: options.prompt,
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
|
|
68
|
+
return validateAuthorizationCode({
|
|
69
|
+
code,
|
|
70
|
+
codeVerifier,
|
|
71
|
+
redirectURI,
|
|
72
|
+
options,
|
|
73
|
+
tokenEndpoint: "https://auth.atlassian.com/oauth/token",
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
refreshAccessToken: options.refreshAccessToken
|
|
78
|
+
? options.refreshAccessToken
|
|
79
|
+
: async (refreshToken) => {
|
|
80
|
+
return refreshAccessToken({
|
|
81
|
+
refreshToken,
|
|
82
|
+
options: {
|
|
83
|
+
clientId: options.clientId,
|
|
84
|
+
clientSecret: options.clientSecret,
|
|
85
|
+
},
|
|
86
|
+
tokenEndpoint: "https://auth.atlassian.com/oauth/token",
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
async getUserInfo(token) {
|
|
91
|
+
if (options.getUserInfo) {
|
|
92
|
+
return options.getUserInfo(token);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!token.accessToken) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const { data: profile } = await betterFetch<{
|
|
101
|
+
account_id: string;
|
|
102
|
+
name: string;
|
|
103
|
+
email?: string | undefined;
|
|
104
|
+
picture?: string | undefined;
|
|
105
|
+
}>("https://api.atlassian.com/me", {
|
|
106
|
+
headers: { Authorization: `Bearer ${token.accessToken}` },
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
if (!profile) return null;
|
|
110
|
+
|
|
111
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
user: {
|
|
115
|
+
id: profile.account_id,
|
|
116
|
+
name: profile.name,
|
|
117
|
+
email: profile.email,
|
|
118
|
+
image: profile.picture,
|
|
119
|
+
emailVerified: false,
|
|
120
|
+
...userMap,
|
|
121
|
+
},
|
|
122
|
+
data: profile,
|
|
123
|
+
};
|
|
124
|
+
} catch (error) {
|
|
125
|
+
logger.error("Failed to fetch user info from Figma:", error);
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
options,
|
|
131
|
+
} satisfies OAuthProvider<AtlassianProfile>;
|
|
132
|
+
};
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import { decodeJwt, decodeProtectedHeader, importJWK, jwtVerify } from "jose";
|
|
3
|
+
import { logger } from "../env";
|
|
4
|
+
import { APIError, BetterAuthError } from "../error";
|
|
5
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
6
|
+
import {
|
|
7
|
+
createAuthorizationURL,
|
|
8
|
+
refreshAccessToken,
|
|
9
|
+
validateAuthorizationCode,
|
|
10
|
+
} from "../oauth2";
|
|
11
|
+
|
|
12
|
+
export interface CognitoProfile {
|
|
13
|
+
sub: string;
|
|
14
|
+
email: string;
|
|
15
|
+
email_verified: boolean;
|
|
16
|
+
name: string;
|
|
17
|
+
given_name?: string | undefined;
|
|
18
|
+
family_name?: string | undefined;
|
|
19
|
+
picture?: string | undefined;
|
|
20
|
+
username?: string | undefined;
|
|
21
|
+
locale?: string | undefined;
|
|
22
|
+
phone_number?: string | undefined;
|
|
23
|
+
phone_number_verified?: boolean | undefined;
|
|
24
|
+
aud: string;
|
|
25
|
+
iss: string;
|
|
26
|
+
exp: number;
|
|
27
|
+
iat: number;
|
|
28
|
+
// Custom attributes from Cognito can be added here
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CognitoOptions extends ProviderOptions<CognitoProfile> {
|
|
33
|
+
clientId: string;
|
|
34
|
+
/**
|
|
35
|
+
* The Cognito domain (e.g., "your-app.auth.us-east-1.amazoncognito.com")
|
|
36
|
+
*/
|
|
37
|
+
domain: string;
|
|
38
|
+
/**
|
|
39
|
+
* AWS region where User Pool is hosted (e.g., "us-east-1")
|
|
40
|
+
*/
|
|
41
|
+
region: string;
|
|
42
|
+
userPoolId: string;
|
|
43
|
+
requireClientSecret?: boolean | undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const cognito = (options: CognitoOptions) => {
|
|
47
|
+
if (!options.domain || !options.region || !options.userPoolId) {
|
|
48
|
+
logger.error(
|
|
49
|
+
"Domain, region and userPoolId are required for Amazon Cognito. Make sure to provide them in the options.",
|
|
50
|
+
);
|
|
51
|
+
throw new BetterAuthError("DOMAIN_AND_REGION_REQUIRED");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const cleanDomain = options.domain.replace(/^https?:\/\//, "");
|
|
55
|
+
const authorizationEndpoint = `https://${cleanDomain}/oauth2/authorize`;
|
|
56
|
+
const tokenEndpoint = `https://${cleanDomain}/oauth2/token`;
|
|
57
|
+
const userInfoEndpoint = `https://${cleanDomain}/oauth2/userinfo`;
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
id: "cognito",
|
|
61
|
+
name: "Cognito",
|
|
62
|
+
async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
|
|
63
|
+
if (!options.clientId) {
|
|
64
|
+
logger.error(
|
|
65
|
+
"ClientId is required for Amazon Cognito. Make sure to provide them in the options.",
|
|
66
|
+
);
|
|
67
|
+
throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (options.requireClientSecret && !options.clientSecret) {
|
|
71
|
+
logger.error(
|
|
72
|
+
"Client Secret is required when requireClientSecret is true. Make sure to provide it in the options.",
|
|
73
|
+
);
|
|
74
|
+
throw new BetterAuthError("CLIENT_SECRET_REQUIRED");
|
|
75
|
+
}
|
|
76
|
+
const _scopes = options.disableDefaultScope
|
|
77
|
+
? []
|
|
78
|
+
: ["openid", "profile", "email"];
|
|
79
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
80
|
+
if (scopes) _scopes.push(...scopes);
|
|
81
|
+
|
|
82
|
+
const url = await createAuthorizationURL({
|
|
83
|
+
id: "cognito",
|
|
84
|
+
options: {
|
|
85
|
+
...options,
|
|
86
|
+
},
|
|
87
|
+
authorizationEndpoint,
|
|
88
|
+
scopes: _scopes,
|
|
89
|
+
state,
|
|
90
|
+
codeVerifier,
|
|
91
|
+
redirectURI,
|
|
92
|
+
prompt: options.prompt,
|
|
93
|
+
});
|
|
94
|
+
// AWS Cognito requires scopes to be encoded with %20 instead of +
|
|
95
|
+
// URLSearchParams encodes spaces as + by default, so we need to fix this
|
|
96
|
+
const scopeValue = url.searchParams.get("scope");
|
|
97
|
+
if (scopeValue) {
|
|
98
|
+
url.searchParams.delete("scope");
|
|
99
|
+
const encodedScope = encodeURIComponent(scopeValue);
|
|
100
|
+
// Manually append the scope with proper encoding to the URL
|
|
101
|
+
const urlString = url.toString();
|
|
102
|
+
const separator = urlString.includes("?") ? "&" : "?";
|
|
103
|
+
return new URL(`${urlString}${separator}scope=${encodedScope}`);
|
|
104
|
+
}
|
|
105
|
+
return url;
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
|
|
109
|
+
return validateAuthorizationCode({
|
|
110
|
+
code,
|
|
111
|
+
codeVerifier,
|
|
112
|
+
redirectURI,
|
|
113
|
+
options,
|
|
114
|
+
tokenEndpoint,
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
refreshAccessToken: options.refreshAccessToken
|
|
119
|
+
? options.refreshAccessToken
|
|
120
|
+
: async (refreshToken) => {
|
|
121
|
+
return refreshAccessToken({
|
|
122
|
+
refreshToken,
|
|
123
|
+
options: {
|
|
124
|
+
clientId: options.clientId,
|
|
125
|
+
clientKey: options.clientKey,
|
|
126
|
+
clientSecret: options.clientSecret,
|
|
127
|
+
},
|
|
128
|
+
tokenEndpoint,
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
async verifyIdToken(token, nonce) {
|
|
133
|
+
if (options.disableIdTokenSignIn) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
if (options.verifyIdToken) {
|
|
137
|
+
return options.verifyIdToken(token, nonce);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
const decodedHeader = decodeProtectedHeader(token);
|
|
142
|
+
const { kid, alg: jwtAlg } = decodedHeader;
|
|
143
|
+
if (!kid || !jwtAlg) return false;
|
|
144
|
+
|
|
145
|
+
const publicKey = await getCognitoPublicKey(
|
|
146
|
+
kid,
|
|
147
|
+
options.region,
|
|
148
|
+
options.userPoolId,
|
|
149
|
+
);
|
|
150
|
+
const expectedIssuer = `https://cognito-idp.${options.region}.amazonaws.com/${options.userPoolId}`;
|
|
151
|
+
|
|
152
|
+
const { payload: jwtClaims } = await jwtVerify(token, publicKey, {
|
|
153
|
+
algorithms: [jwtAlg],
|
|
154
|
+
issuer: expectedIssuer,
|
|
155
|
+
audience: options.clientId,
|
|
156
|
+
maxTokenAge: "1h",
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
if (nonce && jwtClaims.nonce !== nonce) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
return true;
|
|
163
|
+
} catch (error) {
|
|
164
|
+
logger.error("Failed to verify ID token:", error);
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
async getUserInfo(token) {
|
|
170
|
+
if (options.getUserInfo) {
|
|
171
|
+
return options.getUserInfo(token);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (token.idToken) {
|
|
175
|
+
try {
|
|
176
|
+
const profile = decodeJwt<CognitoProfile>(token.idToken);
|
|
177
|
+
if (!profile) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
const name =
|
|
181
|
+
profile.name ||
|
|
182
|
+
profile.given_name ||
|
|
183
|
+
profile.username ||
|
|
184
|
+
profile.email;
|
|
185
|
+
const enrichedProfile = {
|
|
186
|
+
...profile,
|
|
187
|
+
name,
|
|
188
|
+
};
|
|
189
|
+
const userMap = await options.mapProfileToUser?.(enrichedProfile);
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
user: {
|
|
193
|
+
id: profile.sub,
|
|
194
|
+
name: enrichedProfile.name,
|
|
195
|
+
email: profile.email,
|
|
196
|
+
image: profile.picture,
|
|
197
|
+
emailVerified: profile.email_verified,
|
|
198
|
+
...userMap,
|
|
199
|
+
},
|
|
200
|
+
data: enrichedProfile,
|
|
201
|
+
};
|
|
202
|
+
} catch (error) {
|
|
203
|
+
logger.error("Failed to decode ID token:", error);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (token.accessToken) {
|
|
208
|
+
try {
|
|
209
|
+
const { data: userInfo } = await betterFetch<CognitoProfile>(
|
|
210
|
+
userInfoEndpoint,
|
|
211
|
+
{
|
|
212
|
+
headers: {
|
|
213
|
+
Authorization: `Bearer ${token.accessToken}`,
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
if (userInfo) {
|
|
219
|
+
const userMap = await options.mapProfileToUser?.(userInfo);
|
|
220
|
+
return {
|
|
221
|
+
user: {
|
|
222
|
+
id: userInfo.sub,
|
|
223
|
+
name: userInfo.name || userInfo.given_name || userInfo.username,
|
|
224
|
+
email: userInfo.email,
|
|
225
|
+
image: userInfo.picture,
|
|
226
|
+
emailVerified: userInfo.email_verified,
|
|
227
|
+
...userMap,
|
|
228
|
+
},
|
|
229
|
+
data: userInfo,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
} catch (error) {
|
|
233
|
+
logger.error("Failed to fetch user info from Cognito:", error);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return null;
|
|
238
|
+
},
|
|
239
|
+
|
|
240
|
+
options,
|
|
241
|
+
} satisfies OAuthProvider<CognitoProfile>;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export const getCognitoPublicKey = async (
|
|
245
|
+
kid: string,
|
|
246
|
+
region: string,
|
|
247
|
+
userPoolId: string,
|
|
248
|
+
) => {
|
|
249
|
+
const COGNITO_JWKS_URI = `https://cognito-idp.${region}.amazonaws.com/${userPoolId}/.well-known/jwks.json`;
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
const { data } = await betterFetch<{
|
|
253
|
+
keys: Array<{
|
|
254
|
+
kid: string;
|
|
255
|
+
alg: string;
|
|
256
|
+
kty: string;
|
|
257
|
+
use: string;
|
|
258
|
+
n: string;
|
|
259
|
+
e: string;
|
|
260
|
+
}>;
|
|
261
|
+
}>(COGNITO_JWKS_URI);
|
|
262
|
+
|
|
263
|
+
if (!data?.keys) {
|
|
264
|
+
throw new APIError("BAD_REQUEST", {
|
|
265
|
+
message: "Keys not found",
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const jwk = data.keys.find((key) => key.kid === kid);
|
|
270
|
+
if (!jwk) {
|
|
271
|
+
throw new Error(`JWK with kid ${kid} not found`);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return await importJWK(jwk, jwk.alg);
|
|
275
|
+
} catch (error) {
|
|
276
|
+
logger.error("Failed to fetch Cognito public key:", error);
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
};
|