@better-auth/core 1.7.0-beta.6 → 1.7.0-beta.8
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/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 +4 -5
- package/dist/oauth2/create-authorization-url.mjs +4 -5
- package/dist/oauth2/index.d.mts +3 -4
- package/dist/oauth2/index.mjs +2 -3
- package/dist/oauth2/oauth-provider.d.mts +44 -48
- package/dist/oauth2/refresh-access-token.mjs +17 -2
- 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 +3 -5
- package/dist/social-providers/apple.mjs +5 -5
- package/dist/social-providers/atlassian.d.mts +3 -5
- package/dist/social-providers/atlassian.mjs +4 -4
- package/dist/social-providers/cognito.d.mts +3 -5
- package/dist/social-providers/cognito.mjs +11 -18
- package/dist/social-providers/discord.d.mts +3 -5
- package/dist/social-providers/discord.mjs +6 -7
- package/dist/social-providers/dropbox.d.mts +3 -5
- package/dist/social-providers/dropbox.mjs +5 -5
- package/dist/social-providers/facebook.d.mts +3 -5
- package/dist/social-providers/facebook.mjs +5 -5
- package/dist/social-providers/figma.d.mts +3 -5
- package/dist/social-providers/figma.mjs +5 -5
- package/dist/social-providers/github.d.mts +3 -5
- package/dist/social-providers/github.mjs +4 -4
- package/dist/social-providers/gitlab.d.mts +3 -5
- package/dist/social-providers/gitlab.mjs +6 -6
- package/dist/social-providers/google.d.mts +10 -10
- package/dist/social-providers/google.mjs +12 -13
- package/dist/social-providers/huggingface.d.mts +3 -5
- package/dist/social-providers/huggingface.mjs +8 -8
- package/dist/social-providers/index.d.mts +105 -177
- package/dist/social-providers/kakao.d.mts +3 -5
- package/dist/social-providers/kakao.mjs +8 -8
- package/dist/social-providers/kick.d.mts +3 -5
- package/dist/social-providers/kick.mjs +4 -4
- package/dist/social-providers/line.d.mts +3 -5
- package/dist/social-providers/line.mjs +10 -10
- package/dist/social-providers/linear.d.mts +3 -5
- package/dist/social-providers/linear.mjs +4 -4
- package/dist/social-providers/linkedin.d.mts +3 -5
- package/dist/social-providers/linkedin.mjs +10 -10
- package/dist/social-providers/microsoft-entra-id.d.mts +3 -5
- package/dist/social-providers/microsoft-entra-id.mjs +10 -11
- package/dist/social-providers/naver.d.mts +3 -5
- package/dist/social-providers/naver.mjs +4 -4
- package/dist/social-providers/notion.d.mts +3 -5
- package/dist/social-providers/notion.mjs +4 -4
- package/dist/social-providers/paybin.d.mts +3 -5
- package/dist/social-providers/paybin.mjs +10 -10
- package/dist/social-providers/paypal.d.mts +3 -5
- package/dist/social-providers/paypal.mjs +2 -8
- package/dist/social-providers/polar.d.mts +3 -5
- package/dist/social-providers/polar.mjs +8 -8
- package/dist/social-providers/railway.d.mts +3 -5
- package/dist/social-providers/railway.mjs +9 -9
- package/dist/social-providers/reddit.d.mts +3 -5
- package/dist/social-providers/reddit.mjs +5 -5
- package/dist/social-providers/roblox.d.mts +3 -5
- package/dist/social-providers/roblox.mjs +5 -5
- package/dist/social-providers/salesforce.d.mts +3 -5
- package/dist/social-providers/salesforce.mjs +8 -8
- package/dist/social-providers/slack.d.mts +3 -5
- package/dist/social-providers/slack.mjs +9 -9
- package/dist/social-providers/spotify.d.mts +3 -5
- package/dist/social-providers/spotify.mjs +5 -5
- package/dist/social-providers/tiktok.d.mts +3 -5
- package/dist/social-providers/tiktok.mjs +5 -9
- package/dist/social-providers/twitch.d.mts +3 -5
- package/dist/social-providers/twitch.mjs +4 -4
- package/dist/social-providers/twitter.d.mts +3 -5
- package/dist/social-providers/twitter.mjs +9 -9
- package/dist/social-providers/vercel.d.mts +3 -5
- package/dist/social-providers/vercel.mjs +7 -4
- package/dist/social-providers/vk.d.mts +3 -5
- package/dist/social-providers/vk.mjs +5 -5
- package/dist/social-providers/wechat.d.mts +3 -5
- package/dist/social-providers/wechat.mjs +5 -9
- package/dist/social-providers/zoom.d.mts +3 -6
- package/dist/social-providers/zoom.mjs +9 -15
- package/dist/types/context.d.mts +6 -2
- package/dist/utils/host.d.mts +1 -1
- package/dist/utils/host.mjs +3 -0
- 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 +5 -1
- package/src/oauth2/index.ts +3 -12
- package/src/oauth2/oauth-provider.ts +46 -53
- package/src/oauth2/refresh-access-token.ts +30 -5
- package/src/oauth2/utils.ts +39 -1
- package/src/oauth2/verify-id-token.ts +9 -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/src/utils/host.ts +10 -1
- package/dist/oauth2/scopes.d.mts +0 -76
- package/dist/oauth2/scopes.mjs +0 -96
- package/src/oauth2/scopes.ts +0 -118
|
@@ -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/atlassian.ts
|
|
9
|
-
const ATLASSIAN_DEFAULT_SCOPES = ["read:jira-user", "offline_access"];
|
|
10
8
|
const atlassian = (options) => {
|
|
11
9
|
const tokenEndpoint = "https://auth.atlassian.com/oauth/token";
|
|
12
10
|
return {
|
|
13
11
|
id: "atlassian",
|
|
14
12
|
name: "Atlassian",
|
|
15
|
-
callbackPath: "/callback/atlassian",
|
|
16
13
|
async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, additionalParams }) {
|
|
17
14
|
if (!options.clientId || !options.clientSecret) {
|
|
18
15
|
logger.error("Client Id and Secret are required for Atlassian");
|
|
19
16
|
throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
|
|
20
17
|
}
|
|
21
18
|
if (!codeVerifier) throw new BetterAuthError("codeVerifier is required for Atlassian");
|
|
19
|
+
const _scopes = options.disableDefaultScope ? [] : ["read:jira-user", "offline_access"];
|
|
20
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
21
|
+
if (scopes) _scopes.push(...scopes);
|
|
22
22
|
return createAuthorizationURL({
|
|
23
23
|
id: "atlassian",
|
|
24
24
|
options,
|
|
25
25
|
authorizationEndpoint: "https://auth.atlassian.com/authorize",
|
|
26
|
-
scopes:
|
|
26
|
+
scopes: _scopes,
|
|
27
27
|
state,
|
|
28
28
|
codeVerifier,
|
|
29
29
|
redirectURI,
|
|
@@ -49,7 +49,6 @@ interface CognitoOptions extends ProviderOptions<CognitoProfile> {
|
|
|
49
49
|
declare const cognito: (options: CognitoOptions) => {
|
|
50
50
|
id: "cognito";
|
|
51
51
|
name: string;
|
|
52
|
-
callbackPath: string;
|
|
53
52
|
createAuthorizationURL({
|
|
54
53
|
state,
|
|
55
54
|
scopes,
|
|
@@ -63,11 +62,9 @@ declare const cognito: (options: CognitoOptions) => {
|
|
|
63
62
|
redirectURI: string;
|
|
64
63
|
display?: string | undefined;
|
|
65
64
|
loginHint?: string | undefined;
|
|
65
|
+
idTokenNonce?: string | undefined;
|
|
66
66
|
additionalParams?: Record<string, string> | undefined;
|
|
67
|
-
}): Promise<
|
|
68
|
-
url: URL;
|
|
69
|
-
requestedScopes: string[];
|
|
70
|
-
}>;
|
|
67
|
+
}): Promise<URL>;
|
|
71
68
|
validateAuthorizationCode: ({
|
|
72
69
|
code,
|
|
73
70
|
codeVerifier,
|
|
@@ -86,6 +83,7 @@ declare const cognito: (options: CognitoOptions) => {
|
|
|
86
83
|
maxTokenAge: string;
|
|
87
84
|
};
|
|
88
85
|
getUserInfo(token: OAuth2Tokens & {
|
|
86
|
+
expectedIdTokenNonce?: string | undefined;
|
|
89
87
|
user?: {
|
|
90
88
|
name?: {
|
|
91
89
|
firstName?: string;
|
|
@@ -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,11 +7,6 @@ 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/cognito.ts
|
|
11
|
-
const COGNITO_DEFAULT_SCOPES = [
|
|
12
|
-
"openid",
|
|
13
|
-
"profile",
|
|
14
|
-
"email"
|
|
15
|
-
];
|
|
16
10
|
const cognito = (options) => {
|
|
17
11
|
if (!options.domain || !options.region || !options.userPoolId) {
|
|
18
12
|
logger.error("Domain, region and userPoolId are required for Amazon Cognito. Make sure to provide them in the options.");
|
|
@@ -25,7 +19,6 @@ const cognito = (options) => {
|
|
|
25
19
|
return {
|
|
26
20
|
id: "cognito",
|
|
27
21
|
name: "Cognito",
|
|
28
|
-
callbackPath: "/callback/cognito",
|
|
29
22
|
async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, additionalParams }) {
|
|
30
23
|
if (!getPrimaryClientId(options.clientId)) {
|
|
31
24
|
logger.error("ClientId is required for Amazon Cognito. Make sure to provide them in the options.");
|
|
@@ -35,12 +28,18 @@ const cognito = (options) => {
|
|
|
35
28
|
logger.error("Client Secret is required when requireClientSecret is true. Make sure to provide it in the options.");
|
|
36
29
|
throw new BetterAuthError("CLIENT_SECRET_REQUIRED");
|
|
37
30
|
}
|
|
38
|
-
const
|
|
39
|
-
|
|
31
|
+
const _scopes = options.disableDefaultScope ? [] : [
|
|
32
|
+
"openid",
|
|
33
|
+
"profile",
|
|
34
|
+
"email"
|
|
35
|
+
];
|
|
36
|
+
if (options.scope) _scopes.push(...options.scope);
|
|
37
|
+
if (scopes) _scopes.push(...scopes);
|
|
38
|
+
const url = await createAuthorizationURL({
|
|
40
39
|
id: "cognito",
|
|
41
40
|
options: { ...options },
|
|
42
41
|
authorizationEndpoint,
|
|
43
|
-
scopes:
|
|
42
|
+
scopes: _scopes,
|
|
44
43
|
state,
|
|
45
44
|
codeVerifier,
|
|
46
45
|
redirectURI,
|
|
@@ -56,15 +55,9 @@ const cognito = (options) => {
|
|
|
56
55
|
const encodedScope = encodeURIComponent(scopeValue);
|
|
57
56
|
const urlString = url.toString();
|
|
58
57
|
const separator = urlString.includes("?") ? "&" : "?";
|
|
59
|
-
return {
|
|
60
|
-
url: new URL(`${urlString}${separator}scope=${encodedScope}`),
|
|
61
|
-
requestedScopes
|
|
62
|
-
};
|
|
58
|
+
return new URL(`${urlString}${separator}scope=${encodedScope}`);
|
|
63
59
|
}
|
|
64
|
-
return
|
|
65
|
-
url,
|
|
66
|
-
requestedScopes
|
|
67
|
-
};
|
|
60
|
+
return url;
|
|
68
61
|
},
|
|
69
62
|
validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
|
|
70
63
|
return validateAuthorizationCode({
|
|
@@ -77,7 +77,6 @@ interface DiscordOptions extends ProviderOptions<DiscordProfile> {
|
|
|
77
77
|
declare const discord: (options: DiscordOptions) => {
|
|
78
78
|
id: "discord";
|
|
79
79
|
name: string;
|
|
80
|
-
callbackPath: string;
|
|
81
80
|
createAuthorizationURL({
|
|
82
81
|
state,
|
|
83
82
|
scopes,
|
|
@@ -90,11 +89,9 @@ declare const discord: (options: DiscordOptions) => {
|
|
|
90
89
|
redirectURI: string;
|
|
91
90
|
display?: string | undefined;
|
|
92
91
|
loginHint?: string | undefined;
|
|
92
|
+
idTokenNonce?: string | undefined;
|
|
93
93
|
additionalParams?: Record<string, string> | undefined;
|
|
94
|
-
}): Promise<
|
|
95
|
-
url: URL;
|
|
96
|
-
requestedScopes: string[];
|
|
97
|
-
}>;
|
|
94
|
+
}): Promise<URL>;
|
|
98
95
|
validateAuthorizationCode: ({
|
|
99
96
|
code,
|
|
100
97
|
redirectURI
|
|
@@ -106,6 +103,7 @@ declare const discord: (options: DiscordOptions) => {
|
|
|
106
103
|
}) => Promise<OAuth2Tokens>;
|
|
107
104
|
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
108
105
|
getUserInfo(token: OAuth2Tokens & {
|
|
106
|
+
expectedIdTokenNonce?: string | undefined;
|
|
109
107
|
user?: {
|
|
110
108
|
name?: {
|
|
111
109
|
firstName?: string;
|
|
@@ -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,
|
|
@@ -34,11 +33,9 @@ declare const dropbox: (options: DropboxOptions) => {
|
|
|
34
33
|
redirectURI: string;
|
|
35
34
|
display?: string | undefined;
|
|
36
35
|
loginHint?: string | undefined;
|
|
36
|
+
idTokenNonce?: string | undefined;
|
|
37
37
|
additionalParams?: Record<string, string> | undefined;
|
|
38
|
-
}) => Promise<
|
|
39
|
-
url: URL;
|
|
40
|
-
requestedScopes: string[];
|
|
41
|
-
}>;
|
|
38
|
+
}) => Promise<URL>;
|
|
42
39
|
validateAuthorizationCode: ({
|
|
43
40
|
code,
|
|
44
41
|
codeVerifier,
|
|
@@ -51,6 +48,7 @@ declare const dropbox: (options: DropboxOptions) => {
|
|
|
51
48
|
}) => Promise<OAuth2Tokens>;
|
|
52
49
|
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
53
50
|
getUserInfo(token: OAuth2Tokens & {
|
|
51
|
+
expectedIdTokenNonce?: string | undefined;
|
|
54
52
|
user?: {
|
|
55
53
|
name?: {
|
|
56
54
|
firstName?: string;
|
|
@@ -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,
|
|
@@ -46,11 +45,9 @@ declare const facebook: (options: FacebookOptions) => {
|
|
|
46
45
|
redirectURI: string;
|
|
47
46
|
display?: string | undefined;
|
|
48
47
|
loginHint?: string | undefined;
|
|
48
|
+
idTokenNonce?: string | undefined;
|
|
49
49
|
additionalParams?: Record<string, string> | undefined;
|
|
50
|
-
}): Promise<
|
|
51
|
-
url: URL;
|
|
52
|
-
requestedScopes: string[];
|
|
53
|
-
}>;
|
|
50
|
+
}): Promise<URL>;
|
|
54
51
|
validateAuthorizationCode: ({
|
|
55
52
|
code,
|
|
56
53
|
redirectURI
|
|
@@ -76,6 +73,7 @@ declare const facebook: (options: FacebookOptions) => {
|
|
|
76
73
|
};
|
|
77
74
|
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
78
75
|
getUserInfo(token: OAuth2Tokens & {
|
|
76
|
+
expectedIdTokenNonce?: string | undefined;
|
|
79
77
|
user?: {
|
|
80
78
|
name?: {
|
|
81
79
|
firstName?: string;
|
|
@@ -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,
|
|
@@ -26,11 +25,9 @@ declare const figma: (options: FigmaOptions) => {
|
|
|
26
25
|
redirectURI: string;
|
|
27
26
|
display?: string | undefined;
|
|
28
27
|
loginHint?: string | undefined;
|
|
28
|
+
idTokenNonce?: string | undefined;
|
|
29
29
|
additionalParams?: Record<string, string> | undefined;
|
|
30
|
-
}): Promise<
|
|
31
|
-
url: URL;
|
|
32
|
-
requestedScopes: string[];
|
|
33
|
-
}>;
|
|
30
|
+
}): Promise<URL>;
|
|
34
31
|
validateAuthorizationCode: ({
|
|
35
32
|
code,
|
|
36
33
|
codeVerifier,
|
|
@@ -43,6 +40,7 @@ declare const figma: (options: FigmaOptions) => {
|
|
|
43
40
|
}) => Promise<OAuth2Tokens>;
|
|
44
41
|
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
45
42
|
getUserInfo(token: OAuth2Tokens & {
|
|
43
|
+
expectedIdTokenNonce?: string | undefined;
|
|
46
44
|
user?: {
|
|
47
45
|
name?: {
|
|
48
46
|
firstName?: string;
|
|
@@ -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,
|
|
@@ -67,11 +66,9 @@ declare const github: (options: GithubOptions) => {
|
|
|
67
66
|
redirectURI: string;
|
|
68
67
|
display?: string | undefined;
|
|
69
68
|
loginHint?: string | undefined;
|
|
69
|
+
idTokenNonce?: string | undefined;
|
|
70
70
|
additionalParams?: Record<string, string> | undefined;
|
|
71
|
-
}): Promise<
|
|
72
|
-
url: URL;
|
|
73
|
-
requestedScopes: string[];
|
|
74
|
-
}>;
|
|
71
|
+
}): Promise<URL>;
|
|
75
72
|
validateAuthorizationCode: ({
|
|
76
73
|
code,
|
|
77
74
|
codeVerifier,
|
|
@@ -84,6 +81,7 @@ declare const github: (options: GithubOptions) => {
|
|
|
84
81
|
}) => Promise<OAuth2Tokens | null>;
|
|
85
82
|
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
86
83
|
getUserInfo(token: OAuth2Tokens & {
|
|
84
|
+
expectedIdTokenNonce?: string | undefined;
|
|
87
85
|
user?: {
|
|
88
86
|
name?: {
|
|
89
87
|
firstName?: string;
|
|
@@ -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,
|
|
@@ -67,11 +66,9 @@ declare const gitlab: (options: GitlabOptions) => {
|
|
|
67
66
|
redirectURI: string;
|
|
68
67
|
display?: string | undefined;
|
|
69
68
|
loginHint?: string | undefined;
|
|
69
|
+
idTokenNonce?: string | undefined;
|
|
70
70
|
additionalParams?: Record<string, string> | undefined;
|
|
71
|
-
}) => Promise<
|
|
72
|
-
url: URL;
|
|
73
|
-
requestedScopes: string[];
|
|
74
|
-
}>;
|
|
71
|
+
}) => Promise<URL>;
|
|
75
72
|
validateAuthorizationCode: ({
|
|
76
73
|
code,
|
|
77
74
|
redirectURI,
|
|
@@ -84,6 +81,7 @@ declare const gitlab: (options: GitlabOptions) => {
|
|
|
84
81
|
}) => Promise<OAuth2Tokens>;
|
|
85
82
|
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
86
83
|
getUserInfo(token: OAuth2Tokens & {
|
|
84
|
+
expectedIdTokenNonce?: string | undefined;
|
|
87
85
|
user?: {
|
|
88
86
|
name?: {
|
|
89
87
|
firstName?: string;
|
|
@@ -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,
|
|
@@ -76,11 +77,9 @@ declare const google: (options: GoogleOptions) => {
|
|
|
76
77
|
redirectURI: string;
|
|
77
78
|
display?: string | undefined;
|
|
78
79
|
loginHint?: string | undefined;
|
|
80
|
+
idTokenNonce?: string | undefined;
|
|
79
81
|
additionalParams?: Record<string, string> | undefined;
|
|
80
|
-
}): Promise<
|
|
81
|
-
url: URL;
|
|
82
|
-
requestedScopes: string[];
|
|
83
|
-
}>;
|
|
82
|
+
}): Promise<URL>;
|
|
84
83
|
validateAuthorizationCode: ({
|
|
85
84
|
code,
|
|
86
85
|
codeVerifier,
|
|
@@ -100,6 +99,7 @@ declare const google: (options: GoogleOptions) => {
|
|
|
100
99
|
verifyClaims: ((claims: Record<string, unknown>) => boolean) | undefined;
|
|
101
100
|
};
|
|
102
101
|
getUserInfo(token: OAuth2Tokens & {
|
|
102
|
+
expectedIdTokenNonce?: string | undefined;
|
|
103
103
|
user?: {
|
|
104
104
|
name?: {
|
|
105
105
|
firstName?: string;
|
|
@@ -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,
|
|
@@ -48,11 +47,9 @@ declare const huggingface: (options: HuggingFaceOptions) => {
|
|
|
48
47
|
redirectURI: string;
|
|
49
48
|
display?: string | undefined;
|
|
50
49
|
loginHint?: string | undefined;
|
|
50
|
+
idTokenNonce?: string | undefined;
|
|
51
51
|
additionalParams?: Record<string, string> | undefined;
|
|
52
|
-
}): Promise<
|
|
53
|
-
url: URL;
|
|
54
|
-
requestedScopes: string[];
|
|
55
|
-
}>;
|
|
52
|
+
}): Promise<URL>;
|
|
56
53
|
validateAuthorizationCode: ({
|
|
57
54
|
code,
|
|
58
55
|
codeVerifier,
|
|
@@ -65,6 +62,7 @@ declare const huggingface: (options: HuggingFaceOptions) => {
|
|
|
65
62
|
}) => Promise<OAuth2Tokens>;
|
|
66
63
|
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
67
64
|
getUserInfo(token: OAuth2Tokens & {
|
|
65
|
+
expectedIdTokenNonce?: string | undefined;
|
|
68
66
|
user?: {
|
|
69
67
|
name?: {
|
|
70
68
|
firstName?: string;
|