@depup/better-auth__core 1.6.23-depup.2
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/LICENSE.md +20 -0
- package/README.md +32 -0
- package/changes.json +14 -0
- package/dist/api/index.d.mts +281 -0
- package/dist/api/index.mjs +92 -0
- package/dist/async_hooks/index.d.mts +6 -0
- package/dist/async_hooks/index.mjs +20 -0
- package/dist/async_hooks/pure.index.d.mts +6 -0
- package/dist/async_hooks/pure.index.mjs +33 -0
- package/dist/context/endpoint-context.d.mts +18 -0
- package/dist/context/endpoint-context.mjs +29 -0
- package/dist/context/global.d.mts +6 -0
- package/dist/context/global.mjs +36 -0
- package/dist/context/index.d.mts +5 -0
- package/dist/context/index.mjs +5 -0
- package/dist/context/request-state.d.mts +27 -0
- package/dist/context/request-state.mjs +47 -0
- package/dist/context/transaction.d.mts +27 -0
- package/dist/context/transaction.mjs +96 -0
- package/dist/db/adapter/factory.d.mts +17 -0
- package/dist/db/adapter/factory.mjs +905 -0
- package/dist/db/adapter/get-default-field-name.d.mts +18 -0
- package/dist/db/adapter/get-default-field-name.mjs +36 -0
- package/dist/db/adapter/get-default-model-name.d.mts +12 -0
- package/dist/db/adapter/get-default-model-name.mjs +30 -0
- package/dist/db/adapter/get-field-attributes.d.mts +26 -0
- package/dist/db/adapter/get-field-attributes.mjs +37 -0
- package/dist/db/adapter/get-field-name.d.mts +18 -0
- package/dist/db/adapter/get-field-name.mjs +31 -0
- package/dist/db/adapter/get-id-field.d.mts +36 -0
- package/dist/db/adapter/get-id-field.mjs +64 -0
- package/dist/db/adapter/get-model-name.d.mts +12 -0
- package/dist/db/adapter/get-model-name.mjs +21 -0
- package/dist/db/adapter/index.d.mts +615 -0
- package/dist/db/adapter/index.mjs +24 -0
- package/dist/db/adapter/types.d.mts +105 -0
- package/dist/db/adapter/utils.d.mts +7 -0
- package/dist/db/adapter/utils.mjs +37 -0
- package/dist/db/get-tables.d.mts +6 -0
- package/dist/db/get-tables.mjs +266 -0
- package/dist/db/index.d.mts +10 -0
- package/dist/db/index.mjs +8 -0
- package/dist/db/plugin.d.mts +12 -0
- package/dist/db/schema/account.d.mts +28 -0
- package/dist/db/schema/account.mjs +17 -0
- package/dist/db/schema/rate-limit.d.mts +18 -0
- package/dist/db/schema/rate-limit.mjs +9 -0
- package/dist/db/schema/session.d.mts +23 -0
- package/dist/db/schema/session.mjs +12 -0
- package/dist/db/schema/shared.d.mts +10 -0
- package/dist/db/schema/shared.mjs +9 -0
- package/dist/db/schema/user.d.mts +22 -0
- package/dist/db/schema/user.mjs +11 -0
- package/dist/db/schema/verification.d.mts +21 -0
- package/dist/db/schema/verification.mjs +10 -0
- package/dist/db/type.d.mts +194 -0
- package/dist/env/color-depth.d.mts +4 -0
- package/dist/env/color-depth.mjs +86 -0
- package/dist/env/env-impl.d.mts +32 -0
- package/dist/env/env-impl.mjs +81 -0
- package/dist/env/index.d.mts +4 -0
- package/dist/env/index.mjs +4 -0
- package/dist/env/logger.d.mts +48 -0
- package/dist/env/logger.mjs +79 -0
- package/dist/error/codes.d.mts +69 -0
- package/dist/error/codes.mjs +55 -0
- package/dist/error/index.d.mts +26 -0
- package/dist/error/index.mjs +27 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.mjs +1 -0
- package/dist/instrumentation/api.mjs +12 -0
- package/dist/instrumentation/attributes.d.mts +11 -0
- package/dist/instrumentation/attributes.mjs +10 -0
- package/dist/instrumentation/index.d.mts +3 -0
- package/dist/instrumentation/index.mjs +3 -0
- package/dist/instrumentation/noop.mjs +42 -0
- package/dist/instrumentation/pure.index.d.mts +7 -0
- package/dist/instrumentation/pure.index.mjs +7 -0
- package/dist/instrumentation/tracer.d.mts +13 -0
- package/dist/instrumentation/tracer.mjs +53 -0
- package/dist/oauth2/client-credentials-token.d.mts +56 -0
- package/dist/oauth2/client-credentials-token.mjs +64 -0
- package/dist/oauth2/create-authorization-url.d.mts +44 -0
- package/dist/oauth2/create-authorization-url.mjs +41 -0
- package/dist/oauth2/index.d.mts +8 -0
- package/dist/oauth2/index.mjs +7 -0
- package/dist/oauth2/oauth-provider.d.mts +192 -0
- package/dist/oauth2/refresh-access-token.d.mts +54 -0
- package/dist/oauth2/refresh-access-token.mjs +73 -0
- package/dist/oauth2/reject-redirects.mjs +60 -0
- package/dist/oauth2/utils.d.mts +24 -0
- package/dist/oauth2/utils.mjs +48 -0
- package/dist/oauth2/validate-authorization-code.d.mts +85 -0
- package/dist/oauth2/validate-authorization-code.mjs +86 -0
- package/dist/oauth2/verify.d.mts +65 -0
- package/dist/oauth2/verify.mjs +202 -0
- package/dist/social-providers/apple.d.mts +133 -0
- package/dist/social-providers/apple.mjs +117 -0
- package/dist/social-providers/atlassian.d.mts +70 -0
- package/dist/social-providers/atlassian.mjs +80 -0
- package/dist/social-providers/cognito.d.mts +85 -0
- package/dist/social-providers/cognito.mjs +162 -0
- package/dist/social-providers/discord.d.mts +124 -0
- package/dist/social-providers/discord.mjs +62 -0
- package/dist/social-providers/dropbox.d.mts +69 -0
- package/dist/social-providers/dropbox.mjs +72 -0
- package/dist/social-providers/facebook.d.mts +79 -0
- package/dist/social-providers/facebook.mjs +157 -0
- package/dist/social-providers/figma.d.mts +61 -0
- package/dist/social-providers/figma.mjs +83 -0
- package/dist/social-providers/github.d.mts +102 -0
- package/dist/social-providers/github.mjs +92 -0
- package/dist/social-providers/gitlab.d.mts +123 -0
- package/dist/social-providers/gitlab.mjs +79 -0
- package/dist/social-providers/google.d.mts +123 -0
- package/dist/social-providers/google.mjs +137 -0
- package/dist/social-providers/huggingface.d.mts +83 -0
- package/dist/social-providers/huggingface.mjs +73 -0
- package/dist/social-providers/index.d.mts +1834 -0
- package/dist/social-providers/index.mjs +78 -0
- package/dist/social-providers/kakao.d.mts +161 -0
- package/dist/social-providers/kakao.mjs +70 -0
- package/dist/social-providers/kick.d.mts +73 -0
- package/dist/social-providers/kick.mjs +68 -0
- package/dist/social-providers/line.d.mts +105 -0
- package/dist/social-providers/line.mjs +110 -0
- package/dist/social-providers/linear.d.mts +68 -0
- package/dist/social-providers/linear.mjs +85 -0
- package/dist/social-providers/linkedin.d.mts +67 -0
- package/dist/social-providers/linkedin.mjs +73 -0
- package/dist/social-providers/microsoft-entra-id.d.mts +174 -0
- package/dist/social-providers/microsoft-entra-id.mjs +152 -0
- package/dist/social-providers/naver.d.mts +92 -0
- package/dist/social-providers/naver.mjs +65 -0
- package/dist/social-providers/notion.d.mts +64 -0
- package/dist/social-providers/notion.mjs +72 -0
- package/dist/social-providers/paybin.d.mts +71 -0
- package/dist/social-providers/paybin.mjs +81 -0
- package/dist/social-providers/paypal.d.mts +131 -0
- package/dist/social-providers/paypal.mjs +188 -0
- package/dist/social-providers/polar.d.mts +74 -0
- package/dist/social-providers/polar.mjs +71 -0
- package/dist/social-providers/railway.d.mts +65 -0
- package/dist/social-providers/railway.mjs +74 -0
- package/dist/social-providers/reddit.d.mts +62 -0
- package/dist/social-providers/reddit.mjs +81 -0
- package/dist/social-providers/roblox.d.mts +70 -0
- package/dist/social-providers/roblox.mjs +57 -0
- package/dist/social-providers/salesforce.d.mts +79 -0
- package/dist/social-providers/salesforce.mjs +87 -0
- package/dist/social-providers/slack.d.mts +83 -0
- package/dist/social-providers/slack.mjs +66 -0
- package/dist/social-providers/spotify.d.mts +63 -0
- package/dist/social-providers/spotify.mjs +69 -0
- package/dist/social-providers/tiktok.d.mts +168 -0
- package/dist/social-providers/tiktok.mjs +60 -0
- package/dist/social-providers/twitch.d.mts +79 -0
- package/dist/social-providers/twitch.mjs +75 -0
- package/dist/social-providers/twitter.d.mts +126 -0
- package/dist/social-providers/twitter.mjs +85 -0
- package/dist/social-providers/vercel.d.mts +62 -0
- package/dist/social-providers/vercel.mjs +58 -0
- package/dist/social-providers/vk.d.mts +70 -0
- package/dist/social-providers/vk.mjs +81 -0
- package/dist/social-providers/wechat.d.mts +113 -0
- package/dist/social-providers/wechat.mjs +81 -0
- package/dist/social-providers/zoom.d.mts +163 -0
- package/dist/social-providers/zoom.mjs +69 -0
- package/dist/types/context.d.mts +319 -0
- package/dist/types/cookie.d.mts +15 -0
- package/dist/types/helper.d.mts +10 -0
- package/dist/types/index.d.mts +9 -0
- package/dist/types/init-options.d.mts +1430 -0
- package/dist/types/plugin-client.d.mts +123 -0
- package/dist/types/plugin.d.mts +124 -0
- package/dist/types/secret.d.mts +11 -0
- package/dist/utils/async.d.mts +22 -0
- package/dist/utils/async.mjs +32 -0
- package/dist/utils/db.d.mts +9 -0
- package/dist/utils/db.mjs +15 -0
- package/dist/utils/deprecate.d.mts +9 -0
- package/dist/utils/deprecate.mjs +16 -0
- package/dist/utils/error-codes.d.mts +13 -0
- package/dist/utils/error-codes.mjs +10 -0
- package/dist/utils/fetch-metadata.d.mts +4 -0
- package/dist/utils/fetch-metadata.mjs +6 -0
- package/dist/utils/host.d.mts +147 -0
- package/dist/utils/host.mjs +295 -0
- package/dist/utils/id.d.mts +4 -0
- package/dist/utils/id.mjs +7 -0
- package/dist/utils/ip.d.mts +77 -0
- package/dist/utils/ip.mjs +230 -0
- package/dist/utils/is-api-error.d.mts +6 -0
- package/dist/utils/is-api-error.mjs +8 -0
- package/dist/utils/json.d.mts +4 -0
- package/dist/utils/json.mjs +41 -0
- package/dist/utils/redirect-uri.d.mts +20 -0
- package/dist/utils/redirect-uri.mjs +48 -0
- package/dist/utils/string.d.mts +8 -0
- package/dist/utils/string.mjs +25 -0
- package/dist/utils/url.d.mts +37 -0
- package/dist/utils/url.mjs +61 -0
- package/package.json +216 -0
- package/src/api/index.ts +185 -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.ts +91 -0
- package/src/context/transaction.ts +169 -0
- package/src/db/adapter/factory.ts +1740 -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 +150 -0
- package/src/db/adapter/get-model-name.ts +36 -0
- package/src/db/adapter/index.ts +656 -0
- package/src/db/adapter/types.ts +134 -0
- package/src/db/adapter/utils.ts +61 -0
- package/src/db/get-tables.ts +304 -0
- package/src/db/index.ts +43 -0
- package/src/db/plugin.ts +11 -0
- package/src/db/schema/account.ts +47 -0
- package/src/db/schema/rate-limit.ts +36 -0
- package/src/db/schema/session.ts +29 -0
- package/src/db/schema/shared.ts +7 -0
- package/src/db/schema/user.ts +31 -0
- package/src/db/schema/verification.ts +28 -0
- package/src/db/type.ts +360 -0
- package/src/env/color-depth.ts +172 -0
- package/src/env/env-impl.ts +123 -0
- package/src/env/index.ts +23 -0
- package/src/env/logger.ts +145 -0
- package/src/error/codes.ts +72 -0
- package/src/error/index.ts +44 -0
- package/src/index.ts +1 -0
- package/src/instrumentation/api.ts +17 -0
- package/src/instrumentation/attributes.ts +22 -0
- package/src/instrumentation/index.ts +2 -0
- package/src/instrumentation/noop.ts +74 -0
- package/src/instrumentation/pure.index.ts +31 -0
- package/src/instrumentation/tracer.ts +95 -0
- package/src/oauth2/client-credentials-token.ts +126 -0
- package/src/oauth2/create-authorization-url.ts +89 -0
- package/src/oauth2/index.ts +34 -0
- package/src/oauth2/oauth-provider.ts +222 -0
- package/src/oauth2/refresh-access-token.ts +157 -0
- package/src/oauth2/reject-redirects.ts +70 -0
- package/src/oauth2/utils.ts +70 -0
- package/src/oauth2/validate-authorization-code.ts +190 -0
- package/src/oauth2/verify.ts +408 -0
- package/src/social-providers/apple.ts +249 -0
- package/src/social-providers/atlassian.ts +133 -0
- package/src/social-providers/cognito.ts +281 -0
- package/src/social-providers/discord.ts +170 -0
- package/src/social-providers/dropbox.ts +112 -0
- package/src/social-providers/facebook.ts +288 -0
- package/src/social-providers/figma.ts +118 -0
- package/src/social-providers/github.ts +184 -0
- package/src/social-providers/gitlab.ts +155 -0
- package/src/social-providers/google.ts +263 -0
- package/src/social-providers/huggingface.ts +119 -0
- package/src/social-providers/index.ts +132 -0
- package/src/social-providers/kakao.ts +179 -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 +391 -0
- package/src/social-providers/naver.ts +113 -0
- package/src/social-providers/notion.ts +108 -0
- package/src/social-providers/paybin.ts +118 -0
- package/src/social-providers/paypal.ts +371 -0
- package/src/social-providers/polar.ts +111 -0
- package/src/social-providers/railway.ts +100 -0
- package/src/social-providers/reddit.ts +126 -0
- package/src/social-providers/roblox.ts +112 -0
- package/src/social-providers/salesforce.ts +159 -0
- package/src/social-providers/slack.ts +112 -0
- package/src/social-providers/spotify.ts +94 -0
- package/src/social-providers/tiktok.ts +211 -0
- package/src/social-providers/twitch.ts +112 -0
- package/src/social-providers/twitter.ts +199 -0
- package/src/social-providers/vercel.ts +87 -0
- package/src/social-providers/vk.ts +125 -0
- package/src/social-providers/wechat.ts +220 -0
- package/src/social-providers/zoom.ts +230 -0
- package/src/types/context.ts +460 -0
- package/src/types/cookie.ts +10 -0
- package/src/types/helper.ts +27 -0
- package/src/types/index.ts +40 -0
- package/src/types/init-options.ts +1679 -0
- package/src/types/plugin-client.ts +143 -0
- package/src/types/plugin.ts +163 -0
- package/src/types/secret.ts +8 -0
- package/src/utils/async.ts +53 -0
- package/src/utils/db.ts +20 -0
- package/src/utils/deprecate.ts +21 -0
- package/src/utils/error-codes.ts +68 -0
- package/src/utils/fetch-metadata.ts +3 -0
- package/src/utils/host.ts +416 -0
- package/src/utils/id.ts +5 -0
- package/src/utils/ip.ts +395 -0
- package/src/utils/is-api-error.ts +10 -0
- package/src/utils/json.ts +56 -0
- package/src/utils/redirect-uri.ts +54 -0
- package/src/utils/string.ts +40 -0
- package/src/utils/url.ts +77 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
//#region src/social-providers/wechat.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* WeChat user profile information
|
|
5
|
+
* @see https://developers.weixin.qq.com/doc/oplatform/en/Website_App/WeChat_Login/Wechat_Login.html
|
|
6
|
+
*/
|
|
7
|
+
interface WeChatProfile extends Record<string, any> {
|
|
8
|
+
/**
|
|
9
|
+
* User's unique OpenID
|
|
10
|
+
*/
|
|
11
|
+
openid: string;
|
|
12
|
+
/**
|
|
13
|
+
* User's nickname
|
|
14
|
+
*/
|
|
15
|
+
nickname: string;
|
|
16
|
+
/**
|
|
17
|
+
* User's avatar image URL
|
|
18
|
+
*/
|
|
19
|
+
headimgurl: string;
|
|
20
|
+
/**
|
|
21
|
+
* User's privileges
|
|
22
|
+
*/
|
|
23
|
+
privilege: string[];
|
|
24
|
+
/**
|
|
25
|
+
* User's UnionID (unique across the developer's various applications)
|
|
26
|
+
*/
|
|
27
|
+
unionid?: string;
|
|
28
|
+
/** @note Email is currently unsupported by WeChat */
|
|
29
|
+
email?: string;
|
|
30
|
+
}
|
|
31
|
+
interface WeChatOptions extends ProviderOptions<WeChatProfile> {
|
|
32
|
+
/**
|
|
33
|
+
* WeChat App ID
|
|
34
|
+
*/
|
|
35
|
+
clientId: string;
|
|
36
|
+
/**
|
|
37
|
+
* WeChat App Secret
|
|
38
|
+
*/
|
|
39
|
+
clientSecret: string;
|
|
40
|
+
/**
|
|
41
|
+
* Platform type for WeChat login
|
|
42
|
+
* - Currently only supports "WebsiteApp" for WeChat Website Application (网站应用)
|
|
43
|
+
* @default "WebsiteApp"
|
|
44
|
+
*/
|
|
45
|
+
platformType?: "WebsiteApp";
|
|
46
|
+
/**
|
|
47
|
+
* UI language for the WeChat login page
|
|
48
|
+
* cn for Simplified Chinese, en for English
|
|
49
|
+
* @default "cn" if left undefined
|
|
50
|
+
*/
|
|
51
|
+
lang?: "cn" | "en";
|
|
52
|
+
}
|
|
53
|
+
declare const wechat: (options: WeChatOptions) => {
|
|
54
|
+
id: "wechat";
|
|
55
|
+
name: string;
|
|
56
|
+
createAuthorizationURL({
|
|
57
|
+
state,
|
|
58
|
+
scopes,
|
|
59
|
+
redirectURI
|
|
60
|
+
}: {
|
|
61
|
+
state: string;
|
|
62
|
+
codeVerifier: string;
|
|
63
|
+
scopes?: string[] | undefined;
|
|
64
|
+
redirectURI: string;
|
|
65
|
+
display?: string | undefined;
|
|
66
|
+
loginHint?: string | undefined;
|
|
67
|
+
}): URL;
|
|
68
|
+
validateAuthorizationCode: ({
|
|
69
|
+
code
|
|
70
|
+
}: {
|
|
71
|
+
code: string;
|
|
72
|
+
redirectURI: string;
|
|
73
|
+
codeVerifier?: string | undefined;
|
|
74
|
+
deviceId?: string | undefined;
|
|
75
|
+
}) => Promise<{
|
|
76
|
+
tokenType: "Bearer";
|
|
77
|
+
accessToken: string;
|
|
78
|
+
refreshToken: string;
|
|
79
|
+
accessTokenExpiresAt: Date;
|
|
80
|
+
scopes: string[];
|
|
81
|
+
openid: string;
|
|
82
|
+
unionid: string | undefined;
|
|
83
|
+
}>;
|
|
84
|
+
refreshAccessToken: ((refreshToken: string) => Promise<OAuth2Tokens>) | ((refreshToken: string) => Promise<{
|
|
85
|
+
tokenType: "Bearer";
|
|
86
|
+
accessToken: string;
|
|
87
|
+
refreshToken: string;
|
|
88
|
+
accessTokenExpiresAt: Date;
|
|
89
|
+
scopes: string[];
|
|
90
|
+
}>);
|
|
91
|
+
getUserInfo(token: OAuth2Tokens & {
|
|
92
|
+
user?: {
|
|
93
|
+
name?: {
|
|
94
|
+
firstName?: string;
|
|
95
|
+
lastName?: string;
|
|
96
|
+
};
|
|
97
|
+
email?: string;
|
|
98
|
+
} | undefined;
|
|
99
|
+
}): Promise<{
|
|
100
|
+
user: {
|
|
101
|
+
id: string;
|
|
102
|
+
name?: string;
|
|
103
|
+
email?: string | null;
|
|
104
|
+
image?: string;
|
|
105
|
+
emailVerified: boolean;
|
|
106
|
+
[key: string]: any;
|
|
107
|
+
};
|
|
108
|
+
data: any;
|
|
109
|
+
} | null>;
|
|
110
|
+
options: WeChatOptions;
|
|
111
|
+
};
|
|
112
|
+
//#endregion
|
|
113
|
+
export { WeChatOptions, WeChatProfile, wechat };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
2
|
+
//#region src/social-providers/wechat.ts
|
|
3
|
+
const wechat = (options) => {
|
|
4
|
+
return {
|
|
5
|
+
id: "wechat",
|
|
6
|
+
name: "WeChat",
|
|
7
|
+
createAuthorizationURL({ state, scopes, redirectURI }) {
|
|
8
|
+
const _scopes = options.disableDefaultScope ? [] : ["snsapi_login"];
|
|
9
|
+
options.scope && _scopes.push(...options.scope);
|
|
10
|
+
scopes && _scopes.push(...scopes);
|
|
11
|
+
const url = new URL("https://open.weixin.qq.com/connect/qrconnect");
|
|
12
|
+
url.searchParams.set("scope", _scopes.join(","));
|
|
13
|
+
url.searchParams.set("response_type", "code");
|
|
14
|
+
url.searchParams.set("appid", options.clientId);
|
|
15
|
+
url.searchParams.set("redirect_uri", options.redirectURI || redirectURI);
|
|
16
|
+
url.searchParams.set("state", state);
|
|
17
|
+
url.searchParams.set("lang", options.lang || "cn");
|
|
18
|
+
url.hash = "wechat_redirect";
|
|
19
|
+
return url;
|
|
20
|
+
},
|
|
21
|
+
validateAuthorizationCode: async ({ code }) => {
|
|
22
|
+
const { data: tokenData, error } = await betterFetch("https://api.weixin.qq.com/sns/oauth2/access_token?" + new URLSearchParams({
|
|
23
|
+
appid: options.clientId,
|
|
24
|
+
secret: options.clientSecret,
|
|
25
|
+
code,
|
|
26
|
+
grant_type: "authorization_code"
|
|
27
|
+
}).toString(), { method: "GET" });
|
|
28
|
+
if (error || !tokenData || tokenData.errcode) throw new Error(`Failed to validate authorization code: ${tokenData?.errmsg || error?.message || "Unknown error"}`);
|
|
29
|
+
return {
|
|
30
|
+
tokenType: "Bearer",
|
|
31
|
+
accessToken: tokenData.access_token,
|
|
32
|
+
refreshToken: tokenData.refresh_token,
|
|
33
|
+
accessTokenExpiresAt: new Date(Date.now() + tokenData.expires_in * 1e3),
|
|
34
|
+
scopes: tokenData.scope.split(","),
|
|
35
|
+
openid: tokenData.openid,
|
|
36
|
+
unionid: tokenData.unionid
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
|
|
40
|
+
const { data: tokenData, error } = await betterFetch("https://api.weixin.qq.com/sns/oauth2/refresh_token?" + new URLSearchParams({
|
|
41
|
+
appid: options.clientId,
|
|
42
|
+
grant_type: "refresh_token",
|
|
43
|
+
refresh_token: refreshToken
|
|
44
|
+
}).toString(), { method: "GET" });
|
|
45
|
+
if (error || !tokenData || tokenData.errcode) throw new Error(`Failed to refresh access token: ${tokenData?.errmsg || error?.message || "Unknown error"}`);
|
|
46
|
+
return {
|
|
47
|
+
tokenType: "Bearer",
|
|
48
|
+
accessToken: tokenData.access_token,
|
|
49
|
+
refreshToken: tokenData.refresh_token,
|
|
50
|
+
accessTokenExpiresAt: new Date(Date.now() + tokenData.expires_in * 1e3),
|
|
51
|
+
scopes: tokenData.scope.split(",")
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
async getUserInfo(token) {
|
|
55
|
+
if (options.getUserInfo) return options.getUserInfo(token);
|
|
56
|
+
const openid = token.openid;
|
|
57
|
+
if (!openid) return null;
|
|
58
|
+
const { data: profile, error } = await betterFetch("https://api.weixin.qq.com/sns/userinfo?" + new URLSearchParams({
|
|
59
|
+
access_token: token.accessToken || "",
|
|
60
|
+
openid,
|
|
61
|
+
lang: "zh_CN"
|
|
62
|
+
}).toString(), { method: "GET" });
|
|
63
|
+
if (error || !profile || profile.errcode) return null;
|
|
64
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
65
|
+
return {
|
|
66
|
+
user: {
|
|
67
|
+
id: profile.unionid || profile.openid || openid,
|
|
68
|
+
name: profile.nickname,
|
|
69
|
+
email: profile.email || `${profile.unionid || profile.openid || openid}@wechat.invalid`,
|
|
70
|
+
image: profile.headimgurl,
|
|
71
|
+
emailVerified: false,
|
|
72
|
+
...userMap
|
|
73
|
+
},
|
|
74
|
+
data: profile
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
options
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
export { wechat };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
//#region src/social-providers/zoom.d.ts
|
|
3
|
+
type LoginType = 0 /** Facebook OAuth */ | 1 /** Google OAuth */ | 24 /** Apple OAuth */ | 27 /** Microsoft OAuth */ | 97 /** Mobile device */ | 98 /** RingCentral OAuth */ | 99 /** API user */ | 100 /** Zoom Work email */ | 101;
|
|
4
|
+
/** Single Sign-On (SSO) */
|
|
5
|
+
type AccountStatus = "pending" | "active" | "inactive";
|
|
6
|
+
type PronounOption = 1 /** Ask the user every time */ | 2 /** Always display */ | 3;
|
|
7
|
+
/** Do not display */
|
|
8
|
+
interface PhoneNumber {
|
|
9
|
+
/** The country code of the phone number (Example: "+1") */
|
|
10
|
+
code: string;
|
|
11
|
+
/** The country of the phone number (Example: "US") */
|
|
12
|
+
country: string;
|
|
13
|
+
/** The label for the phone number (Example: "Mobile") */
|
|
14
|
+
label: string;
|
|
15
|
+
/** The phone number itself (Example: "800000000") */
|
|
16
|
+
number: string;
|
|
17
|
+
/** Whether the phone number has been verified (Example: true) */
|
|
18
|
+
verified: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* See the full documentation below:
|
|
22
|
+
* https://developers.zoom.us/docs/api/users/#tag/users/GET/users/{userId}
|
|
23
|
+
*/
|
|
24
|
+
interface ZoomProfile extends Record<string, any> {
|
|
25
|
+
/** The user's account ID (Example: "q6gBJVO5TzexKYTb_I2rpg") */
|
|
26
|
+
account_id: string;
|
|
27
|
+
/** The user's account number (Example: 10009239) */
|
|
28
|
+
account_number: number;
|
|
29
|
+
/** The user's cluster (Example: "us04") */
|
|
30
|
+
cluster: string;
|
|
31
|
+
/** The user's CMS ID. Only enabled for Kaltura integration (Example: "KDcuGIm1QgePTO8WbOqwIQ") */
|
|
32
|
+
cms_user_id: string;
|
|
33
|
+
/** The user's cost center (Example: "cost center") */
|
|
34
|
+
cost_center: string;
|
|
35
|
+
/** User create time (Example: "2018-10-31T04:32:37Z") */
|
|
36
|
+
created_at: string;
|
|
37
|
+
/** Department (Example: "Developers") */
|
|
38
|
+
dept: string;
|
|
39
|
+
/** User's display name (Example: "Jill Chill") */
|
|
40
|
+
display_name: string;
|
|
41
|
+
/** User's email address (Example: "jchill@example.com") */
|
|
42
|
+
email: string;
|
|
43
|
+
/** User's first name (Example: "Jill") */
|
|
44
|
+
first_name: string;
|
|
45
|
+
/** IDs of the web groups that the user belongs to (Example: ["RSMaSp8sTEGK0_oamiA2_w"]) */
|
|
46
|
+
group_ids: string[];
|
|
47
|
+
/** User ID (Example: "zJKyaiAyTNC-MWjiWC18KQ") */
|
|
48
|
+
id: string;
|
|
49
|
+
/** IM IDs of the groups that the user belongs to (Example: ["t-_-d56CSWG-7BF15LLrOw"]) */
|
|
50
|
+
im_group_ids: string[];
|
|
51
|
+
/** The user's JID (Example: "jchill@example.com") */
|
|
52
|
+
jid: string;
|
|
53
|
+
/** The user's job title (Example: "API Developer") */
|
|
54
|
+
job_title: string;
|
|
55
|
+
/** Default language for the Zoom Web Portal (Example: "en-US") */
|
|
56
|
+
language: string;
|
|
57
|
+
/** User last login client version (Example: "5.9.6.4993(mac)") */
|
|
58
|
+
last_client_version: string;
|
|
59
|
+
/** User last login time (Example: "2021-05-05T20:40:30Z") */
|
|
60
|
+
last_login_time: string;
|
|
61
|
+
/** User's last name (Example: "Chill") */
|
|
62
|
+
last_name: string;
|
|
63
|
+
/** The time zone of the user (Example: "Asia/Shanghai") */
|
|
64
|
+
timezone: string;
|
|
65
|
+
/** User's location (Example: "Paris") */
|
|
66
|
+
location: string;
|
|
67
|
+
/** The user's login method (Example: 101) */
|
|
68
|
+
login_types: LoginType[];
|
|
69
|
+
/** User's personal meeting URL (Example: "example.com") */
|
|
70
|
+
personal_meeting_url: string;
|
|
71
|
+
/** The URL for user's profile picture (Example: "example.com") */
|
|
72
|
+
pic_url: string;
|
|
73
|
+
/** Personal Meeting ID (PMI) (Example: 3542471135) */
|
|
74
|
+
pmi: number;
|
|
75
|
+
/** Unique identifier of the user's assigned role (Example: "0") */
|
|
76
|
+
role_id: string;
|
|
77
|
+
/** User's role name (Example: "Admin") */
|
|
78
|
+
role_name: string;
|
|
79
|
+
/** Status of user's account (Example: "pending") */
|
|
80
|
+
status: AccountStatus;
|
|
81
|
+
/** Use the personal meeting ID (PMI) for instant meetings (Example: false) */
|
|
82
|
+
use_pmi: boolean;
|
|
83
|
+
/** The time and date when the user was created (Example: "2018-10-31T04:32:37Z") */
|
|
84
|
+
user_created_at: string;
|
|
85
|
+
/** Displays whether user is verified or not (Example: 1) */
|
|
86
|
+
verified: number;
|
|
87
|
+
/** The user's Zoom Workplace plan option (Example: 64) */
|
|
88
|
+
zoom_one_type: number;
|
|
89
|
+
/** The user's company (Example: "Jill") */
|
|
90
|
+
company?: string | undefined;
|
|
91
|
+
/** Custom attributes that have been assigned to the user (Example: [{ "key": "cbf_cywdkexrtqc73f97gd4w6g", "name": "A1", "value": "1" }]) */
|
|
92
|
+
custom_attributes?: {
|
|
93
|
+
key: string;
|
|
94
|
+
name: string;
|
|
95
|
+
value: string;
|
|
96
|
+
}[] | undefined;
|
|
97
|
+
/** 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") */
|
|
98
|
+
employee_unique_id?: string | undefined;
|
|
99
|
+
/** The manager for the user (Example: "thill@example.com") */
|
|
100
|
+
manager?: string | undefined;
|
|
101
|
+
/** The phone number's ISO country code (Example: "+1") */
|
|
102
|
+
phone_numbers?: PhoneNumber[] | undefined;
|
|
103
|
+
/** The user's plan type (Example: "1") */
|
|
104
|
+
plan_united_type?: string | undefined;
|
|
105
|
+
/** The user's pronouns (Example: "3123") */
|
|
106
|
+
pronouns?: string | undefined;
|
|
107
|
+
/** The user's display pronouns setting (Example: 1) */
|
|
108
|
+
pronouns_option?: PronounOption | undefined;
|
|
109
|
+
/** Personal meeting room URL, if the user has one (Example: "example.com") */
|
|
110
|
+
vanity_url?: string | undefined;
|
|
111
|
+
}
|
|
112
|
+
interface ZoomOptions extends ProviderOptions<ZoomProfile> {
|
|
113
|
+
clientId: string;
|
|
114
|
+
pkce?: boolean | undefined;
|
|
115
|
+
}
|
|
116
|
+
declare const zoom: (userOptions: ZoomOptions) => {
|
|
117
|
+
id: "zoom";
|
|
118
|
+
name: string;
|
|
119
|
+
createAuthorizationURL: ({
|
|
120
|
+
state,
|
|
121
|
+
redirectURI,
|
|
122
|
+
codeVerifier
|
|
123
|
+
}: {
|
|
124
|
+
state: string;
|
|
125
|
+
codeVerifier: string;
|
|
126
|
+
scopes?: string[] | undefined;
|
|
127
|
+
redirectURI: string;
|
|
128
|
+
display?: string | undefined;
|
|
129
|
+
loginHint?: string | undefined;
|
|
130
|
+
}) => Promise<URL>;
|
|
131
|
+
validateAuthorizationCode: ({
|
|
132
|
+
code,
|
|
133
|
+
redirectURI,
|
|
134
|
+
codeVerifier
|
|
135
|
+
}: {
|
|
136
|
+
code: string;
|
|
137
|
+
redirectURI: string;
|
|
138
|
+
codeVerifier?: string | undefined;
|
|
139
|
+
deviceId?: string | undefined;
|
|
140
|
+
}) => Promise<OAuth2Tokens>;
|
|
141
|
+
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
142
|
+
getUserInfo(token: OAuth2Tokens & {
|
|
143
|
+
user?: {
|
|
144
|
+
name?: {
|
|
145
|
+
firstName?: string;
|
|
146
|
+
lastName?: string;
|
|
147
|
+
};
|
|
148
|
+
email?: string;
|
|
149
|
+
} | undefined;
|
|
150
|
+
}): Promise<{
|
|
151
|
+
user: {
|
|
152
|
+
id: string;
|
|
153
|
+
name?: string;
|
|
154
|
+
email?: string | null;
|
|
155
|
+
image?: string;
|
|
156
|
+
emailVerified: boolean;
|
|
157
|
+
[key: string]: any;
|
|
158
|
+
};
|
|
159
|
+
data: any;
|
|
160
|
+
} | null>;
|
|
161
|
+
};
|
|
162
|
+
//#endregion
|
|
163
|
+
export { AccountStatus, LoginType, PhoneNumber, PronounOption, ZoomOptions, ZoomProfile, zoom };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { generateCodeChallenge } from "../oauth2/utils.mjs";
|
|
2
|
+
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
3
|
+
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
4
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
5
|
+
//#region src/social-providers/zoom.ts
|
|
6
|
+
const zoom = (userOptions) => {
|
|
7
|
+
const options = {
|
|
8
|
+
pkce: true,
|
|
9
|
+
...userOptions
|
|
10
|
+
};
|
|
11
|
+
return {
|
|
12
|
+
id: "zoom",
|
|
13
|
+
name: "Zoom",
|
|
14
|
+
createAuthorizationURL: async ({ state, redirectURI, codeVerifier }) => {
|
|
15
|
+
const params = new URLSearchParams({
|
|
16
|
+
response_type: "code",
|
|
17
|
+
redirect_uri: options.redirectURI ? options.redirectURI : redirectURI,
|
|
18
|
+
client_id: options.clientId,
|
|
19
|
+
state
|
|
20
|
+
});
|
|
21
|
+
if (options.pkce) {
|
|
22
|
+
const codeChallenge = await generateCodeChallenge(codeVerifier);
|
|
23
|
+
params.set("code_challenge_method", "S256");
|
|
24
|
+
params.set("code_challenge", codeChallenge);
|
|
25
|
+
}
|
|
26
|
+
const url = new URL("https://zoom.us/oauth/authorize");
|
|
27
|
+
url.search = params.toString();
|
|
28
|
+
return url;
|
|
29
|
+
},
|
|
30
|
+
validateAuthorizationCode: async ({ code, redirectURI, codeVerifier }) => {
|
|
31
|
+
return validateAuthorizationCode({
|
|
32
|
+
code,
|
|
33
|
+
redirectURI: options.redirectURI || redirectURI,
|
|
34
|
+
codeVerifier,
|
|
35
|
+
options,
|
|
36
|
+
tokenEndpoint: "https://zoom.us/oauth/token",
|
|
37
|
+
authentication: "post"
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => refreshAccessToken({
|
|
41
|
+
refreshToken,
|
|
42
|
+
options: {
|
|
43
|
+
clientId: options.clientId,
|
|
44
|
+
clientKey: options.clientKey,
|
|
45
|
+
clientSecret: options.clientSecret
|
|
46
|
+
},
|
|
47
|
+
tokenEndpoint: "https://zoom.us/oauth/token"
|
|
48
|
+
}),
|
|
49
|
+
async getUserInfo(token) {
|
|
50
|
+
if (options.getUserInfo) return options.getUserInfo(token);
|
|
51
|
+
const { data: profile, error } = await betterFetch("https://api.zoom.us/v2/users/me", { headers: { authorization: `Bearer ${token.accessToken}` } });
|
|
52
|
+
if (error) return null;
|
|
53
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
54
|
+
return {
|
|
55
|
+
user: {
|
|
56
|
+
id: profile.id,
|
|
57
|
+
name: profile.display_name,
|
|
58
|
+
image: profile.pic_url,
|
|
59
|
+
email: profile.email,
|
|
60
|
+
emailVerified: Boolean(profile.verified),
|
|
61
|
+
...userMap
|
|
62
|
+
},
|
|
63
|
+
data: { ...profile }
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
export { zoom };
|