@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,198 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
3
|
+
import {
|
|
4
|
+
createAuthorizationURL,
|
|
5
|
+
refreshAccessToken,
|
|
6
|
+
validateAuthorizationCode,
|
|
7
|
+
} from "../oauth2";
|
|
8
|
+
|
|
9
|
+
export interface TwitterProfile {
|
|
10
|
+
data: {
|
|
11
|
+
/**
|
|
12
|
+
* Unique identifier of this user. This is returned as a string in order to avoid complications with languages and tools
|
|
13
|
+
* that cannot handle large integers.
|
|
14
|
+
*/
|
|
15
|
+
id: string;
|
|
16
|
+
/** The friendly name of this user, as shown on their profile. */
|
|
17
|
+
name: string;
|
|
18
|
+
/** The email address of this user. */
|
|
19
|
+
email?: string | undefined;
|
|
20
|
+
/** The Twitter handle (screen name) of this user. */
|
|
21
|
+
username: string;
|
|
22
|
+
/**
|
|
23
|
+
* The location specified in the user's profile, if the user provided one.
|
|
24
|
+
* As this is a freeform value, it may not indicate a valid location, but it may be fuzzily evaluated when performing searches with location queries.
|
|
25
|
+
*
|
|
26
|
+
* To return this field, add `user.fields=location` in the authorization request's query parameter.
|
|
27
|
+
*/
|
|
28
|
+
location?: string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* This object and its children fields contain details about text that has a special meaning in the user's description.
|
|
31
|
+
*
|
|
32
|
+
*To return this field, add `user.fields=entities` in the authorization request's query parameter.
|
|
33
|
+
*/
|
|
34
|
+
entities?:
|
|
35
|
+
| {
|
|
36
|
+
/** Contains details about the user's profile website. */
|
|
37
|
+
url: {
|
|
38
|
+
/** Contains details about the user's profile website. */
|
|
39
|
+
urls: Array<{
|
|
40
|
+
/** The start position (zero-based) of the recognized user's profile website. All start indices are inclusive. */
|
|
41
|
+
start: number;
|
|
42
|
+
/** The end position (zero-based) of the recognized user's profile website. This end index is exclusive. */
|
|
43
|
+
end: number;
|
|
44
|
+
/** The URL in the format entered by the user. */
|
|
45
|
+
url: string;
|
|
46
|
+
/** The fully resolved URL. */
|
|
47
|
+
expanded_url: string;
|
|
48
|
+
/** The URL as displayed in the user's profile. */
|
|
49
|
+
display_url: string;
|
|
50
|
+
}>;
|
|
51
|
+
};
|
|
52
|
+
/** Contains details about URLs, Hashtags, Cashtags, or mentions located within a user's description. */
|
|
53
|
+
description: {
|
|
54
|
+
hashtags: Array<{
|
|
55
|
+
start: number;
|
|
56
|
+
end: number;
|
|
57
|
+
tag: string;
|
|
58
|
+
}>;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
| undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Indicate if this user is a verified Twitter user.
|
|
64
|
+
*
|
|
65
|
+
* To return this field, add `user.fields=verified` in the authorization request's query parameter.
|
|
66
|
+
*/
|
|
67
|
+
verified?: boolean | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* The text of this user's profile description (also known as bio), if the user provided one.
|
|
70
|
+
*
|
|
71
|
+
* To return this field, add `user.fields=description` in the authorization request's query parameter.
|
|
72
|
+
*/
|
|
73
|
+
description?: string | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* The URL specified in the user's profile, if present.
|
|
76
|
+
*
|
|
77
|
+
* To return this field, add `user.fields=url` in the authorization request's query parameter.
|
|
78
|
+
*/
|
|
79
|
+
url?: string | undefined;
|
|
80
|
+
/** The URL to the profile image for this user, as shown on the user's profile. */
|
|
81
|
+
profile_image_url?: string | undefined;
|
|
82
|
+
protected?: boolean | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Unique identifier of this user's pinned Tweet.
|
|
85
|
+
*
|
|
86
|
+
* You can obtain the expanded object in `includes.tweets` by adding `expansions=pinned_tweet_id` in the authorization request's query parameter.
|
|
87
|
+
*/
|
|
88
|
+
pinned_tweet_id?: string | undefined;
|
|
89
|
+
created_at?: string | undefined;
|
|
90
|
+
};
|
|
91
|
+
includes?:
|
|
92
|
+
| {
|
|
93
|
+
tweets?: Array<{
|
|
94
|
+
id: string;
|
|
95
|
+
text: string;
|
|
96
|
+
}>;
|
|
97
|
+
}
|
|
98
|
+
| undefined;
|
|
99
|
+
[claims: string]: unknown;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface TwitterOption extends ProviderOptions<TwitterProfile> {
|
|
103
|
+
clientId: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export const twitter = (options: TwitterOption) => {
|
|
107
|
+
return {
|
|
108
|
+
id: "twitter",
|
|
109
|
+
name: "Twitter",
|
|
110
|
+
createAuthorizationURL(data) {
|
|
111
|
+
const _scopes = options.disableDefaultScope
|
|
112
|
+
? []
|
|
113
|
+
: ["users.read", "tweet.read", "offline.access", "users.email"];
|
|
114
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
115
|
+
if (data.scopes) _scopes.push(...data.scopes);
|
|
116
|
+
return createAuthorizationURL({
|
|
117
|
+
id: "twitter",
|
|
118
|
+
options,
|
|
119
|
+
authorizationEndpoint: "https://x.com/i/oauth2/authorize",
|
|
120
|
+
scopes: _scopes,
|
|
121
|
+
state: data.state,
|
|
122
|
+
codeVerifier: data.codeVerifier,
|
|
123
|
+
redirectURI: data.redirectURI,
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
|
|
127
|
+
return validateAuthorizationCode({
|
|
128
|
+
code,
|
|
129
|
+
codeVerifier,
|
|
130
|
+
authentication: "basic",
|
|
131
|
+
redirectURI,
|
|
132
|
+
options,
|
|
133
|
+
tokenEndpoint: "https://api.x.com/2/oauth2/token",
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
refreshAccessToken: options.refreshAccessToken
|
|
138
|
+
? options.refreshAccessToken
|
|
139
|
+
: async (refreshToken) => {
|
|
140
|
+
return refreshAccessToken({
|
|
141
|
+
refreshToken,
|
|
142
|
+
options: {
|
|
143
|
+
clientId: options.clientId,
|
|
144
|
+
clientKey: options.clientKey,
|
|
145
|
+
clientSecret: options.clientSecret,
|
|
146
|
+
},
|
|
147
|
+
authentication: "basic",
|
|
148
|
+
tokenEndpoint: "https://api.x.com/2/oauth2/token",
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
async getUserInfo(token) {
|
|
152
|
+
if (options.getUserInfo) {
|
|
153
|
+
return options.getUserInfo(token);
|
|
154
|
+
}
|
|
155
|
+
const { data: profile, error: profileError } =
|
|
156
|
+
await betterFetch<TwitterProfile>(
|
|
157
|
+
"https://api.x.com/2/users/me?user.fields=profile_image_url",
|
|
158
|
+
{
|
|
159
|
+
method: "GET",
|
|
160
|
+
headers: {
|
|
161
|
+
Authorization: `Bearer ${token.accessToken}`,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
if (profileError) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const { data: emailData, error: emailError } = await betterFetch<{
|
|
171
|
+
data: { confirmed_email: string };
|
|
172
|
+
}>("https://api.x.com/2/users/me?user.fields=confirmed_email", {
|
|
173
|
+
method: "GET",
|
|
174
|
+
headers: {
|
|
175
|
+
Authorization: `Bearer ${token.accessToken}`,
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
let emailVerified = false;
|
|
179
|
+
if (!emailError && emailData?.data?.confirmed_email) {
|
|
180
|
+
profile.data.email = emailData.data.confirmed_email;
|
|
181
|
+
emailVerified = true;
|
|
182
|
+
}
|
|
183
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
184
|
+
return {
|
|
185
|
+
user: {
|
|
186
|
+
id: profile.data.id,
|
|
187
|
+
name: profile.data.name,
|
|
188
|
+
email: profile.data.email || profile.data.username || null,
|
|
189
|
+
image: profile.data.profile_image_url,
|
|
190
|
+
emailVerified: emailVerified,
|
|
191
|
+
...userMap,
|
|
192
|
+
},
|
|
193
|
+
data: profile,
|
|
194
|
+
};
|
|
195
|
+
},
|
|
196
|
+
options,
|
|
197
|
+
} satisfies OAuthProvider<TwitterProfile>;
|
|
198
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import { BetterAuthError } from "../error";
|
|
3
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
4
|
+
import { createAuthorizationURL, validateAuthorizationCode } from "../oauth2";
|
|
5
|
+
|
|
6
|
+
export interface VercelProfile {
|
|
7
|
+
sub: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
preferred_username?: string;
|
|
10
|
+
email?: string;
|
|
11
|
+
email_verified?: boolean;
|
|
12
|
+
picture?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface VercelOptions extends ProviderOptions<VercelProfile> {
|
|
16
|
+
clientId: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const vercel = (options: VercelOptions) => {
|
|
20
|
+
return {
|
|
21
|
+
id: "vercel",
|
|
22
|
+
name: "Vercel",
|
|
23
|
+
createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
|
|
24
|
+
if (!codeVerifier) {
|
|
25
|
+
throw new BetterAuthError("codeVerifier is required for Vercel");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let _scopes: string[] | undefined = undefined;
|
|
29
|
+
if (options.scope !== undefined || scopes !== undefined) {
|
|
30
|
+
_scopes = [];
|
|
31
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
32
|
+
if (scopes) _scopes.push(...scopes);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return createAuthorizationURL({
|
|
36
|
+
id: "vercel",
|
|
37
|
+
options,
|
|
38
|
+
authorizationEndpoint: "https://vercel.com/oauth/authorize",
|
|
39
|
+
scopes: _scopes,
|
|
40
|
+
state,
|
|
41
|
+
codeVerifier,
|
|
42
|
+
redirectURI,
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
|
|
46
|
+
return validateAuthorizationCode({
|
|
47
|
+
code,
|
|
48
|
+
codeVerifier,
|
|
49
|
+
redirectURI,
|
|
50
|
+
options,
|
|
51
|
+
tokenEndpoint: "https://api.vercel.com/login/oauth/token",
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
async getUserInfo(token) {
|
|
55
|
+
if (options.getUserInfo) {
|
|
56
|
+
return options.getUserInfo(token);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const { data: profile, error } = await betterFetch<VercelProfile>(
|
|
60
|
+
"https://api.vercel.com/login/oauth/userinfo",
|
|
61
|
+
{
|
|
62
|
+
headers: {
|
|
63
|
+
Authorization: `Bearer ${token.accessToken}`,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
if (error || !profile) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
73
|
+
return {
|
|
74
|
+
user: {
|
|
75
|
+
id: profile.sub,
|
|
76
|
+
name: profile.name ?? profile.preferred_username,
|
|
77
|
+
email: profile.email,
|
|
78
|
+
image: profile.picture,
|
|
79
|
+
emailVerified: profile.email_verified ?? false,
|
|
80
|
+
...userMap,
|
|
81
|
+
},
|
|
82
|
+
data: profile,
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
options,
|
|
86
|
+
} satisfies OAuthProvider<VercelProfile>;
|
|
87
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
3
|
+
import {
|
|
4
|
+
createAuthorizationURL,
|
|
5
|
+
refreshAccessToken,
|
|
6
|
+
validateAuthorizationCode,
|
|
7
|
+
} from "../oauth2";
|
|
8
|
+
|
|
9
|
+
export interface VkProfile {
|
|
10
|
+
user: {
|
|
11
|
+
user_id: string;
|
|
12
|
+
first_name: string;
|
|
13
|
+
last_name: string;
|
|
14
|
+
email?: string | undefined;
|
|
15
|
+
phone?: number | undefined;
|
|
16
|
+
avatar?: string | undefined;
|
|
17
|
+
sex?: number | undefined;
|
|
18
|
+
verified?: boolean | undefined;
|
|
19
|
+
birthday: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface VkOption extends ProviderOptions {
|
|
24
|
+
clientId: string;
|
|
25
|
+
scheme?: ("light" | "dark") | undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const vk = (options: VkOption) => {
|
|
29
|
+
return {
|
|
30
|
+
id: "vk",
|
|
31
|
+
name: "VK",
|
|
32
|
+
async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
|
|
33
|
+
const _scopes = options.disableDefaultScope ? [] : ["email", "phone"];
|
|
34
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
35
|
+
if (scopes) _scopes.push(...scopes);
|
|
36
|
+
const authorizationEndpoint = "https://id.vk.com/authorize";
|
|
37
|
+
|
|
38
|
+
return createAuthorizationURL({
|
|
39
|
+
id: "vk",
|
|
40
|
+
options,
|
|
41
|
+
authorizationEndpoint,
|
|
42
|
+
scopes: _scopes,
|
|
43
|
+
state,
|
|
44
|
+
redirectURI,
|
|
45
|
+
codeVerifier,
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
validateAuthorizationCode: async ({
|
|
49
|
+
code,
|
|
50
|
+
codeVerifier,
|
|
51
|
+
redirectURI,
|
|
52
|
+
deviceId,
|
|
53
|
+
}) => {
|
|
54
|
+
return validateAuthorizationCode({
|
|
55
|
+
code,
|
|
56
|
+
codeVerifier,
|
|
57
|
+
redirectURI: options.redirectURI || redirectURI,
|
|
58
|
+
options,
|
|
59
|
+
deviceId,
|
|
60
|
+
tokenEndpoint: "https://id.vk.com/oauth2/auth",
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
refreshAccessToken: options.refreshAccessToken
|
|
64
|
+
? options.refreshAccessToken
|
|
65
|
+
: async (refreshToken) => {
|
|
66
|
+
return refreshAccessToken({
|
|
67
|
+
refreshToken,
|
|
68
|
+
options: {
|
|
69
|
+
clientId: options.clientId,
|
|
70
|
+
clientKey: options.clientKey,
|
|
71
|
+
clientSecret: options.clientSecret,
|
|
72
|
+
},
|
|
73
|
+
tokenEndpoint: "https://id.vk.com/oauth2/auth",
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
async getUserInfo(data) {
|
|
77
|
+
if (options.getUserInfo) {
|
|
78
|
+
return options.getUserInfo(data);
|
|
79
|
+
}
|
|
80
|
+
if (!data.accessToken) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const formBody = new URLSearchParams({
|
|
84
|
+
access_token: data.accessToken,
|
|
85
|
+
client_id: options.clientId,
|
|
86
|
+
}).toString();
|
|
87
|
+
const { data: profile, error } = await betterFetch<VkProfile>(
|
|
88
|
+
"https://id.vk.com/oauth2/user_info",
|
|
89
|
+
{
|
|
90
|
+
method: "POST",
|
|
91
|
+
headers: {
|
|
92
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
93
|
+
},
|
|
94
|
+
body: formBody,
|
|
95
|
+
},
|
|
96
|
+
);
|
|
97
|
+
if (error) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
102
|
+
if (!profile.user.email && !userMap?.email) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
user: {
|
|
108
|
+
id: profile.user.user_id,
|
|
109
|
+
first_name: profile.user.first_name,
|
|
110
|
+
last_name: profile.user.last_name,
|
|
111
|
+
email: profile.user.email,
|
|
112
|
+
image: profile.user.avatar,
|
|
113
|
+
emailVerified: false,
|
|
114
|
+
birthday: profile.user.birthday,
|
|
115
|
+
sex: profile.user.sex,
|
|
116
|
+
name: `${profile.user.first_name} ${profile.user.last_name}`,
|
|
117
|
+
...userMap,
|
|
118
|
+
},
|
|
119
|
+
data: profile,
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
options,
|
|
123
|
+
} satisfies OAuthProvider<VkProfile>;
|
|
124
|
+
};
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
import type { OAuthProvider, ProviderOptions } from "../oauth2";
|
|
3
|
+
import {
|
|
4
|
+
generateCodeChallenge,
|
|
5
|
+
refreshAccessToken,
|
|
6
|
+
validateAuthorizationCode,
|
|
7
|
+
} from "../oauth2";
|
|
8
|
+
|
|
9
|
+
export type LoginType =
|
|
10
|
+
| 0 /** Facebook OAuth */
|
|
11
|
+
| 1 /** Google OAuth */
|
|
12
|
+
| 24 /** Apple OAuth */
|
|
13
|
+
| 27 /** Microsoft OAuth */
|
|
14
|
+
| 97 /** Mobile device */
|
|
15
|
+
| 98 /** RingCentral OAuth */
|
|
16
|
+
| 99 /** API user */
|
|
17
|
+
| 100 /** Zoom Work email */
|
|
18
|
+
| 101; /** Single Sign-On (SSO) */
|
|
19
|
+
|
|
20
|
+
export type AccountStatus = "pending" | "active" | "inactive";
|
|
21
|
+
|
|
22
|
+
export type PronounOption =
|
|
23
|
+
| 1 /** Ask the user every time */
|
|
24
|
+
| 2 /** Always display */
|
|
25
|
+
| 3; /** Do not display */
|
|
26
|
+
|
|
27
|
+
export interface PhoneNumber {
|
|
28
|
+
/** The country code of the phone number (Example: "+1") */
|
|
29
|
+
code: string;
|
|
30
|
+
|
|
31
|
+
/** The country of the phone number (Example: "US") */
|
|
32
|
+
country: string;
|
|
33
|
+
|
|
34
|
+
/** The label for the phone number (Example: "Mobile") */
|
|
35
|
+
label: string;
|
|
36
|
+
|
|
37
|
+
/** The phone number itself (Example: "800000000") */
|
|
38
|
+
number: string;
|
|
39
|
+
|
|
40
|
+
/** Whether the phone number has been verified (Example: true) */
|
|
41
|
+
verified: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* See the full documentation below:
|
|
46
|
+
* https://developers.zoom.us/docs/api/users/#tag/users/GET/users/{userId}
|
|
47
|
+
*/
|
|
48
|
+
export interface ZoomProfile extends Record<string, any> {
|
|
49
|
+
/* cspell:disable-next-line */
|
|
50
|
+
/** The user's account ID (Example: "q6gBJVO5TzexKYTb_I2rpg") */
|
|
51
|
+
account_id: string;
|
|
52
|
+
/** The user's account number (Example: 10009239) */
|
|
53
|
+
account_number: number;
|
|
54
|
+
/** The user's cluster (Example: "us04") */
|
|
55
|
+
cluster: string;
|
|
56
|
+
/** The user's CMS ID. Only enabled for Kaltura integration (Example: "KDcuGIm1QgePTO8WbOqwIQ") */
|
|
57
|
+
cms_user_id: string;
|
|
58
|
+
/** The user's cost center (Example: "cost center") */
|
|
59
|
+
cost_center: string;
|
|
60
|
+
/** User create time (Example: "2018-10-31T04:32:37Z") */
|
|
61
|
+
created_at: string;
|
|
62
|
+
/** Department (Example: "Developers") */
|
|
63
|
+
dept: string;
|
|
64
|
+
/** User's display name (Example: "Jill Chill") */
|
|
65
|
+
display_name: string;
|
|
66
|
+
/** User's email address (Example: "jchill@example.com") */
|
|
67
|
+
email: string;
|
|
68
|
+
/** User's first name (Example: "Jill") */
|
|
69
|
+
first_name: string;
|
|
70
|
+
/* cspell:disable-next-line */
|
|
71
|
+
/** IDs of the web groups that the user belongs to (Example: ["RSMaSp8sTEGK0_oamiA2_w"]) */
|
|
72
|
+
group_ids: string[];
|
|
73
|
+
/* cspell:disable-next-line */
|
|
74
|
+
/** User ID (Example: "zJKyaiAyTNC-MWjiWC18KQ") */
|
|
75
|
+
id: string;
|
|
76
|
+
/* cspell:disable-next-line */
|
|
77
|
+
/** IM IDs of the groups that the user belongs to (Example: ["t-_-d56CSWG-7BF15LLrOw"]) */
|
|
78
|
+
im_group_ids: string[];
|
|
79
|
+
/** The user's JID (Example: "jchill@example.com") */
|
|
80
|
+
jid: string;
|
|
81
|
+
/** The user's job title (Example: "API Developer") */
|
|
82
|
+
job_title: string;
|
|
83
|
+
/** Default language for the Zoom Web Portal (Example: "en-US") */
|
|
84
|
+
language: string;
|
|
85
|
+
/** User last login client version (Example: "5.9.6.4993(mac)") */
|
|
86
|
+
last_client_version: string;
|
|
87
|
+
/** User last login time (Example: "2021-05-05T20:40:30Z") */
|
|
88
|
+
last_login_time: string;
|
|
89
|
+
/** User's last name (Example: "Chill") */
|
|
90
|
+
last_name: string;
|
|
91
|
+
/** The time zone of the user (Example: "Asia/Shanghai") */
|
|
92
|
+
timezone: string;
|
|
93
|
+
/** User's location (Example: "Paris") */
|
|
94
|
+
location: string;
|
|
95
|
+
/** The user's login method (Example: 101) */
|
|
96
|
+
login_types: LoginType[];
|
|
97
|
+
/** User's personal meeting URL (Example: "example.com") */
|
|
98
|
+
personal_meeting_url: string;
|
|
99
|
+
/** This field has been deprecated and will not be supported in the future.
|
|
100
|
+
* Use the phone_numbers field instead of this field.
|
|
101
|
+
* The user's phone number (Example: "+1 800000000") */
|
|
102
|
+
// @deprecated true
|
|
103
|
+
phone_number?: string | undefined;
|
|
104
|
+
/** The URL for user's profile picture (Example: "example.com") */
|
|
105
|
+
pic_url: string;
|
|
106
|
+
/** Personal Meeting ID (PMI) (Example: 3542471135) */
|
|
107
|
+
pmi: number;
|
|
108
|
+
/** Unique identifier of the user's assigned role (Example: "0") */
|
|
109
|
+
role_id: string;
|
|
110
|
+
/** User's role name (Example: "Admin") */
|
|
111
|
+
role_name: string;
|
|
112
|
+
/** Status of user's account (Example: "pending") */
|
|
113
|
+
status: AccountStatus;
|
|
114
|
+
/** Use the personal meeting ID (PMI) for instant meetings (Example: false) */
|
|
115
|
+
use_pmi: boolean;
|
|
116
|
+
/** The time and date when the user was created (Example: "2018-10-31T04:32:37Z") */
|
|
117
|
+
user_created_at: string;
|
|
118
|
+
/** Displays whether user is verified or not (Example: 1) */
|
|
119
|
+
verified: number;
|
|
120
|
+
/** The user's Zoom Workplace plan option (Example: 64) */
|
|
121
|
+
zoom_one_type: number;
|
|
122
|
+
/** The user's company (Example: "Jill") */
|
|
123
|
+
company?: string | undefined;
|
|
124
|
+
/* cspell:disable-next-line */
|
|
125
|
+
/** Custom attributes that have been assigned to the user (Example: [{ "key": "cbf_cywdkexrtqc73f97gd4w6g", "name": "A1", "value": "1" }]) */
|
|
126
|
+
custom_attributes?:
|
|
127
|
+
| { key: string; name: string; value: string }[]
|
|
128
|
+
| undefined;
|
|
129
|
+
/* cspell:disable-next-line */
|
|
130
|
+
/** The employee's unique ID. This field only returns when SAML single sign-on (SSO) is enabled. The `login_type` value is `101` (SSO) (Example: "HqDyI037Qjili1kNsSIrIg") */
|
|
131
|
+
employee_unique_id?: string | undefined;
|
|
132
|
+
/** The manager for the user (Example: "thill@example.com") */
|
|
133
|
+
manager?: string | undefined;
|
|
134
|
+
/** The user's country for the company phone number (Example: "US")
|
|
135
|
+
* @deprecated true */
|
|
136
|
+
phone_country?: string | undefined;
|
|
137
|
+
/** The phone number's ISO country code (Example: "+1") */
|
|
138
|
+
phone_numbers?: PhoneNumber[] | undefined;
|
|
139
|
+
/** The user's plan type (Example: "1") */
|
|
140
|
+
plan_united_type?: string | undefined;
|
|
141
|
+
/** The user's pronouns (Example: "3123") */
|
|
142
|
+
pronouns?: string | undefined;
|
|
143
|
+
/** The user's display pronouns setting (Example: 1) */
|
|
144
|
+
pronouns_option?: PronounOption | undefined;
|
|
145
|
+
/** Personal meeting room URL, if the user has one (Example: "example.com") */
|
|
146
|
+
vanity_url?: string | undefined;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface ZoomOptions extends ProviderOptions<ZoomProfile> {
|
|
150
|
+
clientId: string;
|
|
151
|
+
pkce?: boolean | undefined;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export const zoom = (userOptions: ZoomOptions) => {
|
|
155
|
+
const options = {
|
|
156
|
+
pkce: true,
|
|
157
|
+
...userOptions,
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
id: "zoom",
|
|
162
|
+
name: "Zoom",
|
|
163
|
+
createAuthorizationURL: async ({ state, redirectURI, codeVerifier }) => {
|
|
164
|
+
const params = new URLSearchParams({
|
|
165
|
+
response_type: "code",
|
|
166
|
+
redirect_uri: options.redirectURI ? options.redirectURI : redirectURI,
|
|
167
|
+
client_id: options.clientId,
|
|
168
|
+
state,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
if (options.pkce) {
|
|
172
|
+
const codeChallenge = await generateCodeChallenge(codeVerifier);
|
|
173
|
+
params.set("code_challenge_method", "S256");
|
|
174
|
+
params.set("code_challenge", codeChallenge);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const url = new URL("https://zoom.us/oauth/authorize");
|
|
178
|
+
url.search = params.toString();
|
|
179
|
+
|
|
180
|
+
return url;
|
|
181
|
+
},
|
|
182
|
+
validateAuthorizationCode: async ({ code, redirectURI, codeVerifier }) => {
|
|
183
|
+
return validateAuthorizationCode({
|
|
184
|
+
code,
|
|
185
|
+
redirectURI: options.redirectURI || redirectURI,
|
|
186
|
+
codeVerifier,
|
|
187
|
+
options,
|
|
188
|
+
tokenEndpoint: "https://zoom.us/oauth/token",
|
|
189
|
+
authentication: "post",
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
refreshAccessToken: options.refreshAccessToken
|
|
193
|
+
? options.refreshAccessToken
|
|
194
|
+
: async (refreshToken) =>
|
|
195
|
+
refreshAccessToken({
|
|
196
|
+
refreshToken,
|
|
197
|
+
options: {
|
|
198
|
+
clientId: options.clientId,
|
|
199
|
+
clientKey: options.clientKey,
|
|
200
|
+
clientSecret: options.clientSecret,
|
|
201
|
+
},
|
|
202
|
+
tokenEndpoint: "https://zoom.us/oauth/token",
|
|
203
|
+
}),
|
|
204
|
+
async getUserInfo(token) {
|
|
205
|
+
if (options.getUserInfo) {
|
|
206
|
+
return options.getUserInfo(token);
|
|
207
|
+
}
|
|
208
|
+
const { data: profile, error } = await betterFetch<ZoomProfile>(
|
|
209
|
+
"https://api.zoom.us/v2/users/me",
|
|
210
|
+
{
|
|
211
|
+
headers: {
|
|
212
|
+
authorization: `Bearer ${token.accessToken}`,
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
if (error) {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
222
|
+
|
|
223
|
+
return {
|
|
224
|
+
user: {
|
|
225
|
+
id: profile.id,
|
|
226
|
+
name: profile.display_name,
|
|
227
|
+
image: profile.pic_url,
|
|
228
|
+
email: profile.email,
|
|
229
|
+
emailVerified: Boolean(profile.verified),
|
|
230
|
+
...userMap,
|
|
231
|
+
},
|
|
232
|
+
data: {
|
|
233
|
+
...profile,
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
},
|
|
237
|
+
} satisfies OAuthProvider<ZoomProfile>;
|
|
238
|
+
};
|