@better-auth/core 1.4.12-beta.2 → 1.4.13
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 +172 -35
- package/dist/api/index.d.mts +178 -1
- package/dist/api/index.mjs +2 -1
- package/dist/context/endpoint-context.d.mts +19 -0
- package/dist/context/endpoint-context.mjs +31 -0
- package/dist/context/global.d.mts +7 -0
- package/dist/context/global.mjs +37 -0
- package/dist/context/index.d.mts +5 -53
- package/dist/context/index.mjs +5 -2
- package/dist/context/request-state.d.mts +27 -0
- package/dist/context/request-state.mjs +49 -0
- package/dist/context/transaction.d.mts +16 -0
- package/dist/context/transaction.mjs +52 -0
- package/dist/db/adapter/factory.d.mts +27 -0
- package/dist/db/adapter/factory.mjs +738 -0
- package/dist/db/adapter/get-default-field-name.d.mts +18 -0
- package/dist/db/adapter/get-default-field-name.mjs +38 -0
- package/dist/db/adapter/get-default-model-name.d.mts +12 -0
- package/dist/db/adapter/get-default-model-name.mjs +32 -0
- package/dist/db/adapter/get-field-attributes.d.mts +29 -0
- package/dist/db/adapter/get-field-attributes.mjs +39 -0
- package/dist/db/adapter/get-field-name.d.mts +18 -0
- package/dist/db/adapter/get-field-name.mjs +33 -0
- package/dist/db/adapter/get-id-field.d.mts +39 -0
- package/dist/db/adapter/get-id-field.mjs +68 -0
- package/dist/db/adapter/get-model-name.d.mts +12 -0
- package/dist/db/adapter/get-model-name.mjs +23 -0
- package/dist/db/adapter/index.d.mts +513 -1
- package/dist/db/adapter/index.mjs +8 -970
- package/dist/db/adapter/types.d.mts +139 -0
- package/dist/db/adapter/utils.d.mts +7 -0
- package/dist/db/adapter/utils.mjs +38 -0
- package/dist/db/get-tables.d.mts +8 -0
- package/dist/{get-tables-CMc_Emww.mjs → db/get-tables.mjs} +1 -1
- package/dist/db/index.d.mts +10 -2
- package/dist/db/index.mjs +7 -60
- package/dist/db/plugin.d.mts +12 -0
- package/dist/db/schema/account.d.mts +26 -0
- package/dist/db/schema/account.mjs +19 -0
- package/dist/db/schema/rate-limit.d.mts +14 -0
- package/dist/db/schema/rate-limit.mjs +11 -0
- package/dist/db/schema/session.d.mts +21 -0
- package/dist/db/schema/session.mjs +14 -0
- package/dist/db/schema/shared.d.mts +10 -0
- package/dist/db/schema/shared.mjs +11 -0
- package/dist/db/schema/user.d.mts +20 -0
- package/dist/db/schema/user.mjs +13 -0
- package/dist/db/schema/verification.d.mts +19 -0
- package/dist/db/schema/verification.mjs +12 -0
- package/dist/db/type.d.mts +143 -0
- package/dist/env/color-depth.d.mts +4 -0
- package/dist/env/color-depth.mjs +88 -0
- package/dist/env/env-impl.d.mts +32 -0
- package/dist/env/env-impl.mjs +82 -0
- package/dist/env/index.d.mts +4 -2
- package/dist/env/index.mjs +3 -1
- package/dist/{index-BRBu0-5h.d.mts → env/logger.d.mts} +1 -35
- package/dist/env/logger.mjs +81 -0
- package/dist/error/codes.d.mts +48 -0
- package/dist/{error-DP1xOn7P.mjs → error/codes.mjs} +3 -14
- package/dist/error/index.d.mts +5 -48
- package/dist/error/index.mjs +12 -3
- package/dist/index.d.mts +8 -2
- package/dist/oauth2/client-credentials-token.d.mts +36 -0
- package/dist/oauth2/client-credentials-token.mjs +54 -0
- package/dist/oauth2/create-authorization-url.d.mts +45 -0
- package/dist/oauth2/create-authorization-url.mjs +42 -0
- package/dist/oauth2/index.d.mts +8 -2
- package/dist/oauth2/index.mjs +6 -2
- package/dist/oauth2/oauth-provider.d.mts +194 -0
- package/dist/oauth2/refresh-access-token.d.mts +36 -0
- package/dist/oauth2/refresh-access-token.mjs +58 -0
- package/dist/oauth2/utils.d.mts +7 -0
- package/dist/oauth2/utils.mjs +27 -0
- package/dist/oauth2/validate-authorization-code.d.mts +55 -0
- package/dist/oauth2/validate-authorization-code.mjs +71 -0
- package/dist/oauth2/verify.d.mts +49 -0
- package/dist/oauth2/verify.mjs +95 -0
- package/dist/social-providers/apple.d.mts +119 -0
- package/dist/social-providers/apple.mjs +102 -0
- package/dist/social-providers/atlassian.d.mts +72 -0
- package/dist/social-providers/atlassian.mjs +83 -0
- package/dist/social-providers/cognito.d.mts +87 -0
- package/dist/social-providers/cognito.mjs +166 -0
- package/dist/social-providers/discord.d.mts +126 -0
- package/dist/social-providers/discord.mjs +64 -0
- package/dist/social-providers/dropbox.d.mts +71 -0
- package/dist/social-providers/dropbox.mjs +75 -0
- package/dist/social-providers/facebook.d.mts +81 -0
- package/dist/social-providers/facebook.mjs +120 -0
- package/dist/social-providers/figma.d.mts +63 -0
- package/dist/social-providers/figma.mjs +84 -0
- package/dist/social-providers/github.d.mts +104 -0
- package/dist/social-providers/github.mjs +80 -0
- package/dist/social-providers/gitlab.d.mts +125 -0
- package/dist/social-providers/gitlab.mjs +82 -0
- package/dist/social-providers/google.d.mts +99 -0
- package/dist/social-providers/google.mjs +109 -0
- package/dist/social-providers/huggingface.d.mts +85 -0
- package/dist/social-providers/huggingface.mjs +75 -0
- package/dist/social-providers/index.d.mts +1723 -1
- package/dist/social-providers/index.mjs +33 -2570
- package/dist/social-providers/kakao.d.mts +163 -0
- package/dist/social-providers/kakao.mjs +72 -0
- package/dist/social-providers/kick.d.mts +75 -0
- package/dist/social-providers/kick.mjs +71 -0
- package/dist/social-providers/line.d.mts +107 -0
- package/dist/social-providers/line.mjs +113 -0
- package/dist/social-providers/linear.d.mts +70 -0
- package/dist/social-providers/linear.mjs +88 -0
- package/dist/social-providers/linkedin.d.mts +69 -0
- package/dist/social-providers/linkedin.mjs +76 -0
- package/dist/social-providers/microsoft-entra-id.d.mts +174 -0
- package/dist/social-providers/microsoft-entra-id.mjs +106 -0
- package/dist/social-providers/naver.d.mts +104 -0
- package/dist/social-providers/naver.mjs +67 -0
- package/dist/social-providers/notion.d.mts +66 -0
- package/dist/social-providers/notion.mjs +75 -0
- package/dist/social-providers/paybin.d.mts +73 -0
- package/dist/social-providers/paybin.mjs +85 -0
- package/dist/social-providers/paypal.d.mts +131 -0
- package/dist/social-providers/paypal.mjs +144 -0
- package/dist/social-providers/polar.d.mts +76 -0
- package/dist/social-providers/polar.mjs +73 -0
- package/dist/social-providers/reddit.d.mts +64 -0
- package/dist/social-providers/reddit.mjs +83 -0
- package/dist/social-providers/roblox.d.mts +72 -0
- package/dist/social-providers/roblox.mjs +59 -0
- package/dist/social-providers/salesforce.d.mts +81 -0
- package/dist/social-providers/salesforce.mjs +91 -0
- package/dist/social-providers/slack.d.mts +85 -0
- package/dist/social-providers/slack.mjs +68 -0
- package/dist/social-providers/spotify.d.mts +65 -0
- package/dist/social-providers/spotify.mjs +71 -0
- package/dist/social-providers/tiktok.d.mts +171 -0
- package/dist/social-providers/tiktok.mjs +62 -0
- package/dist/social-providers/twitch.d.mts +81 -0
- package/dist/social-providers/twitch.mjs +78 -0
- package/dist/social-providers/twitter.d.mts +140 -0
- package/dist/social-providers/twitter.mjs +87 -0
- package/dist/social-providers/vercel.d.mts +64 -0
- package/dist/social-providers/vercel.mjs +61 -0
- package/dist/social-providers/vk.d.mts +72 -0
- package/dist/social-providers/vk.mjs +83 -0
- package/dist/social-providers/zoom.d.mts +173 -0
- package/dist/social-providers/zoom.mjs +72 -0
- package/dist/types/context.d.mts +215 -0
- package/dist/types/cookie.d.mts +15 -0
- package/dist/types/helper.d.mts +8 -0
- package/dist/types/index.d.mts +8 -0
- package/dist/types/init-options.d.mts +1266 -0
- package/dist/types/plugin-client.d.mts +103 -0
- package/dist/types/plugin.d.mts +121 -0
- package/dist/utils/deprecate.d.mts +10 -0
- package/dist/utils/deprecate.mjs +17 -0
- package/dist/utils/error-codes.d.mts +9 -0
- package/dist/utils/error-codes.mjs +7 -0
- package/dist/utils/id.d.mts +4 -0
- package/dist/utils/id.mjs +9 -0
- package/dist/utils/index.d.mts +5 -26
- package/dist/utils/index.mjs +5 -2
- package/dist/utils/json.d.mts +4 -0
- package/dist/utils/json.mjs +25 -0
- package/dist/utils/string.d.mts +4 -0
- package/dist/utils/string.mjs +7 -0
- package/package.json +1 -1
- package/src/context/endpoint-context.ts +7 -15
- package/src/context/global.ts +57 -0
- package/src/context/index.ts +1 -0
- package/src/context/request-state.ts +7 -12
- package/src/context/transaction.ts +7 -16
- package/src/db/adapter/factory.ts +13 -13
- package/src/db/adapter/get-default-model-name.ts +1 -1
- package/src/db/adapter/get-id-field.ts +2 -2
- package/src/error/index.ts +2 -3
- package/src/social-providers/gitlab.ts +1 -1
- package/src/types/context.ts +137 -131
- package/src/types/cookie.ts +6 -4
- package/src/types/index.ts +2 -1
- package/tsdown.config.ts +9 -0
- package/dist/context-BGZ8V6DD.mjs +0 -126
- package/dist/env-DbssmzoK.mjs +0 -245
- package/dist/index-zgYuzZ7O.d.mts +0 -8020
- package/dist/oauth2-COJkghlT.mjs +0 -326
- package/dist/utils-U2L7n92V.mjs +0 -59
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
2
|
+
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
3
|
+
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
4
|
+
import "../oauth2/index.mjs";
|
|
5
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
6
|
+
|
|
7
|
+
//#region src/social-providers/twitter.ts
|
|
8
|
+
const twitter = (options) => {
|
|
9
|
+
return {
|
|
10
|
+
id: "twitter",
|
|
11
|
+
name: "Twitter",
|
|
12
|
+
createAuthorizationURL(data) {
|
|
13
|
+
const _scopes = options.disableDefaultScope ? [] : [
|
|
14
|
+
"users.read",
|
|
15
|
+
"tweet.read",
|
|
16
|
+
"offline.access",
|
|
17
|
+
"users.email"
|
|
18
|
+
];
|
|
19
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
20
|
+
if (data.scopes) _scopes.push(...data.scopes);
|
|
21
|
+
return createAuthorizationURL({
|
|
22
|
+
id: "twitter",
|
|
23
|
+
options,
|
|
24
|
+
authorizationEndpoint: "https://x.com/i/oauth2/authorize",
|
|
25
|
+
scopes: _scopes,
|
|
26
|
+
state: data.state,
|
|
27
|
+
codeVerifier: data.codeVerifier,
|
|
28
|
+
redirectURI: data.redirectURI
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
|
|
32
|
+
return validateAuthorizationCode({
|
|
33
|
+
code,
|
|
34
|
+
codeVerifier,
|
|
35
|
+
authentication: "basic",
|
|
36
|
+
redirectURI,
|
|
37
|
+
options,
|
|
38
|
+
tokenEndpoint: "https://api.x.com/2/oauth2/token"
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
|
|
42
|
+
return refreshAccessToken({
|
|
43
|
+
refreshToken,
|
|
44
|
+
options: {
|
|
45
|
+
clientId: options.clientId,
|
|
46
|
+
clientKey: options.clientKey,
|
|
47
|
+
clientSecret: options.clientSecret
|
|
48
|
+
},
|
|
49
|
+
authentication: "basic",
|
|
50
|
+
tokenEndpoint: "https://api.x.com/2/oauth2/token"
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
async getUserInfo(token) {
|
|
54
|
+
if (options.getUserInfo) return options.getUserInfo(token);
|
|
55
|
+
const { data: profile, error: profileError } = await betterFetch("https://api.x.com/2/users/me?user.fields=profile_image_url", {
|
|
56
|
+
method: "GET",
|
|
57
|
+
headers: { Authorization: `Bearer ${token.accessToken}` }
|
|
58
|
+
});
|
|
59
|
+
if (profileError) return null;
|
|
60
|
+
const { data: emailData, error: emailError } = await betterFetch("https://api.x.com/2/users/me?user.fields=confirmed_email", {
|
|
61
|
+
method: "GET",
|
|
62
|
+
headers: { Authorization: `Bearer ${token.accessToken}` }
|
|
63
|
+
});
|
|
64
|
+
let emailVerified = false;
|
|
65
|
+
if (!emailError && emailData?.data?.confirmed_email) {
|
|
66
|
+
profile.data.email = emailData.data.confirmed_email;
|
|
67
|
+
emailVerified = true;
|
|
68
|
+
}
|
|
69
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
70
|
+
return {
|
|
71
|
+
user: {
|
|
72
|
+
id: profile.data.id,
|
|
73
|
+
name: profile.data.name,
|
|
74
|
+
email: profile.data.email || profile.data.username || null,
|
|
75
|
+
image: profile.data.profile_image_url,
|
|
76
|
+
emailVerified,
|
|
77
|
+
...userMap
|
|
78
|
+
},
|
|
79
|
+
data: profile
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
options
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
export { twitter };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/social-providers/vercel.d.ts
|
|
5
|
+
interface VercelProfile {
|
|
6
|
+
sub: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
preferred_username?: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
email_verified?: boolean;
|
|
11
|
+
picture?: string;
|
|
12
|
+
}
|
|
13
|
+
interface VercelOptions extends ProviderOptions<VercelProfile> {
|
|
14
|
+
clientId: string;
|
|
15
|
+
}
|
|
16
|
+
declare const vercel: (options: VercelOptions) => {
|
|
17
|
+
id: "vercel";
|
|
18
|
+
name: string;
|
|
19
|
+
createAuthorizationURL({
|
|
20
|
+
state,
|
|
21
|
+
scopes,
|
|
22
|
+
codeVerifier,
|
|
23
|
+
redirectURI
|
|
24
|
+
}: {
|
|
25
|
+
state: string;
|
|
26
|
+
codeVerifier: string;
|
|
27
|
+
scopes?: string[] | undefined;
|
|
28
|
+
redirectURI: string;
|
|
29
|
+
display?: string | undefined;
|
|
30
|
+
loginHint?: string | undefined;
|
|
31
|
+
}): Promise<URL>;
|
|
32
|
+
validateAuthorizationCode: ({
|
|
33
|
+
code,
|
|
34
|
+
codeVerifier,
|
|
35
|
+
redirectURI
|
|
36
|
+
}: {
|
|
37
|
+
code: string;
|
|
38
|
+
redirectURI: string;
|
|
39
|
+
codeVerifier?: string | undefined;
|
|
40
|
+
deviceId?: string | undefined;
|
|
41
|
+
}) => Promise<OAuth2Tokens>;
|
|
42
|
+
getUserInfo(token: OAuth2Tokens & {
|
|
43
|
+
user?: {
|
|
44
|
+
name?: {
|
|
45
|
+
firstName?: string;
|
|
46
|
+
lastName?: string;
|
|
47
|
+
};
|
|
48
|
+
email?: string;
|
|
49
|
+
} | undefined;
|
|
50
|
+
}): Promise<{
|
|
51
|
+
user: {
|
|
52
|
+
id: string;
|
|
53
|
+
name?: string;
|
|
54
|
+
email?: string | null;
|
|
55
|
+
image?: string;
|
|
56
|
+
emailVerified: boolean;
|
|
57
|
+
[key: string]: any;
|
|
58
|
+
};
|
|
59
|
+
data: any;
|
|
60
|
+
} | null>;
|
|
61
|
+
options: VercelOptions;
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { VercelOptions, VercelProfile, vercel };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { BetterAuthError } from "../error/index.mjs";
|
|
2
|
+
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
3
|
+
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
4
|
+
import "../oauth2/index.mjs";
|
|
5
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
6
|
+
|
|
7
|
+
//#region src/social-providers/vercel.ts
|
|
8
|
+
const vercel = (options) => {
|
|
9
|
+
return {
|
|
10
|
+
id: "vercel",
|
|
11
|
+
name: "Vercel",
|
|
12
|
+
createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
|
|
13
|
+
if (!codeVerifier) throw new BetterAuthError("codeVerifier is required for Vercel");
|
|
14
|
+
let _scopes = void 0;
|
|
15
|
+
if (options.scope !== void 0 || scopes !== void 0) {
|
|
16
|
+
_scopes = [];
|
|
17
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
18
|
+
if (scopes) _scopes.push(...scopes);
|
|
19
|
+
}
|
|
20
|
+
return createAuthorizationURL({
|
|
21
|
+
id: "vercel",
|
|
22
|
+
options,
|
|
23
|
+
authorizationEndpoint: "https://vercel.com/oauth/authorize",
|
|
24
|
+
scopes: _scopes,
|
|
25
|
+
state,
|
|
26
|
+
codeVerifier,
|
|
27
|
+
redirectURI
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
|
|
31
|
+
return validateAuthorizationCode({
|
|
32
|
+
code,
|
|
33
|
+
codeVerifier,
|
|
34
|
+
redirectURI,
|
|
35
|
+
options,
|
|
36
|
+
tokenEndpoint: "https://api.vercel.com/login/oauth/token"
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
async getUserInfo(token) {
|
|
40
|
+
if (options.getUserInfo) return options.getUserInfo(token);
|
|
41
|
+
const { data: profile, error } = await betterFetch("https://api.vercel.com/login/oauth/userinfo", { headers: { Authorization: `Bearer ${token.accessToken}` } });
|
|
42
|
+
if (error || !profile) return null;
|
|
43
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
44
|
+
return {
|
|
45
|
+
user: {
|
|
46
|
+
id: profile.sub,
|
|
47
|
+
name: profile.name ?? profile.preferred_username,
|
|
48
|
+
email: profile.email,
|
|
49
|
+
image: profile.picture,
|
|
50
|
+
emailVerified: profile.email_verified ?? false,
|
|
51
|
+
...userMap
|
|
52
|
+
},
|
|
53
|
+
data: profile
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
options
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
export { vercel };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/social-providers/vk.d.ts
|
|
5
|
+
interface VkProfile {
|
|
6
|
+
user: {
|
|
7
|
+
user_id: string;
|
|
8
|
+
first_name: string;
|
|
9
|
+
last_name: string;
|
|
10
|
+
email?: string | undefined;
|
|
11
|
+
phone?: number | undefined;
|
|
12
|
+
avatar?: string | undefined;
|
|
13
|
+
sex?: number | undefined;
|
|
14
|
+
verified?: boolean | undefined;
|
|
15
|
+
birthday: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface VkOption extends ProviderOptions {
|
|
19
|
+
clientId: string;
|
|
20
|
+
scheme?: ("light" | "dark") | undefined;
|
|
21
|
+
}
|
|
22
|
+
declare const vk: (options: VkOption) => {
|
|
23
|
+
id: "vk";
|
|
24
|
+
name: string;
|
|
25
|
+
createAuthorizationURL({
|
|
26
|
+
state,
|
|
27
|
+
scopes,
|
|
28
|
+
codeVerifier,
|
|
29
|
+
redirectURI
|
|
30
|
+
}: {
|
|
31
|
+
state: string;
|
|
32
|
+
codeVerifier: string;
|
|
33
|
+
scopes?: string[] | undefined;
|
|
34
|
+
redirectURI: string;
|
|
35
|
+
display?: string | undefined;
|
|
36
|
+
loginHint?: string | undefined;
|
|
37
|
+
}): Promise<URL>;
|
|
38
|
+
validateAuthorizationCode: ({
|
|
39
|
+
code,
|
|
40
|
+
codeVerifier,
|
|
41
|
+
redirectURI,
|
|
42
|
+
deviceId
|
|
43
|
+
}: {
|
|
44
|
+
code: string;
|
|
45
|
+
redirectURI: string;
|
|
46
|
+
codeVerifier?: string | undefined;
|
|
47
|
+
deviceId?: string | undefined;
|
|
48
|
+
}) => Promise<OAuth2Tokens>;
|
|
49
|
+
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
50
|
+
getUserInfo(data: OAuth2Tokens & {
|
|
51
|
+
user?: {
|
|
52
|
+
name?: {
|
|
53
|
+
firstName?: string;
|
|
54
|
+
lastName?: string;
|
|
55
|
+
};
|
|
56
|
+
email?: string;
|
|
57
|
+
} | undefined;
|
|
58
|
+
}): Promise<{
|
|
59
|
+
user: {
|
|
60
|
+
id: string;
|
|
61
|
+
name?: string;
|
|
62
|
+
email?: string | null;
|
|
63
|
+
image?: string;
|
|
64
|
+
emailVerified: boolean;
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
};
|
|
67
|
+
data: any;
|
|
68
|
+
} | null>;
|
|
69
|
+
options: VkOption;
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
export { VkOption, VkProfile, vk };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
2
|
+
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
3
|
+
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
4
|
+
import "../oauth2/index.mjs";
|
|
5
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
6
|
+
|
|
7
|
+
//#region src/social-providers/vk.ts
|
|
8
|
+
const vk = (options) => {
|
|
9
|
+
return {
|
|
10
|
+
id: "vk",
|
|
11
|
+
name: "VK",
|
|
12
|
+
async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
|
|
13
|
+
const _scopes = options.disableDefaultScope ? [] : ["email", "phone"];
|
|
14
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
15
|
+
if (scopes) _scopes.push(...scopes);
|
|
16
|
+
return createAuthorizationURL({
|
|
17
|
+
id: "vk",
|
|
18
|
+
options,
|
|
19
|
+
authorizationEndpoint: "https://id.vk.com/authorize",
|
|
20
|
+
scopes: _scopes,
|
|
21
|
+
state,
|
|
22
|
+
redirectURI,
|
|
23
|
+
codeVerifier
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
validateAuthorizationCode: async ({ code, codeVerifier, redirectURI, deviceId }) => {
|
|
27
|
+
return validateAuthorizationCode({
|
|
28
|
+
code,
|
|
29
|
+
codeVerifier,
|
|
30
|
+
redirectURI: options.redirectURI || redirectURI,
|
|
31
|
+
options,
|
|
32
|
+
deviceId,
|
|
33
|
+
tokenEndpoint: "https://id.vk.com/oauth2/auth"
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => {
|
|
37
|
+
return refreshAccessToken({
|
|
38
|
+
refreshToken,
|
|
39
|
+
options: {
|
|
40
|
+
clientId: options.clientId,
|
|
41
|
+
clientKey: options.clientKey,
|
|
42
|
+
clientSecret: options.clientSecret
|
|
43
|
+
},
|
|
44
|
+
tokenEndpoint: "https://id.vk.com/oauth2/auth"
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
async getUserInfo(data) {
|
|
48
|
+
if (options.getUserInfo) return options.getUserInfo(data);
|
|
49
|
+
if (!data.accessToken) return null;
|
|
50
|
+
const formBody = new URLSearchParams({
|
|
51
|
+
access_token: data.accessToken,
|
|
52
|
+
client_id: options.clientId
|
|
53
|
+
}).toString();
|
|
54
|
+
const { data: profile, error } = await betterFetch("https://id.vk.com/oauth2/user_info", {
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
57
|
+
body: formBody
|
|
58
|
+
});
|
|
59
|
+
if (error) return null;
|
|
60
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
61
|
+
if (!profile.user.email && !userMap?.email) return null;
|
|
62
|
+
return {
|
|
63
|
+
user: {
|
|
64
|
+
id: profile.user.user_id,
|
|
65
|
+
first_name: profile.user.first_name,
|
|
66
|
+
last_name: profile.user.last_name,
|
|
67
|
+
email: profile.user.email,
|
|
68
|
+
image: profile.user.avatar,
|
|
69
|
+
emailVerified: false,
|
|
70
|
+
birthday: profile.user.birthday,
|
|
71
|
+
sex: profile.user.sex,
|
|
72
|
+
name: `${profile.user.first_name} ${profile.user.last_name}`,
|
|
73
|
+
...userMap
|
|
74
|
+
},
|
|
75
|
+
data: profile
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
options
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
export { vk };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { OAuth2Tokens, ProviderOptions } from "../oauth2/oauth-provider.mjs";
|
|
2
|
+
import "../oauth2/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/social-providers/zoom.d.ts
|
|
5
|
+
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;
|
|
6
|
+
/** Single Sign-On (SSO) */
|
|
7
|
+
type AccountStatus = "pending" | "active" | "inactive";
|
|
8
|
+
type PronounOption = 1 /** Ask the user every time */ | 2 /** Always display */ | 3;
|
|
9
|
+
/** Do not display */
|
|
10
|
+
interface PhoneNumber {
|
|
11
|
+
/** The country code of the phone number (Example: "+1") */
|
|
12
|
+
code: string;
|
|
13
|
+
/** The country of the phone number (Example: "US") */
|
|
14
|
+
country: string;
|
|
15
|
+
/** The label for the phone number (Example: "Mobile") */
|
|
16
|
+
label: string;
|
|
17
|
+
/** The phone number itself (Example: "800000000") */
|
|
18
|
+
number: string;
|
|
19
|
+
/** Whether the phone number has been verified (Example: true) */
|
|
20
|
+
verified: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* See the full documentation below:
|
|
24
|
+
* https://developers.zoom.us/docs/api/users/#tag/users/GET/users/{userId}
|
|
25
|
+
*/
|
|
26
|
+
interface ZoomProfile extends Record<string, any> {
|
|
27
|
+
/** The user's account ID (Example: "q6gBJVO5TzexKYTb_I2rpg") */
|
|
28
|
+
account_id: string;
|
|
29
|
+
/** The user's account number (Example: 10009239) */
|
|
30
|
+
account_number: number;
|
|
31
|
+
/** The user's cluster (Example: "us04") */
|
|
32
|
+
cluster: string;
|
|
33
|
+
/** The user's CMS ID. Only enabled for Kaltura integration (Example: "KDcuGIm1QgePTO8WbOqwIQ") */
|
|
34
|
+
cms_user_id: string;
|
|
35
|
+
/** The user's cost center (Example: "cost center") */
|
|
36
|
+
cost_center: string;
|
|
37
|
+
/** User create time (Example: "2018-10-31T04:32:37Z") */
|
|
38
|
+
created_at: string;
|
|
39
|
+
/** Department (Example: "Developers") */
|
|
40
|
+
dept: string;
|
|
41
|
+
/** User's display name (Example: "Jill Chill") */
|
|
42
|
+
display_name: string;
|
|
43
|
+
/** User's email address (Example: "jchill@example.com") */
|
|
44
|
+
email: string;
|
|
45
|
+
/** User's first name (Example: "Jill") */
|
|
46
|
+
first_name: string;
|
|
47
|
+
/** IDs of the web groups that the user belongs to (Example: ["RSMaSp8sTEGK0_oamiA2_w"]) */
|
|
48
|
+
group_ids: string[];
|
|
49
|
+
/** User ID (Example: "zJKyaiAyTNC-MWjiWC18KQ") */
|
|
50
|
+
id: string;
|
|
51
|
+
/** IM IDs of the groups that the user belongs to (Example: ["t-_-d56CSWG-7BF15LLrOw"]) */
|
|
52
|
+
im_group_ids: string[];
|
|
53
|
+
/** The user's JID (Example: "jchill@example.com") */
|
|
54
|
+
jid: string;
|
|
55
|
+
/** The user's job title (Example: "API Developer") */
|
|
56
|
+
job_title: string;
|
|
57
|
+
/** Default language for the Zoom Web Portal (Example: "en-US") */
|
|
58
|
+
language: string;
|
|
59
|
+
/** User last login client version (Example: "5.9.6.4993(mac)") */
|
|
60
|
+
last_client_version: string;
|
|
61
|
+
/** User last login time (Example: "2021-05-05T20:40:30Z") */
|
|
62
|
+
last_login_time: string;
|
|
63
|
+
/** User's last name (Example: "Chill") */
|
|
64
|
+
last_name: string;
|
|
65
|
+
/** The time zone of the user (Example: "Asia/Shanghai") */
|
|
66
|
+
timezone: string;
|
|
67
|
+
/** User's location (Example: "Paris") */
|
|
68
|
+
location: string;
|
|
69
|
+
/** The user's login method (Example: 101) */
|
|
70
|
+
login_types: LoginType[];
|
|
71
|
+
/** User's personal meeting URL (Example: "example.com") */
|
|
72
|
+
personal_meeting_url: string;
|
|
73
|
+
/** This field has been deprecated and will not be supported in the future.
|
|
74
|
+
* Use the phone_numbers field instead of this field.
|
|
75
|
+
* The user's phone number (Example: "+1 800000000") */
|
|
76
|
+
phone_number?: string | undefined;
|
|
77
|
+
/** The URL for user's profile picture (Example: "example.com") */
|
|
78
|
+
pic_url: string;
|
|
79
|
+
/** Personal Meeting ID (PMI) (Example: 3542471135) */
|
|
80
|
+
pmi: number;
|
|
81
|
+
/** Unique identifier of the user's assigned role (Example: "0") */
|
|
82
|
+
role_id: string;
|
|
83
|
+
/** User's role name (Example: "Admin") */
|
|
84
|
+
role_name: string;
|
|
85
|
+
/** Status of user's account (Example: "pending") */
|
|
86
|
+
status: AccountStatus;
|
|
87
|
+
/** Use the personal meeting ID (PMI) for instant meetings (Example: false) */
|
|
88
|
+
use_pmi: boolean;
|
|
89
|
+
/** The time and date when the user was created (Example: "2018-10-31T04:32:37Z") */
|
|
90
|
+
user_created_at: string;
|
|
91
|
+
/** Displays whether user is verified or not (Example: 1) */
|
|
92
|
+
verified: number;
|
|
93
|
+
/** The user's Zoom Workplace plan option (Example: 64) */
|
|
94
|
+
zoom_one_type: number;
|
|
95
|
+
/** The user's company (Example: "Jill") */
|
|
96
|
+
company?: string | undefined;
|
|
97
|
+
/** Custom attributes that have been assigned to the user (Example: [{ "key": "cbf_cywdkexrtqc73f97gd4w6g", "name": "A1", "value": "1" }]) */
|
|
98
|
+
custom_attributes?: {
|
|
99
|
+
key: string;
|
|
100
|
+
name: string;
|
|
101
|
+
value: string;
|
|
102
|
+
}[] | undefined;
|
|
103
|
+
/** 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") */
|
|
104
|
+
employee_unique_id?: string | undefined;
|
|
105
|
+
/** The manager for the user (Example: "thill@example.com") */
|
|
106
|
+
manager?: string | undefined;
|
|
107
|
+
/** The user's country for the company phone number (Example: "US")
|
|
108
|
+
* @deprecated true */
|
|
109
|
+
phone_country?: string | undefined;
|
|
110
|
+
/** The phone number's ISO country code (Example: "+1") */
|
|
111
|
+
phone_numbers?: PhoneNumber[] | undefined;
|
|
112
|
+
/** The user's plan type (Example: "1") */
|
|
113
|
+
plan_united_type?: string | undefined;
|
|
114
|
+
/** The user's pronouns (Example: "3123") */
|
|
115
|
+
pronouns?: string | undefined;
|
|
116
|
+
/** The user's display pronouns setting (Example: 1) */
|
|
117
|
+
pronouns_option?: PronounOption | undefined;
|
|
118
|
+
/** Personal meeting room URL, if the user has one (Example: "example.com") */
|
|
119
|
+
vanity_url?: string | undefined;
|
|
120
|
+
}
|
|
121
|
+
interface ZoomOptions extends ProviderOptions<ZoomProfile> {
|
|
122
|
+
clientId: string;
|
|
123
|
+
pkce?: boolean | undefined;
|
|
124
|
+
}
|
|
125
|
+
declare const zoom: (userOptions: ZoomOptions) => {
|
|
126
|
+
id: "zoom";
|
|
127
|
+
name: string;
|
|
128
|
+
createAuthorizationURL: ({
|
|
129
|
+
state,
|
|
130
|
+
redirectURI,
|
|
131
|
+
codeVerifier
|
|
132
|
+
}: {
|
|
133
|
+
state: string;
|
|
134
|
+
codeVerifier: string;
|
|
135
|
+
scopes?: string[] | undefined;
|
|
136
|
+
redirectURI: string;
|
|
137
|
+
display?: string | undefined;
|
|
138
|
+
loginHint?: string | undefined;
|
|
139
|
+
}) => Promise<URL>;
|
|
140
|
+
validateAuthorizationCode: ({
|
|
141
|
+
code,
|
|
142
|
+
redirectURI,
|
|
143
|
+
codeVerifier
|
|
144
|
+
}: {
|
|
145
|
+
code: string;
|
|
146
|
+
redirectURI: string;
|
|
147
|
+
codeVerifier?: string | undefined;
|
|
148
|
+
deviceId?: string | undefined;
|
|
149
|
+
}) => Promise<OAuth2Tokens>;
|
|
150
|
+
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
151
|
+
getUserInfo(token: OAuth2Tokens & {
|
|
152
|
+
user?: {
|
|
153
|
+
name
|
|
154
|
+
/** The user's cluster (Example: "us04") */? /** The user's cluster (Example: "us04") */: {
|
|
155
|
+
firstName?: string;
|
|
156
|
+
lastName?: string;
|
|
157
|
+
};
|
|
158
|
+
email?: string;
|
|
159
|
+
} | undefined;
|
|
160
|
+
}): Promise<{
|
|
161
|
+
user: {
|
|
162
|
+
id: string;
|
|
163
|
+
name?: string;
|
|
164
|
+
email?: string | null;
|
|
165
|
+
image?: string;
|
|
166
|
+
emailVerified: boolean;
|
|
167
|
+
[key: string]: any;
|
|
168
|
+
};
|
|
169
|
+
data: any;
|
|
170
|
+
} | null>;
|
|
171
|
+
};
|
|
172
|
+
//#endregion
|
|
173
|
+
export { AccountStatus, LoginType, PhoneNumber, PronounOption, ZoomOptions, ZoomProfile, zoom };
|
|
@@ -0,0 +1,72 @@
|
|
|
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 "../oauth2/index.mjs";
|
|
5
|
+
import { betterFetch } from "@better-fetch/fetch";
|
|
6
|
+
|
|
7
|
+
//#region src/social-providers/zoom.ts
|
|
8
|
+
const zoom = (userOptions) => {
|
|
9
|
+
const options = {
|
|
10
|
+
pkce: true,
|
|
11
|
+
...userOptions
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
id: "zoom",
|
|
15
|
+
name: "Zoom",
|
|
16
|
+
createAuthorizationURL: async ({ state, redirectURI, codeVerifier }) => {
|
|
17
|
+
const params = new URLSearchParams({
|
|
18
|
+
response_type: "code",
|
|
19
|
+
redirect_uri: options.redirectURI ? options.redirectURI : redirectURI,
|
|
20
|
+
client_id: options.clientId,
|
|
21
|
+
state
|
|
22
|
+
});
|
|
23
|
+
if (options.pkce) {
|
|
24
|
+
const codeChallenge = await generateCodeChallenge(codeVerifier);
|
|
25
|
+
params.set("code_challenge_method", "S256");
|
|
26
|
+
params.set("code_challenge", codeChallenge);
|
|
27
|
+
}
|
|
28
|
+
const url = new URL("https://zoom.us/oauth/authorize");
|
|
29
|
+
url.search = params.toString();
|
|
30
|
+
return url;
|
|
31
|
+
},
|
|
32
|
+
validateAuthorizationCode: async ({ code, redirectURI, codeVerifier }) => {
|
|
33
|
+
return validateAuthorizationCode({
|
|
34
|
+
code,
|
|
35
|
+
redirectURI: options.redirectURI || redirectURI,
|
|
36
|
+
codeVerifier,
|
|
37
|
+
options,
|
|
38
|
+
tokenEndpoint: "https://zoom.us/oauth/token",
|
|
39
|
+
authentication: "post"
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
refreshAccessToken: options.refreshAccessToken ? options.refreshAccessToken : async (refreshToken) => refreshAccessToken({
|
|
43
|
+
refreshToken,
|
|
44
|
+
options: {
|
|
45
|
+
clientId: options.clientId,
|
|
46
|
+
clientKey: options.clientKey,
|
|
47
|
+
clientSecret: options.clientSecret
|
|
48
|
+
},
|
|
49
|
+
tokenEndpoint: "https://zoom.us/oauth/token"
|
|
50
|
+
}),
|
|
51
|
+
async getUserInfo(token) {
|
|
52
|
+
if (options.getUserInfo) return options.getUserInfo(token);
|
|
53
|
+
const { data: profile, error } = await betterFetch("https://api.zoom.us/v2/users/me", { headers: { authorization: `Bearer ${token.accessToken}` } });
|
|
54
|
+
if (error) return null;
|
|
55
|
+
const userMap = await options.mapProfileToUser?.(profile);
|
|
56
|
+
return {
|
|
57
|
+
user: {
|
|
58
|
+
id: profile.id,
|
|
59
|
+
name: profile.display_name,
|
|
60
|
+
image: profile.pic_url,
|
|
61
|
+
email: profile.email,
|
|
62
|
+
emailVerified: Boolean(profile.verified),
|
|
63
|
+
...userMap
|
|
64
|
+
},
|
|
65
|
+
data: { ...profile }
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { zoom };
|