@better-auth/core 1.7.0-beta.7 → 1.7.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/dist/api/index.d.mts +3 -3
- package/dist/context/global.mjs +1 -1
- package/dist/db/adapter/factory.mjs +1 -1
- package/dist/db/get-tables.mjs +3 -3
- package/dist/db/schema/account.d.mts +1 -1
- package/dist/db/schema/account.mjs +1 -1
- package/dist/error/codes.d.mts +0 -5
- package/dist/error/codes.mjs +0 -5
- package/dist/instrumentation/tracer.mjs +1 -1
- package/dist/oauth2/create-authorization-url.d.mts +1 -4
- package/dist/oauth2/create-authorization-url.mjs +1 -4
- package/dist/oauth2/index.d.mts +3 -4
- package/dist/oauth2/index.mjs +2 -3
- package/dist/oauth2/oauth-provider.d.mts +12 -50
- package/dist/oauth2/refresh-access-token.mjs +2 -1
- package/dist/oauth2/utils.d.mts +6 -1
- package/dist/oauth2/utils.mjs +24 -2
- package/dist/oauth2/verify-id-token.d.mts +6 -5
- package/dist/oauth2/verify-id-token.mjs +2 -2
- package/dist/social-providers/apple.d.mts +1 -5
- package/dist/social-providers/apple.mjs +5 -5
- package/dist/social-providers/atlassian.d.mts +1 -5
- package/dist/social-providers/atlassian.mjs +4 -4
- package/dist/social-providers/cognito.d.mts +1 -5
- package/dist/social-providers/cognito.mjs +11 -18
- package/dist/social-providers/discord.d.mts +1 -5
- package/dist/social-providers/discord.mjs +6 -7
- package/dist/social-providers/dropbox.d.mts +1 -5
- package/dist/social-providers/dropbox.mjs +5 -5
- package/dist/social-providers/facebook.d.mts +1 -5
- package/dist/social-providers/facebook.mjs +5 -5
- package/dist/social-providers/figma.d.mts +1 -5
- package/dist/social-providers/figma.mjs +5 -5
- package/dist/social-providers/github.d.mts +1 -5
- package/dist/social-providers/github.mjs +4 -4
- package/dist/social-providers/gitlab.d.mts +1 -5
- package/dist/social-providers/gitlab.mjs +6 -6
- package/dist/social-providers/google.d.mts +8 -10
- package/dist/social-providers/google.mjs +12 -13
- package/dist/social-providers/huggingface.d.mts +1 -5
- package/dist/social-providers/huggingface.mjs +8 -8
- package/dist/social-providers/index.d.mts +35 -177
- package/dist/social-providers/kakao.d.mts +1 -5
- package/dist/social-providers/kakao.mjs +8 -8
- package/dist/social-providers/kick.d.mts +1 -5
- package/dist/social-providers/kick.mjs +4 -4
- package/dist/social-providers/line.d.mts +1 -5
- package/dist/social-providers/line.mjs +10 -10
- package/dist/social-providers/linear.d.mts +1 -5
- package/dist/social-providers/linear.mjs +4 -4
- package/dist/social-providers/linkedin.d.mts +1 -5
- package/dist/social-providers/linkedin.mjs +10 -10
- package/dist/social-providers/microsoft-entra-id.d.mts +1 -5
- package/dist/social-providers/microsoft-entra-id.mjs +10 -11
- package/dist/social-providers/naver.d.mts +1 -5
- package/dist/social-providers/naver.mjs +4 -4
- package/dist/social-providers/notion.d.mts +1 -5
- package/dist/social-providers/notion.mjs +4 -4
- package/dist/social-providers/paybin.d.mts +1 -5
- package/dist/social-providers/paybin.mjs +10 -10
- package/dist/social-providers/paypal.d.mts +1 -5
- package/dist/social-providers/paypal.mjs +2 -8
- package/dist/social-providers/polar.d.mts +1 -5
- package/dist/social-providers/polar.mjs +8 -8
- package/dist/social-providers/railway.d.mts +1 -5
- package/dist/social-providers/railway.mjs +9 -9
- package/dist/social-providers/reddit.d.mts +1 -5
- package/dist/social-providers/reddit.mjs +5 -5
- package/dist/social-providers/roblox.d.mts +1 -5
- package/dist/social-providers/roblox.mjs +5 -5
- package/dist/social-providers/salesforce.d.mts +1 -5
- package/dist/social-providers/salesforce.mjs +8 -8
- package/dist/social-providers/slack.d.mts +1 -5
- package/dist/social-providers/slack.mjs +9 -9
- package/dist/social-providers/spotify.d.mts +1 -5
- package/dist/social-providers/spotify.mjs +5 -5
- package/dist/social-providers/tiktok.d.mts +1 -5
- package/dist/social-providers/tiktok.mjs +5 -9
- package/dist/social-providers/twitch.d.mts +1 -5
- package/dist/social-providers/twitch.mjs +4 -4
- package/dist/social-providers/twitter.d.mts +1 -5
- package/dist/social-providers/twitter.mjs +9 -9
- package/dist/social-providers/vercel.d.mts +1 -5
- package/dist/social-providers/vercel.mjs +7 -4
- package/dist/social-providers/vk.d.mts +1 -5
- package/dist/social-providers/vk.mjs +5 -5
- package/dist/social-providers/wechat.d.mts +1 -5
- package/dist/social-providers/wechat.mjs +5 -9
- package/dist/social-providers/zoom.d.mts +1 -6
- package/dist/social-providers/zoom.mjs +9 -15
- package/dist/types/context.d.mts +6 -2
- package/package.json +1 -1
- package/src/db/get-tables.ts +3 -8
- package/src/db/schema/account.ts +5 -14
- package/src/error/codes.ts +0 -5
- package/src/oauth2/create-authorization-url.ts +1 -1
- package/src/oauth2/index.ts +2 -12
- package/src/oauth2/oauth-provider.ts +11 -56
- package/src/oauth2/refresh-access-token.ts +3 -2
- package/src/oauth2/utils.ts +39 -1
- package/src/oauth2/verify-id-token.ts +7 -5
- package/src/social-providers/apple.ts +8 -13
- package/src/social-providers/atlassian.ts +8 -12
- package/src/social-providers/cognito.ts +11 -18
- package/src/social-providers/discord.ts +8 -19
- package/src/social-providers/dropbox.ts +7 -13
- package/src/social-providers/facebook.ts +9 -13
- package/src/social-providers/figma.ts +9 -13
- package/src/social-providers/github.ts +8 -12
- package/src/social-providers/gitlab.ts +8 -14
- package/src/social-providers/google.ts +23 -29
- package/src/social-providers/huggingface.ts +8 -12
- package/src/social-providers/kakao.ts +8 -16
- package/src/social-providers/kick.ts +7 -12
- package/src/social-providers/line.ts +10 -14
- package/src/social-providers/linear.ts +6 -12
- package/src/social-providers/linkedin.ts +10 -14
- package/src/social-providers/microsoft-entra-id.ts +8 -18
- package/src/social-providers/naver.ts +6 -12
- package/src/social-providers/notion.ts +6 -12
- package/src/social-providers/paybin.ts +11 -14
- package/src/social-providers/paypal.ts +8 -6
- package/src/social-providers/polar.ts +8 -12
- package/src/social-providers/railway.ts +9 -13
- package/src/social-providers/reddit.ts +7 -18
- package/src/social-providers/roblox.ts +7 -18
- package/src/social-providers/salesforce.ts +8 -12
- package/src/social-providers/slack.ts +9 -18
- package/src/social-providers/spotify.ts +7 -13
- package/src/social-providers/tiktok.ts +7 -13
- package/src/social-providers/twitch.ts +8 -12
- package/src/social-providers/twitter.ts +8 -17
- package/src/social-providers/vercel.ts +10 -16
- package/src/social-providers/vk.ts +7 -13
- package/src/social-providers/wechat.ts +8 -20
- package/src/social-providers/zoom.ts +6 -19
- package/src/types/context.ts +8 -2
- package/dist/oauth2/scopes.d.mts +0 -76
- package/dist/oauth2/scopes.mjs +0 -96
- package/src/oauth2/scopes.ts +0 -118
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import { resolveRequestedScopes } from "../oauth2/scopes.mjs";
|
|
2
1
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
3
2
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
4
3
|
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
5
4
|
import { betterFetch } from "@better-fetch/fetch";
|
|
6
5
|
//#region src/social-providers/discord.ts
|
|
7
|
-
const DISCORD_DEFAULT_SCOPES = ["identify", "email"];
|
|
8
6
|
const discord = (options) => {
|
|
9
7
|
const tokenEndpoint = "https://discord.com/api/oauth2/token";
|
|
10
8
|
return {
|
|
11
9
|
id: "discord",
|
|
12
10
|
name: "Discord",
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
|
|
12
|
+
const _scopes = options.disableDefaultScope ? [] : ["identify", "email"];
|
|
13
|
+
if (scopes) _scopes.push(...scopes);
|
|
14
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
15
|
+
const hasBotScope = _scopes.includes("bot");
|
|
17
16
|
return createAuthorizationURL({
|
|
18
17
|
id: "discord",
|
|
19
18
|
options,
|
|
20
19
|
authorizationEndpoint: "https://discord.com/api/oauth2/authorize",
|
|
21
|
-
scopes:
|
|
20
|
+
scopes: _scopes,
|
|
22
21
|
state,
|
|
23
22
|
redirectURI,
|
|
24
23
|
prompt: options.prompt || "none",
|
|
@@ -20,7 +20,6 @@ interface DropboxOptions extends ProviderOptions<DropboxProfile> {
|
|
|
20
20
|
declare const dropbox: (options: DropboxOptions) => {
|
|
21
21
|
id: "dropbox";
|
|
22
22
|
name: string;
|
|
23
|
-
callbackPath: string;
|
|
24
23
|
createAuthorizationURL: ({
|
|
25
24
|
state,
|
|
26
25
|
scopes,
|
|
@@ -36,10 +35,7 @@ declare const dropbox: (options: DropboxOptions) => {
|
|
|
36
35
|
loginHint?: string | undefined;
|
|
37
36
|
idTokenNonce?: string | undefined;
|
|
38
37
|
additionalParams?: Record<string, string> | undefined;
|
|
39
|
-
}) => Promise<
|
|
40
|
-
url: URL;
|
|
41
|
-
requestedScopes: string[];
|
|
42
|
-
}>;
|
|
38
|
+
}) => Promise<URL>;
|
|
43
39
|
validateAuthorizationCode: ({
|
|
44
40
|
code,
|
|
45
41
|
codeVerifier,
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { resolveRequestedScopes } from "../oauth2/scopes.mjs";
|
|
2
1
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
3
2
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
4
3
|
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
5
4
|
import { betterFetch } from "@better-fetch/fetch";
|
|
6
5
|
//#region src/social-providers/dropbox.ts
|
|
7
|
-
const DROPBOX_DEFAULT_SCOPES = ["account_info.read"];
|
|
8
6
|
const dropbox = (options) => {
|
|
9
7
|
const tokenEndpoint = "https://api.dropboxapi.com/oauth2/token";
|
|
10
8
|
return {
|
|
11
9
|
id: "dropbox",
|
|
12
10
|
name: "Dropbox",
|
|
13
|
-
callbackPath: "/callback/dropbox",
|
|
14
11
|
createAuthorizationURL: async ({ state, scopes, codeVerifier, redirectURI, additionalParams }) => {
|
|
15
|
-
|
|
12
|
+
const _scopes = options.disableDefaultScope ? [] : ["account_info.read"];
|
|
13
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
14
|
+
if (scopes) _scopes.push(...scopes);
|
|
15
|
+
return await createAuthorizationURL({
|
|
16
16
|
id: "dropbox",
|
|
17
17
|
options,
|
|
18
18
|
authorizationEndpoint: "https://www.dropbox.com/oauth2/authorize",
|
|
19
|
-
scopes:
|
|
19
|
+
scopes: _scopes,
|
|
20
20
|
state,
|
|
21
21
|
redirectURI,
|
|
22
22
|
codeVerifier,
|
|
@@ -32,7 +32,6 @@ interface FacebookOptions extends ProviderOptions<FacebookProfile> {
|
|
|
32
32
|
declare const facebook: (options: FacebookOptions) => {
|
|
33
33
|
id: "facebook";
|
|
34
34
|
name: string;
|
|
35
|
-
callbackPath: string;
|
|
36
35
|
createAuthorizationURL({
|
|
37
36
|
state,
|
|
38
37
|
scopes,
|
|
@@ -48,10 +47,7 @@ declare const facebook: (options: FacebookOptions) => {
|
|
|
48
47
|
loginHint?: string | undefined;
|
|
49
48
|
idTokenNonce?: string | undefined;
|
|
50
49
|
additionalParams?: Record<string, string> | undefined;
|
|
51
|
-
}): Promise<
|
|
52
|
-
url: URL;
|
|
53
|
-
requestedScopes: string[];
|
|
54
|
-
}>;
|
|
50
|
+
}): Promise<URL>;
|
|
55
51
|
validateAuthorizationCode: ({
|
|
56
52
|
code,
|
|
57
53
|
redirectURI
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BetterAuthError } from "../error/index.mjs";
|
|
2
2
|
import { logger } from "../env/logger.mjs";
|
|
3
|
-
import { resolveRequestedScopes } from "../oauth2/scopes.mjs";
|
|
4
3
|
import { getPrimaryClientId } from "../oauth2/utils.mjs";
|
|
5
4
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
6
5
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
@@ -36,22 +35,23 @@ async function verifyFacebookAccessToken(accessToken, options) {
|
|
|
36
35
|
if (is_valid !== true || !app_id || !clientIds.includes(app_id) || !user_id) return null;
|
|
37
36
|
return user_id;
|
|
38
37
|
}
|
|
39
|
-
const FACEBOOK_DEFAULT_SCOPES = ["email", "public_profile"];
|
|
40
38
|
const facebook = (options) => {
|
|
41
39
|
return {
|
|
42
40
|
id: "facebook",
|
|
43
41
|
name: "Facebook",
|
|
44
|
-
callbackPath: "/callback/facebook",
|
|
45
42
|
async createAuthorizationURL({ state, scopes, redirectURI, loginHint, additionalParams }) {
|
|
46
43
|
if (!getPrimaryClientId(options.clientId) || !options.clientSecret) {
|
|
47
44
|
logger.error("Client ID and client secret are required for Facebook. Make sure to provide them in the options.");
|
|
48
45
|
throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
|
|
49
46
|
}
|
|
50
|
-
|
|
47
|
+
const _scopes = options.disableDefaultScope ? [] : ["email", "public_profile"];
|
|
48
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
49
|
+
if (scopes) _scopes.push(...scopes);
|
|
50
|
+
return await createAuthorizationURL({
|
|
51
51
|
id: "facebook",
|
|
52
52
|
options,
|
|
53
53
|
authorizationEndpoint: "https://www.facebook.com/v24.0/dialog/oauth",
|
|
54
|
-
scopes:
|
|
54
|
+
scopes: _scopes,
|
|
55
55
|
state,
|
|
56
56
|
redirectURI,
|
|
57
57
|
loginHint,
|
|
@@ -12,7 +12,6 @@ interface FigmaOptions extends ProviderOptions<FigmaProfile> {
|
|
|
12
12
|
declare const figma: (options: FigmaOptions) => {
|
|
13
13
|
id: "figma";
|
|
14
14
|
name: string;
|
|
15
|
-
callbackPath: string;
|
|
16
15
|
createAuthorizationURL({
|
|
17
16
|
state,
|
|
18
17
|
scopes,
|
|
@@ -28,10 +27,7 @@ declare const figma: (options: FigmaOptions) => {
|
|
|
28
27
|
loginHint?: string | undefined;
|
|
29
28
|
idTokenNonce?: string | undefined;
|
|
30
29
|
additionalParams?: Record<string, string> | undefined;
|
|
31
|
-
}): Promise<
|
|
32
|
-
url: URL;
|
|
33
|
-
requestedScopes: string[];
|
|
34
|
-
}>;
|
|
30
|
+
}): Promise<URL>;
|
|
35
31
|
validateAuthorizationCode: ({
|
|
36
32
|
code,
|
|
37
33
|
codeVerifier,
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { BetterAuthError } from "../error/index.mjs";
|
|
2
2
|
import { logger } from "../env/logger.mjs";
|
|
3
|
-
import { resolveRequestedScopes } from "../oauth2/scopes.mjs";
|
|
4
3
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
5
4
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
6
5
|
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
7
6
|
import { betterFetch } from "@better-fetch/fetch";
|
|
8
7
|
//#region src/social-providers/figma.ts
|
|
9
|
-
const FIGMA_DEFAULT_SCOPES = ["current_user:read"];
|
|
10
8
|
const figma = (options) => {
|
|
11
9
|
const tokenEndpoint = "https://api.figma.com/v1/oauth/token";
|
|
12
10
|
return {
|
|
13
11
|
id: "figma",
|
|
14
12
|
name: "Figma",
|
|
15
|
-
callbackPath: "/callback/figma",
|
|
16
13
|
async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, additionalParams }) {
|
|
17
14
|
if (!options.clientId || !options.clientSecret) {
|
|
18
15
|
logger.error("Client Id and Client Secret are required for Figma. Make sure to provide them in the options.");
|
|
19
16
|
throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
|
|
20
17
|
}
|
|
21
18
|
if (!codeVerifier) throw new BetterAuthError("codeVerifier is required for Figma");
|
|
22
|
-
|
|
19
|
+
const _scopes = options.disableDefaultScope ? [] : ["current_user:read"];
|
|
20
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
21
|
+
if (scopes) _scopes.push(...scopes);
|
|
22
|
+
return await createAuthorizationURL({
|
|
23
23
|
id: "figma",
|
|
24
24
|
options,
|
|
25
25
|
authorizationEndpoint: "https://www.figma.com/oauth",
|
|
26
|
-
scopes:
|
|
26
|
+
scopes: _scopes,
|
|
27
27
|
state,
|
|
28
28
|
codeVerifier,
|
|
29
29
|
redirectURI,
|
|
@@ -52,7 +52,6 @@ interface GithubOptions extends ProviderOptions<GithubProfile> {
|
|
|
52
52
|
declare const github: (options: GithubOptions) => {
|
|
53
53
|
id: "github";
|
|
54
54
|
name: string;
|
|
55
|
-
callbackPath: string;
|
|
56
55
|
createAuthorizationURL({
|
|
57
56
|
state,
|
|
58
57
|
scopes,
|
|
@@ -69,10 +68,7 @@ declare const github: (options: GithubOptions) => {
|
|
|
69
68
|
loginHint?: string | undefined;
|
|
70
69
|
idTokenNonce?: string | undefined;
|
|
71
70
|
additionalParams?: Record<string, string> | undefined;
|
|
72
|
-
}): Promise<
|
|
73
|
-
url: URL;
|
|
74
|
-
requestedScopes: string[];
|
|
75
|
-
}>;
|
|
71
|
+
}): Promise<URL>;
|
|
76
72
|
validateAuthorizationCode: ({
|
|
77
73
|
code,
|
|
78
74
|
codeVerifier,
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { logger } from "../env/logger.mjs";
|
|
2
|
-
import { resolveRequestedScopes } from "../oauth2/scopes.mjs";
|
|
3
2
|
import { getOAuth2Tokens } from "../oauth2/utils.mjs";
|
|
4
3
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
5
4
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
6
5
|
import { authorizationCodeRequest } from "../oauth2/validate-authorization-code.mjs";
|
|
7
6
|
import { betterFetch } from "@better-fetch/fetch";
|
|
8
7
|
//#region src/social-providers/github.ts
|
|
9
|
-
const GITHUB_DEFAULT_SCOPES = ["read:user", "user:email"];
|
|
10
8
|
const github = (options) => {
|
|
11
9
|
const tokenEndpoint = "https://github.com/login/oauth/access_token";
|
|
12
10
|
return {
|
|
13
11
|
id: "github",
|
|
14
12
|
name: "GitHub",
|
|
15
|
-
callbackPath: "/callback/github",
|
|
16
13
|
createAuthorizationURL({ state, scopes, loginHint, codeVerifier, redirectURI, additionalParams }) {
|
|
14
|
+
const _scopes = options.disableDefaultScope ? [] : ["read:user", "user:email"];
|
|
15
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
16
|
+
if (scopes) _scopes.push(...scopes);
|
|
17
17
|
return createAuthorizationURL({
|
|
18
18
|
id: "github",
|
|
19
19
|
options,
|
|
20
20
|
authorizationEndpoint: "https://github.com/login/oauth/authorize",
|
|
21
|
-
scopes:
|
|
21
|
+
scopes: _scopes,
|
|
22
22
|
state,
|
|
23
23
|
codeVerifier,
|
|
24
24
|
redirectURI,
|
|
@@ -52,7 +52,6 @@ interface GitlabOptions extends ProviderOptions<GitlabProfile> {
|
|
|
52
52
|
declare const gitlab: (options: GitlabOptions) => {
|
|
53
53
|
id: "gitlab";
|
|
54
54
|
name: string;
|
|
55
|
-
callbackPath: string;
|
|
56
55
|
createAuthorizationURL: ({
|
|
57
56
|
state,
|
|
58
57
|
scopes,
|
|
@@ -69,10 +68,7 @@ declare const gitlab: (options: GitlabOptions) => {
|
|
|
69
68
|
loginHint?: string | undefined;
|
|
70
69
|
idTokenNonce?: string | undefined;
|
|
71
70
|
additionalParams?: Record<string, string> | undefined;
|
|
72
|
-
}) => Promise<
|
|
73
|
-
url: URL;
|
|
74
|
-
requestedScopes: string[];
|
|
75
|
-
}>;
|
|
71
|
+
}) => Promise<URL>;
|
|
76
72
|
validateAuthorizationCode: ({
|
|
77
73
|
code,
|
|
78
74
|
redirectURI,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { resolveRequestedScopes } from "../oauth2/scopes.mjs";
|
|
2
1
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
3
2
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
4
3
|
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
@@ -15,20 +14,21 @@ const issuerToEndpoints = (issuer) => {
|
|
|
15
14
|
userinfoEndpoint: cleanDoubleSlashes(`${baseUrl}/api/v4/user`)
|
|
16
15
|
};
|
|
17
16
|
};
|
|
18
|
-
const GITLAB_DEFAULT_SCOPES = ["read_user"];
|
|
19
17
|
const gitlab = (options) => {
|
|
20
18
|
const { authorizationEndpoint, tokenEndpoint, userinfoEndpoint } = issuerToEndpoints(options.issuer);
|
|
21
19
|
const issuerId = "gitlab";
|
|
22
20
|
return {
|
|
23
21
|
id: issuerId,
|
|
24
22
|
name: "Gitlab",
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
createAuthorizationURL: async ({ state, scopes, codeVerifier, loginHint, redirectURI, additionalParams }) => {
|
|
24
|
+
const _scopes = options.disableDefaultScope ? [] : ["read_user"];
|
|
25
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
26
|
+
if (scopes) _scopes.push(...scopes);
|
|
27
|
+
return await createAuthorizationURL({
|
|
28
28
|
id: issuerId,
|
|
29
29
|
options,
|
|
30
30
|
authorizationEndpoint,
|
|
31
|
-
scopes:
|
|
31
|
+
scopes: _scopes,
|
|
32
32
|
state,
|
|
33
33
|
redirectURI,
|
|
34
34
|
codeVerifier,
|
|
@@ -48,19 +48,20 @@ interface GoogleOptions extends ProviderOptions<GoogleProfile> {
|
|
|
48
48
|
*/
|
|
49
49
|
hd?: string | undefined;
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* in the
|
|
51
|
+
* Whether to send `include_granted_scopes=true` to Google's authorization
|
|
52
|
+
* endpoint, which lets new access tokens cover scopes from prior grants
|
|
53
|
+
* in addition to the ones requested for this flow. Set to `false` when
|
|
54
|
+
* each OAuth flow should request only its own scopes.
|
|
54
55
|
*
|
|
55
|
-
*
|
|
56
|
+
* Defaults to `true`.
|
|
57
|
+
*
|
|
58
|
+
* @see https://developers.google.com/identity/protocols/oauth2/web-server#incrementalAuth
|
|
56
59
|
*/
|
|
57
60
|
includeGrantedScopes?: boolean | undefined;
|
|
58
61
|
}
|
|
59
62
|
declare const google: (options: GoogleOptions) => {
|
|
60
63
|
id: "google";
|
|
61
64
|
name: string;
|
|
62
|
-
callbackPath: string;
|
|
63
|
-
grantAuthority: "full-grant" | "projection";
|
|
64
65
|
createAuthorizationURL({
|
|
65
66
|
state,
|
|
66
67
|
scopes,
|
|
@@ -78,10 +79,7 @@ declare const google: (options: GoogleOptions) => {
|
|
|
78
79
|
loginHint?: string | undefined;
|
|
79
80
|
idTokenNonce?: string | undefined;
|
|
80
81
|
additionalParams?: Record<string, string> | undefined;
|
|
81
|
-
}): Promise<
|
|
82
|
-
url: URL;
|
|
83
|
-
requestedScopes: string[];
|
|
84
|
-
}>;
|
|
82
|
+
}): Promise<URL>;
|
|
85
83
|
validateAuthorizationCode: ({
|
|
86
84
|
code,
|
|
87
85
|
codeVerifier,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { APIError, BetterAuthError } from "../error/index.mjs";
|
|
2
2
|
import { logger } from "../env/logger.mjs";
|
|
3
|
-
import { resolveRequestedScopes } from "../oauth2/scopes.mjs";
|
|
4
3
|
import { getPrimaryClientId } from "../oauth2/utils.mjs";
|
|
5
4
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
6
5
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
@@ -8,28 +7,28 @@ import { validateAuthorizationCode } from "../oauth2/validate-authorization-code
|
|
|
8
7
|
import { decodeJwt, importJWK } from "jose";
|
|
9
8
|
import { betterFetch } from "@better-fetch/fetch";
|
|
10
9
|
//#region src/social-providers/google.ts
|
|
11
|
-
const GOOGLE_DEFAULT_SCOPES = [
|
|
12
|
-
"email",
|
|
13
|
-
"profile",
|
|
14
|
-
"openid"
|
|
15
|
-
];
|
|
16
10
|
const google = (options) => {
|
|
17
11
|
return {
|
|
18
12
|
id: "google",
|
|
19
13
|
name: "Google",
|
|
20
|
-
callbackPath: "/callback/google",
|
|
21
|
-
grantAuthority: options.includeGrantedScopes !== false ? "full-grant" : "projection",
|
|
22
14
|
async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, loginHint, display, additionalParams }) {
|
|
23
15
|
if (!getPrimaryClientId(options.clientId) || !options.clientSecret) {
|
|
24
16
|
logger.error("Client Id and Client Secret is required for Google. Make sure to provide them in the options.");
|
|
25
17
|
throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
|
|
26
18
|
}
|
|
27
19
|
if (!codeVerifier) throw new BetterAuthError("codeVerifier is required for Google");
|
|
28
|
-
|
|
20
|
+
const _scopes = options.disableDefaultScope ? [] : [
|
|
21
|
+
"email",
|
|
22
|
+
"profile",
|
|
23
|
+
"openid"
|
|
24
|
+
];
|
|
25
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
26
|
+
if (scopes) _scopes.push(...scopes);
|
|
27
|
+
return await createAuthorizationURL({
|
|
29
28
|
id: "google",
|
|
30
29
|
options,
|
|
31
30
|
authorizationEndpoint: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
32
|
-
scopes:
|
|
31
|
+
scopes: _scopes,
|
|
33
32
|
state,
|
|
34
33
|
codeVerifier,
|
|
35
34
|
redirectURI,
|
|
@@ -38,9 +37,9 @@ const google = (options) => {
|
|
|
38
37
|
display: display || options.display,
|
|
39
38
|
loginHint,
|
|
40
39
|
hd: options.hd,
|
|
41
|
-
additionalParams:
|
|
42
|
-
...
|
|
43
|
-
|
|
40
|
+
additionalParams: {
|
|
41
|
+
...options.includeGrantedScopes === false ? {} : { include_granted_scopes: "true" },
|
|
42
|
+
...additionalParams ?? {}
|
|
44
43
|
}
|
|
45
44
|
});
|
|
46
45
|
},
|
|
@@ -34,7 +34,6 @@ interface HuggingFaceOptions extends ProviderOptions<HuggingFaceProfile> {
|
|
|
34
34
|
declare const huggingface: (options: HuggingFaceOptions) => {
|
|
35
35
|
id: "huggingface";
|
|
36
36
|
name: string;
|
|
37
|
-
callbackPath: string;
|
|
38
37
|
createAuthorizationURL({
|
|
39
38
|
state,
|
|
40
39
|
scopes,
|
|
@@ -50,10 +49,7 @@ declare const huggingface: (options: HuggingFaceOptions) => {
|
|
|
50
49
|
loginHint?: string | undefined;
|
|
51
50
|
idTokenNonce?: string | undefined;
|
|
52
51
|
additionalParams?: Record<string, string> | undefined;
|
|
53
|
-
}): Promise<
|
|
54
|
-
url: URL;
|
|
55
|
-
requestedScopes: string[];
|
|
56
|
-
}>;
|
|
52
|
+
}): Promise<URL>;
|
|
57
53
|
validateAuthorizationCode: ({
|
|
58
54
|
code,
|
|
59
55
|
codeVerifier,
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { resolveRequestedScopes } from "../oauth2/scopes.mjs";
|
|
2
1
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
3
2
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
4
3
|
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
5
4
|
import { betterFetch } from "@better-fetch/fetch";
|
|
6
5
|
//#region src/social-providers/huggingface.ts
|
|
7
|
-
const HUGGINGFACE_DEFAULT_SCOPES = [
|
|
8
|
-
"openid",
|
|
9
|
-
"profile",
|
|
10
|
-
"email"
|
|
11
|
-
];
|
|
12
6
|
const huggingface = (options) => {
|
|
13
7
|
const tokenEndpoint = "https://huggingface.co/oauth/token";
|
|
14
8
|
return {
|
|
15
9
|
id: "huggingface",
|
|
16
10
|
name: "Hugging Face",
|
|
17
|
-
callbackPath: "/callback/huggingface",
|
|
18
11
|
createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, additionalParams }) {
|
|
12
|
+
const _scopes = options.disableDefaultScope ? [] : [
|
|
13
|
+
"openid",
|
|
14
|
+
"profile",
|
|
15
|
+
"email"
|
|
16
|
+
];
|
|
17
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
18
|
+
if (scopes) _scopes.push(...scopes);
|
|
19
19
|
return createAuthorizationURL({
|
|
20
20
|
id: "huggingface",
|
|
21
21
|
options,
|
|
22
22
|
authorizationEndpoint: "https://huggingface.co/oauth/authorize",
|
|
23
|
-
scopes:
|
|
23
|
+
scopes: _scopes,
|
|
24
24
|
state,
|
|
25
25
|
codeVerifier,
|
|
26
26
|
redirectURI,
|