@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.
Files changed (142) hide show
  1. package/dist/api/index.d.mts +3 -3
  2. package/dist/context/global.mjs +1 -1
  3. package/dist/db/get-tables.mjs +3 -3
  4. package/dist/db/schema/account.d.mts +1 -1
  5. package/dist/db/schema/account.mjs +1 -1
  6. package/dist/error/codes.d.mts +0 -5
  7. package/dist/error/codes.mjs +0 -5
  8. package/dist/instrumentation/tracer.mjs +1 -1
  9. package/dist/oauth2/create-authorization-url.d.mts +4 -5
  10. package/dist/oauth2/create-authorization-url.mjs +4 -5
  11. package/dist/oauth2/index.d.mts +3 -4
  12. package/dist/oauth2/index.mjs +2 -3
  13. package/dist/oauth2/oauth-provider.d.mts +44 -48
  14. package/dist/oauth2/refresh-access-token.mjs +17 -2
  15. package/dist/oauth2/utils.d.mts +6 -1
  16. package/dist/oauth2/utils.mjs +24 -2
  17. package/dist/oauth2/verify-id-token.d.mts +6 -5
  18. package/dist/oauth2/verify-id-token.mjs +2 -2
  19. package/dist/social-providers/apple.d.mts +3 -5
  20. package/dist/social-providers/apple.mjs +5 -5
  21. package/dist/social-providers/atlassian.d.mts +3 -5
  22. package/dist/social-providers/atlassian.mjs +4 -4
  23. package/dist/social-providers/cognito.d.mts +3 -5
  24. package/dist/social-providers/cognito.mjs +11 -18
  25. package/dist/social-providers/discord.d.mts +3 -5
  26. package/dist/social-providers/discord.mjs +6 -7
  27. package/dist/social-providers/dropbox.d.mts +3 -5
  28. package/dist/social-providers/dropbox.mjs +5 -5
  29. package/dist/social-providers/facebook.d.mts +3 -5
  30. package/dist/social-providers/facebook.mjs +5 -5
  31. package/dist/social-providers/figma.d.mts +3 -5
  32. package/dist/social-providers/figma.mjs +5 -5
  33. package/dist/social-providers/github.d.mts +3 -5
  34. package/dist/social-providers/github.mjs +4 -4
  35. package/dist/social-providers/gitlab.d.mts +3 -5
  36. package/dist/social-providers/gitlab.mjs +6 -6
  37. package/dist/social-providers/google.d.mts +10 -10
  38. package/dist/social-providers/google.mjs +12 -13
  39. package/dist/social-providers/huggingface.d.mts +3 -5
  40. package/dist/social-providers/huggingface.mjs +8 -8
  41. package/dist/social-providers/index.d.mts +105 -177
  42. package/dist/social-providers/kakao.d.mts +3 -5
  43. package/dist/social-providers/kakao.mjs +8 -8
  44. package/dist/social-providers/kick.d.mts +3 -5
  45. package/dist/social-providers/kick.mjs +4 -4
  46. package/dist/social-providers/line.d.mts +3 -5
  47. package/dist/social-providers/line.mjs +10 -10
  48. package/dist/social-providers/linear.d.mts +3 -5
  49. package/dist/social-providers/linear.mjs +4 -4
  50. package/dist/social-providers/linkedin.d.mts +3 -5
  51. package/dist/social-providers/linkedin.mjs +10 -10
  52. package/dist/social-providers/microsoft-entra-id.d.mts +3 -5
  53. package/dist/social-providers/microsoft-entra-id.mjs +10 -11
  54. package/dist/social-providers/naver.d.mts +3 -5
  55. package/dist/social-providers/naver.mjs +4 -4
  56. package/dist/social-providers/notion.d.mts +3 -5
  57. package/dist/social-providers/notion.mjs +4 -4
  58. package/dist/social-providers/paybin.d.mts +3 -5
  59. package/dist/social-providers/paybin.mjs +10 -10
  60. package/dist/social-providers/paypal.d.mts +3 -5
  61. package/dist/social-providers/paypal.mjs +2 -8
  62. package/dist/social-providers/polar.d.mts +3 -5
  63. package/dist/social-providers/polar.mjs +8 -8
  64. package/dist/social-providers/railway.d.mts +3 -5
  65. package/dist/social-providers/railway.mjs +9 -9
  66. package/dist/social-providers/reddit.d.mts +3 -5
  67. package/dist/social-providers/reddit.mjs +5 -5
  68. package/dist/social-providers/roblox.d.mts +3 -5
  69. package/dist/social-providers/roblox.mjs +5 -5
  70. package/dist/social-providers/salesforce.d.mts +3 -5
  71. package/dist/social-providers/salesforce.mjs +8 -8
  72. package/dist/social-providers/slack.d.mts +3 -5
  73. package/dist/social-providers/slack.mjs +9 -9
  74. package/dist/social-providers/spotify.d.mts +3 -5
  75. package/dist/social-providers/spotify.mjs +5 -5
  76. package/dist/social-providers/tiktok.d.mts +3 -5
  77. package/dist/social-providers/tiktok.mjs +5 -9
  78. package/dist/social-providers/twitch.d.mts +3 -5
  79. package/dist/social-providers/twitch.mjs +4 -4
  80. package/dist/social-providers/twitter.d.mts +3 -5
  81. package/dist/social-providers/twitter.mjs +9 -9
  82. package/dist/social-providers/vercel.d.mts +3 -5
  83. package/dist/social-providers/vercel.mjs +7 -4
  84. package/dist/social-providers/vk.d.mts +3 -5
  85. package/dist/social-providers/vk.mjs +5 -5
  86. package/dist/social-providers/wechat.d.mts +3 -5
  87. package/dist/social-providers/wechat.mjs +5 -9
  88. package/dist/social-providers/zoom.d.mts +3 -6
  89. package/dist/social-providers/zoom.mjs +9 -15
  90. package/dist/types/context.d.mts +6 -2
  91. package/dist/utils/host.d.mts +1 -1
  92. package/dist/utils/host.mjs +3 -0
  93. package/package.json +1 -1
  94. package/src/db/get-tables.ts +3 -8
  95. package/src/db/schema/account.ts +5 -14
  96. package/src/error/codes.ts +0 -5
  97. package/src/oauth2/create-authorization-url.ts +5 -1
  98. package/src/oauth2/index.ts +3 -12
  99. package/src/oauth2/oauth-provider.ts +46 -53
  100. package/src/oauth2/refresh-access-token.ts +30 -5
  101. package/src/oauth2/utils.ts +39 -1
  102. package/src/oauth2/verify-id-token.ts +9 -5
  103. package/src/social-providers/apple.ts +8 -13
  104. package/src/social-providers/atlassian.ts +8 -12
  105. package/src/social-providers/cognito.ts +11 -18
  106. package/src/social-providers/discord.ts +8 -19
  107. package/src/social-providers/dropbox.ts +7 -13
  108. package/src/social-providers/facebook.ts +9 -13
  109. package/src/social-providers/figma.ts +9 -13
  110. package/src/social-providers/github.ts +8 -12
  111. package/src/social-providers/gitlab.ts +8 -14
  112. package/src/social-providers/google.ts +23 -29
  113. package/src/social-providers/huggingface.ts +8 -12
  114. package/src/social-providers/kakao.ts +8 -16
  115. package/src/social-providers/kick.ts +7 -12
  116. package/src/social-providers/line.ts +10 -14
  117. package/src/social-providers/linear.ts +6 -12
  118. package/src/social-providers/linkedin.ts +10 -14
  119. package/src/social-providers/microsoft-entra-id.ts +8 -18
  120. package/src/social-providers/naver.ts +6 -12
  121. package/src/social-providers/notion.ts +6 -12
  122. package/src/social-providers/paybin.ts +11 -14
  123. package/src/social-providers/paypal.ts +8 -6
  124. package/src/social-providers/polar.ts +8 -12
  125. package/src/social-providers/railway.ts +9 -13
  126. package/src/social-providers/reddit.ts +7 -18
  127. package/src/social-providers/roblox.ts +7 -18
  128. package/src/social-providers/salesforce.ts +8 -12
  129. package/src/social-providers/slack.ts +9 -18
  130. package/src/social-providers/spotify.ts +7 -13
  131. package/src/social-providers/tiktok.ts +7 -13
  132. package/src/social-providers/twitch.ts +8 -12
  133. package/src/social-providers/twitter.ts +8 -17
  134. package/src/social-providers/vercel.ts +10 -16
  135. package/src/social-providers/vk.ts +7 -13
  136. package/src/social-providers/wechat.ts +8 -20
  137. package/src/social-providers/zoom.ts +6 -19
  138. package/src/types/context.ts +8 -2
  139. package/src/utils/host.ts +10 -1
  140. package/dist/oauth2/scopes.d.mts +0 -76
  141. package/dist/oauth2/scopes.mjs +0 -96
  142. package/src/oauth2/scopes.ts +0 -118
@@ -1,11 +1,10 @@
1
1
  import { decodeJwt } from "jose";
2
2
  import { logger } from "../env";
3
3
  import { BetterAuthError } from "../error";
4
- import type { ProviderOptions, UpstreamProvider } from "../oauth2";
4
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
5
5
  import {
6
6
  createAuthorizationURL,
7
7
  refreshAccessToken,
8
- resolveRequestedScopes,
9
8
  validateAuthorizationCode,
10
9
  } from "../oauth2";
11
10
 
@@ -29,8 +28,6 @@ export interface PaybinOptions extends ProviderOptions<PaybinProfile> {
29
28
  issuer?: string | undefined;
30
29
  }
31
30
 
32
- const PAYBIN_DEFAULT_SCOPES = ["openid", "email", "profile"];
33
-
34
31
  export const paybin = (options: PaybinOptions) => {
35
32
  const issuer = options.issuer || "https://idp.paybin.io";
36
33
  const authorizationEndpoint = `${issuer}/oauth2/authorize`;
@@ -39,8 +36,7 @@ export const paybin = (options: PaybinOptions) => {
39
36
  return {
40
37
  id: "paybin",
41
38
  name: "Paybin",
42
- callbackPath: "/callback/paybin",
43
- createAuthorizationURL({
39
+ async createAuthorizationURL({
44
40
  state,
45
41
  scopes,
46
42
  codeVerifier,
@@ -57,16 +53,16 @@ export const paybin = (options: PaybinOptions) => {
57
53
  if (!codeVerifier) {
58
54
  throw new BetterAuthError("codeVerifier is required for Paybin");
59
55
  }
60
- const requestedScopes = resolveRequestedScopes(
61
- options,
62
- PAYBIN_DEFAULT_SCOPES,
63
- scopes,
64
- );
65
- return createAuthorizationURL({
56
+ const _scopes = options.disableDefaultScope
57
+ ? []
58
+ : ["openid", "email", "profile"];
59
+ if (options.scope) _scopes.push(...options.scope);
60
+ if (scopes) _scopes.push(...scopes);
61
+ const url = await createAuthorizationURL({
66
62
  id: "paybin",
67
63
  options,
68
64
  authorizationEndpoint,
69
- scopes: requestedScopes,
65
+ scopes: _scopes,
70
66
  state,
71
67
  codeVerifier,
72
68
  redirectURI,
@@ -74,6 +70,7 @@ export const paybin = (options: PaybinOptions) => {
74
70
  loginHint,
75
71
  additionalParams,
76
72
  });
73
+ return url;
77
74
  },
78
75
  validateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {
79
76
  return validateAuthorizationCode({
@@ -119,5 +116,5 @@ export const paybin = (options: PaybinOptions) => {
119
116
  };
120
117
  },
121
118
  options,
122
- } satisfies UpstreamProvider<PaybinProfile>;
119
+ } satisfies OAuthProvider<PaybinProfile>;
123
120
  };
@@ -2,7 +2,7 @@ import { base64 } from "@better-auth/utils/base64";
2
2
  import { betterFetch } from "@better-fetch/fetch";
3
3
  import { logger } from "../env";
4
4
  import { BetterAuthError } from "../error";
5
- import type { ProviderOptions, UpstreamProvider } from "../oauth2";
5
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
6
6
  import { createAuthorizationURL } from "../oauth2";
7
7
 
8
8
  export interface PayPalProfile {
@@ -77,8 +77,7 @@ export const paypal = (options: PayPalOptions) => {
77
77
  return {
78
78
  id: "paypal",
79
79
  name: "PayPal",
80
- callbackPath: "/callback/paypal",
81
- createAuthorizationURL({
80
+ async createAuthorizationURL({
82
81
  state,
83
82
  codeVerifier,
84
83
  redirectURI,
@@ -97,17 +96,20 @@ export const paypal = (options: PayPalOptions) => {
97
96
  * We don't pass any scopes to avoid "invalid scope" errors
98
97
  **/
99
98
 
100
- return createAuthorizationURL({
99
+ const _scopes: string[] = [];
100
+
101
+ const url = await createAuthorizationURL({
101
102
  id: "paypal",
102
103
  options,
103
104
  authorizationEndpoint,
104
- scopes: [],
105
+ scopes: _scopes,
105
106
  state,
106
107
  codeVerifier,
107
108
  redirectURI,
108
109
  prompt: options.prompt,
109
110
  additionalParams,
110
111
  });
112
+ return url;
111
113
  },
112
114
 
113
115
  validateAuthorizationCode: async ({ code, redirectURI }) => {
@@ -246,5 +248,5 @@ export const paypal = (options: PayPalOptions) => {
246
248
  },
247
249
 
248
250
  options,
249
- } satisfies UpstreamProvider<PayPalProfile>;
251
+ } satisfies OAuthProvider<PayPalProfile>;
250
252
  };
@@ -1,9 +1,8 @@
1
1
  import { betterFetch } from "@better-fetch/fetch";
2
- import type { ProviderOptions, UpstreamProvider } from "../oauth2";
2
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
3
  import {
4
4
  createAuthorizationURL,
5
5
  refreshAccessToken,
6
- resolveRequestedScopes,
7
6
  validateAuthorizationCode,
8
7
  } from "../oauth2";
9
8
 
@@ -33,14 +32,11 @@ export interface PolarProfile {
33
32
 
34
33
  export interface PolarOptions extends ProviderOptions<PolarProfile> {}
35
34
 
36
- const POLAR_DEFAULT_SCOPES = ["openid", "profile", "email"];
37
-
38
35
  export const polar = (options: PolarOptions) => {
39
36
  const tokenEndpoint = "https://api.polar.sh/v1/oauth2/token";
40
37
  return {
41
38
  id: "polar",
42
39
  name: "Polar",
43
- callbackPath: "/callback/polar",
44
40
  createAuthorizationURL({
45
41
  state,
46
42
  scopes,
@@ -48,16 +44,16 @@ export const polar = (options: PolarOptions) => {
48
44
  redirectURI,
49
45
  additionalParams,
50
46
  }) {
51
- const requestedScopes = resolveRequestedScopes(
52
- options,
53
- POLAR_DEFAULT_SCOPES,
54
- scopes,
55
- );
47
+ const _scopes = options.disableDefaultScope
48
+ ? []
49
+ : ["openid", "profile", "email"];
50
+ if (options.scope) _scopes.push(...options.scope);
51
+ if (scopes) _scopes.push(...scopes);
56
52
  return createAuthorizationURL({
57
53
  id: "polar",
58
54
  options,
59
55
  authorizationEndpoint: "https://polar.sh/oauth2/authorize",
60
- scopes: requestedScopes,
56
+ scopes: _scopes,
61
57
  state,
62
58
  codeVerifier,
63
59
  redirectURI,
@@ -118,5 +114,5 @@ export const polar = (options: PolarOptions) => {
118
114
  };
119
115
  },
120
116
  options,
121
- } satisfies UpstreamProvider<PolarProfile>;
117
+ } satisfies OAuthProvider<PolarProfile>;
122
118
  };
@@ -1,9 +1,8 @@
1
1
  import { betterFetch } from "@better-fetch/fetch";
2
- import type { ProviderOptions, UpstreamProvider } from "../oauth2";
2
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
3
  import {
4
4
  createAuthorizationURL,
5
5
  refreshAccessToken,
6
- resolveRequestedScopes,
7
6
  validateAuthorizationCode,
8
7
  } from "../oauth2";
9
8
 
@@ -26,30 +25,27 @@ export interface RailwayOptions extends ProviderOptions<RailwayProfile> {
26
25
  clientId: string;
27
26
  }
28
27
 
29
- const RAILWAY_DEFAULT_SCOPES = ["openid", "email", "profile"];
30
-
31
28
  export const railway = (options: RailwayOptions) => {
32
29
  return {
33
30
  id: "railway",
34
31
  name: "Railway",
35
- callbackPath: "/callback/railway",
36
- async createAuthorizationURL({
32
+ createAuthorizationURL({
37
33
  state,
38
34
  scopes,
39
35
  codeVerifier,
40
36
  redirectURI,
41
37
  additionalParams,
42
38
  }) {
43
- const requestedScopes = resolveRequestedScopes(
44
- options,
45
- RAILWAY_DEFAULT_SCOPES,
46
- scopes,
47
- );
39
+ const _scopes = options.disableDefaultScope
40
+ ? []
41
+ : ["openid", "email", "profile"];
42
+ if (options.scope) _scopes.push(...options.scope);
43
+ if (scopes) _scopes.push(...scopes);
48
44
  return createAuthorizationURL({
49
45
  id: "railway",
50
46
  options,
51
47
  authorizationEndpoint,
52
- scopes: requestedScopes,
48
+ scopes: _scopes,
53
49
  state,
54
50
  codeVerifier,
55
51
  redirectURI,
@@ -107,5 +103,5 @@ export const railway = (options: RailwayOptions) => {
107
103
  };
108
104
  },
109
105
  options,
110
- } satisfies UpstreamProvider<RailwayProfile>;
106
+ } satisfies OAuthProvider<RailwayProfile>;
111
107
  };
@@ -1,11 +1,10 @@
1
1
  import { base64 } from "@better-auth/utils/base64";
2
2
  import { betterFetch } from "@better-fetch/fetch";
3
- import type { ProviderOptions, UpstreamProvider } from "../oauth2";
3
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
4
4
  import {
5
5
  createAuthorizationURL,
6
6
  getOAuth2Tokens,
7
7
  refreshAccessToken,
8
- resolveRequestedScopes,
9
8
  } from "../oauth2";
10
9
 
11
10
  export interface RedditProfile {
@@ -22,29 +21,19 @@ export interface RedditOptions extends ProviderOptions<RedditProfile> {
22
21
  duration?: string | undefined;
23
22
  }
24
23
 
25
- const REDDIT_DEFAULT_SCOPES = ["identity"];
26
-
27
24
  export const reddit = (options: RedditOptions) => {
28
25
  return {
29
26
  id: "reddit",
30
27
  name: "Reddit",
31
- callbackPath: "/callback/reddit",
32
- async createAuthorizationURL({
33
- state,
34
- scopes,
35
- redirectURI,
36
- additionalParams,
37
- }) {
38
- const requestedScopes = resolveRequestedScopes(
39
- options,
40
- REDDIT_DEFAULT_SCOPES,
41
- scopes,
42
- );
28
+ createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
29
+ const _scopes = options.disableDefaultScope ? [] : ["identity"];
30
+ if (options.scope) _scopes.push(...options.scope);
31
+ if (scopes) _scopes.push(...scopes);
43
32
  return createAuthorizationURL({
44
33
  id: "reddit",
45
34
  options,
46
35
  authorizationEndpoint: "https://www.reddit.com/api/v1/authorize",
47
- scopes: requestedScopes,
36
+ scopes: _scopes,
48
37
  state,
49
38
  redirectURI,
50
39
  duration: options.duration,
@@ -134,5 +123,5 @@ export const reddit = (options: RedditOptions) => {
134
123
  };
135
124
  },
136
125
  options,
137
- } satisfies UpstreamProvider<RedditProfile>;
126
+ } satisfies OAuthProvider<RedditProfile>;
138
127
  };
@@ -1,9 +1,8 @@
1
1
  import { betterFetch } from "@better-fetch/fetch";
2
- import type { ProviderOptions, UpstreamProvider } from "../oauth2";
2
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
3
  import {
4
4
  createAuthorizationURL,
5
5
  refreshAccessToken,
6
- resolveRequestedScopes,
7
6
  validateAuthorizationCode,
8
7
  } from "../oauth2";
9
8
 
@@ -37,30 +36,20 @@ export interface RobloxOptions extends ProviderOptions<RobloxProfile> {
37
36
  | undefined;
38
37
  }
39
38
 
40
- const ROBLOX_DEFAULT_SCOPES = ["openid", "profile"];
41
-
42
39
  export const roblox = (options: RobloxOptions) => {
43
40
  const tokenEndpoint = "https://apis.roblox.com/oauth/v1/token";
44
41
  return {
45
42
  id: "roblox",
46
43
  name: "Roblox",
47
- callbackPath: "/callback/roblox",
48
- async createAuthorizationURL({
49
- state,
50
- scopes,
51
- redirectURI,
52
- additionalParams,
53
- }) {
54
- const requestedScopes = resolveRequestedScopes(
55
- options,
56
- ROBLOX_DEFAULT_SCOPES,
57
- scopes,
58
- );
44
+ createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
45
+ const _scopes = options.disableDefaultScope ? [] : ["openid", "profile"];
46
+ if (options.scope) _scopes.push(...options.scope);
47
+ if (scopes) _scopes.push(...scopes);
59
48
  return createAuthorizationURL({
60
49
  id: "roblox",
61
50
  options,
62
51
  authorizationEndpoint: "https://apis.roblox.com/oauth/v1/authorize",
63
- scopes: requestedScopes,
52
+ scopes: _scopes,
64
53
  state,
65
54
  redirectURI,
66
55
  prompt: options.prompt || "select_account consent",
@@ -124,5 +113,5 @@ export const roblox = (options: RobloxOptions) => {
124
113
  };
125
114
  },
126
115
  options,
127
- } satisfies UpstreamProvider<RobloxProfile>;
116
+ } satisfies OAuthProvider<RobloxProfile>;
128
117
  };
@@ -1,11 +1,10 @@
1
1
  import { betterFetch } from "@better-fetch/fetch";
2
2
  import { logger } from "../env";
3
3
  import { BetterAuthError } from "../error";
4
- import type { ProviderOptions, UpstreamProvider } from "../oauth2";
4
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
5
5
  import {
6
6
  createAuthorizationURL,
7
7
  refreshAccessToken,
8
- resolveRequestedScopes,
9
8
  validateAuthorizationCode,
10
9
  } from "../oauth2";
11
10
 
@@ -40,8 +39,6 @@ export interface SalesforceOptions extends ProviderOptions<SalesforceProfile> {
40
39
  redirectURI?: string | undefined;
41
40
  }
42
41
 
43
- const SALESFORCE_DEFAULT_SCOPES = ["openid", "email", "profile"];
44
-
45
42
  export const salesforce = (options: SalesforceOptions) => {
46
43
  const environment = options.environment ?? "production";
47
44
  const isSandbox = environment === "sandbox";
@@ -66,7 +63,6 @@ export const salesforce = (options: SalesforceOptions) => {
66
63
  return {
67
64
  id: "salesforce",
68
65
  name: "Salesforce",
69
- callbackPath: "/callback/salesforce",
70
66
 
71
67
  async createAuthorizationURL({
72
68
  state,
@@ -85,17 +81,17 @@ export const salesforce = (options: SalesforceOptions) => {
85
81
  throw new BetterAuthError("codeVerifier is required for Salesforce");
86
82
  }
87
83
 
88
- const requestedScopes = resolveRequestedScopes(
89
- options,
90
- SALESFORCE_DEFAULT_SCOPES,
91
- scopes,
92
- );
84
+ const _scopes = options.disableDefaultScope
85
+ ? []
86
+ : ["openid", "email", "profile"];
87
+ if (options.scope) _scopes.push(...options.scope);
88
+ if (scopes) _scopes.push(...scopes);
93
89
 
94
90
  return createAuthorizationURL({
95
91
  id: "salesforce",
96
92
  options,
97
93
  authorizationEndpoint,
98
- scopes: requestedScopes,
94
+ scopes: _scopes,
99
95
  state,
100
96
  codeVerifier,
101
97
  redirectURI: options.redirectURI || redirectURI,
@@ -166,5 +162,5 @@ export const salesforce = (options: SalesforceOptions) => {
166
162
  },
167
163
 
168
164
  options,
169
- } satisfies UpstreamProvider<SalesforceProfile>;
165
+ } satisfies OAuthProvider<SalesforceProfile>;
170
166
  };
@@ -1,9 +1,8 @@
1
1
  import { betterFetch } from "@better-fetch/fetch";
2
- import type { ProviderOptions, UpstreamProvider } from "../oauth2";
2
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
3
  import {
4
4
  createAuthorizationURL,
5
5
  refreshAccessToken,
6
- resolveRequestedScopes,
7
6
  validateAuthorizationCode,
8
7
  } from "../oauth2";
9
8
 
@@ -42,30 +41,22 @@ export interface SlackOptions extends ProviderOptions<SlackProfile> {
42
41
  clientId: string;
43
42
  }
44
43
 
45
- const SLACK_DEFAULT_SCOPES = ["openid", "profile", "email"];
46
-
47
44
  export const slack = (options: SlackOptions) => {
48
45
  const tokenEndpoint = "https://slack.com/api/openid.connect.token";
49
46
  return {
50
47
  id: "slack",
51
48
  name: "Slack",
52
- callbackPath: "/callback/slack",
53
- async createAuthorizationURL({
54
- state,
55
- scopes,
56
- redirectURI,
57
- additionalParams,
58
- }) {
59
- const requestedScopes = resolveRequestedScopes(
60
- options,
61
- SLACK_DEFAULT_SCOPES,
62
- scopes,
63
- );
49
+ createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
50
+ const _scopes = options.disableDefaultScope
51
+ ? []
52
+ : ["openid", "profile", "email"];
53
+ if (scopes) _scopes.push(...scopes);
54
+ if (options.scope) _scopes.push(...options.scope);
64
55
  return createAuthorizationURL({
65
56
  id: "slack",
66
57
  options,
67
58
  authorizationEndpoint: "https://slack.com/openid/connect/authorize",
68
- scopes: requestedScopes,
59
+ scopes: _scopes,
69
60
  state,
70
61
  redirectURI,
71
62
  additionalParams,
@@ -123,5 +114,5 @@ export const slack = (options: SlackOptions) => {
123
114
  };
124
115
  },
125
116
  options,
126
- } satisfies UpstreamProvider<SlackProfile>;
117
+ } satisfies OAuthProvider<SlackProfile>;
127
118
  };
@@ -1,9 +1,8 @@
1
1
  import { betterFetch } from "@better-fetch/fetch";
2
- import type { ProviderOptions, UpstreamProvider } from "../oauth2";
2
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
3
  import {
4
4
  createAuthorizationURL,
5
5
  refreshAccessToken,
6
- resolveRequestedScopes,
7
6
  validateAuthorizationCode,
8
7
  } from "../oauth2";
9
8
 
@@ -20,31 +19,26 @@ export interface SpotifyOptions extends ProviderOptions<SpotifyProfile> {
20
19
  clientId: string;
21
20
  }
22
21
 
23
- const SPOTIFY_DEFAULT_SCOPES = ["user-read-email"];
24
-
25
22
  export const spotify = (options: SpotifyOptions) => {
26
23
  const tokenEndpoint = "https://accounts.spotify.com/api/token";
27
24
  return {
28
25
  id: "spotify",
29
26
  name: "Spotify",
30
- callbackPath: "/callback/spotify",
31
- async createAuthorizationURL({
27
+ createAuthorizationURL({
32
28
  state,
33
29
  scopes,
34
30
  codeVerifier,
35
31
  redirectURI,
36
32
  additionalParams,
37
33
  }) {
38
- const requestedScopes = resolveRequestedScopes(
39
- options,
40
- SPOTIFY_DEFAULT_SCOPES,
41
- scopes,
42
- );
34
+ const _scopes = options.disableDefaultScope ? [] : ["user-read-email"];
35
+ if (options.scope) _scopes.push(...options.scope);
36
+ if (scopes) _scopes.push(...scopes);
43
37
  return createAuthorizationURL({
44
38
  id: "spotify",
45
39
  options,
46
40
  authorizationEndpoint: "https://accounts.spotify.com/authorize",
47
- scopes: requestedScopes,
41
+ scopes: _scopes,
48
42
  state,
49
43
  codeVerifier,
50
44
  redirectURI,
@@ -103,5 +97,5 @@ export const spotify = (options: SpotifyOptions) => {
103
97
  };
104
98
  },
105
99
  options,
106
- } satisfies UpstreamProvider<SpotifyProfile>;
100
+ } satisfies OAuthProvider<SpotifyProfile>;
107
101
  };
@@ -1,9 +1,8 @@
1
1
  import { betterFetch } from "@better-fetch/fetch";
2
- import type { ProviderOptions, UpstreamProvider } from "../oauth2";
2
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
3
  import {
4
4
  RESERVED_AUTHORIZATION_PARAMS_SET,
5
5
  refreshAccessToken,
6
- resolveRequestedScopes,
7
6
  validateAuthorizationCode,
8
7
  } from "../oauth2";
9
8
 
@@ -131,24 +130,19 @@ export interface TiktokOptions extends ProviderOptions {
131
130
  clientKey: string;
132
131
  }
133
132
 
134
- const TIKTOK_DEFAULT_SCOPES = ["user.info.profile"];
135
-
136
133
  export const tiktok = (options: TiktokOptions) => {
137
134
  const tokenEndpoint = "https://open.tiktokapis.com/v2/oauth/token/";
138
135
  return {
139
136
  id: "tiktok",
140
137
  name: "TikTok",
141
- callbackPath: "/callback/tiktok",
142
138
  createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
143
- const requestedScopes = resolveRequestedScopes(
144
- options,
145
- TIKTOK_DEFAULT_SCOPES,
146
- scopes,
147
- );
139
+ const _scopes = options.disableDefaultScope ? [] : ["user.info.profile"];
140
+ if (options.scope) _scopes.push(...options.scope);
141
+ if (scopes) _scopes.push(...scopes);
148
142
  // TikTok uses `client_key` instead of the standard `client_id`, so the
149
143
  // shared createAuthorizationURL helper cannot be used directly.
150
144
  const url = new URL("https://www.tiktok.com/v2/auth/authorize");
151
- url.searchParams.set("scope", requestedScopes.join(","));
145
+ url.searchParams.set("scope", _scopes.join(","));
152
146
  url.searchParams.set("response_type", "code");
153
147
  url.searchParams.set("client_key", options.clientKey);
154
148
  url.searchParams.set("redirect_uri", options.redirectURI || redirectURI);
@@ -160,7 +154,7 @@ export const tiktok = (options: TiktokOptions) => {
160
154
  url.searchParams.set(key, value);
161
155
  }
162
156
  }
163
- return { url, requestedScopes };
157
+ return url;
164
158
  },
165
159
 
166
160
  validateAuthorizationCode: async ({ code, redirectURI }) => {
@@ -226,5 +220,5 @@ export const tiktok = (options: TiktokOptions) => {
226
220
  };
227
221
  },
228
222
  options,
229
- } satisfies UpstreamProvider<TiktokProfile, TiktokOptions>;
223
+ } satisfies OAuthProvider<TiktokProfile, TiktokOptions>;
230
224
  };
@@ -1,10 +1,9 @@
1
1
  import { decodeJwt } from "jose";
2
2
  import { logger } from "../env";
3
- import type { ProviderOptions, UpstreamProvider } from "../oauth2";
3
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
4
4
  import {
5
5
  createAuthorizationURL,
6
6
  refreshAccessToken,
7
- resolveRequestedScopes,
8
7
  validateAuthorizationCode,
9
8
  } from "../oauth2";
10
9
 
@@ -38,26 +37,23 @@ export interface TwitchOptions extends ProviderOptions<TwitchProfile> {
38
37
  clientId: string;
39
38
  claims?: string[] | undefined;
40
39
  }
41
- const TWITCH_DEFAULT_SCOPES = ["user:read:email", "openid"];
42
-
43
40
  export const twitch = (options: TwitchOptions) => {
44
41
  const tokenEndpoint = "https://id.twitch.tv/oauth2/token";
45
42
  return {
46
43
  id: "twitch",
47
44
  name: "Twitch",
48
- callbackPath: "/callback/twitch",
49
45
  createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
50
- const requestedScopes = resolveRequestedScopes(
51
- options,
52
- TWITCH_DEFAULT_SCOPES,
53
- scopes,
54
- );
46
+ const _scopes = options.disableDefaultScope
47
+ ? []
48
+ : ["user:read:email", "openid"];
49
+ if (options.scope) _scopes.push(...options.scope);
50
+ if (scopes) _scopes.push(...scopes);
55
51
  return createAuthorizationURL({
56
52
  id: "twitch",
57
53
  redirectURI,
58
54
  options,
59
55
  authorizationEndpoint: "https://id.twitch.tv/oauth2/authorize",
60
- scopes: requestedScopes,
56
+ scopes: _scopes,
61
57
  state,
62
58
  claims: options.claims || [
63
59
  "email",
@@ -113,5 +109,5 @@ export const twitch = (options: TwitchOptions) => {
113
109
  };
114
110
  },
115
111
  options,
116
- } satisfies UpstreamProvider<TwitchProfile>;
112
+ } satisfies OAuthProvider<TwitchProfile>;
117
113
  };
@@ -1,9 +1,8 @@
1
1
  import { betterFetch } from "@better-fetch/fetch";
2
- import type { ProviderOptions, UpstreamProvider } from "../oauth2";
2
+ import type { OAuthProvider, ProviderOptions } from "../oauth2";
3
3
  import {
4
4
  createAuthorizationURL,
5
5
  refreshAccessToken,
6
- resolveRequestedScopes,
7
6
  validateAuthorizationCode,
8
7
  } from "../oauth2";
9
8
 
@@ -104,30 +103,22 @@ export interface TwitterOption extends ProviderOptions<TwitterProfile> {
104
103
  clientId: string;
105
104
  }
106
105
 
107
- const TWITTER_DEFAULT_SCOPES = [
108
- "users.read",
109
- "tweet.read",
110
- "offline.access",
111
- "users.email",
112
- ];
113
-
114
106
  export const twitter = (options: TwitterOption) => {
115
107
  const tokenEndpoint = "https://api.x.com/2/oauth2/token";
116
108
  return {
117
109
  id: "twitter",
118
110
  name: "Twitter",
119
- callbackPath: "/callback/twitter",
120
111
  createAuthorizationURL(data) {
121
- const requestedScopes = resolveRequestedScopes(
122
- options,
123
- TWITTER_DEFAULT_SCOPES,
124
- data.scopes,
125
- );
112
+ const _scopes = options.disableDefaultScope
113
+ ? []
114
+ : ["users.read", "tweet.read", "offline.access", "users.email"];
115
+ if (options.scope) _scopes.push(...options.scope);
116
+ if (data.scopes) _scopes.push(...data.scopes);
126
117
  return createAuthorizationURL({
127
118
  id: "twitter",
128
119
  options,
129
120
  authorizationEndpoint: "https://x.com/i/oauth2/authorize",
130
- scopes: requestedScopes,
121
+ scopes: _scopes,
131
122
  state: data.state,
132
123
  codeVerifier: data.codeVerifier,
133
124
  redirectURI: data.redirectURI,
@@ -205,5 +196,5 @@ export const twitter = (options: TwitterOption) => {
205
196
  };
206
197
  },
207
198
  options,
208
- } satisfies UpstreamProvider<TwitterProfile>;
199
+ } satisfies OAuthProvider<TwitterProfile>;
209
200
  };