@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.
Files changed (140) hide show
  1. package/dist/api/index.d.mts +3 -3
  2. package/dist/context/global.mjs +1 -1
  3. package/dist/db/adapter/factory.mjs +1 -1
  4. package/dist/db/get-tables.mjs +3 -3
  5. package/dist/db/schema/account.d.mts +1 -1
  6. package/dist/db/schema/account.mjs +1 -1
  7. package/dist/error/codes.d.mts +0 -5
  8. package/dist/error/codes.mjs +0 -5
  9. package/dist/instrumentation/tracer.mjs +1 -1
  10. package/dist/oauth2/create-authorization-url.d.mts +1 -4
  11. package/dist/oauth2/create-authorization-url.mjs +1 -4
  12. package/dist/oauth2/index.d.mts +3 -4
  13. package/dist/oauth2/index.mjs +2 -3
  14. package/dist/oauth2/oauth-provider.d.mts +12 -50
  15. package/dist/oauth2/refresh-access-token.mjs +2 -1
  16. package/dist/oauth2/utils.d.mts +6 -1
  17. package/dist/oauth2/utils.mjs +24 -2
  18. package/dist/oauth2/verify-id-token.d.mts +6 -5
  19. package/dist/oauth2/verify-id-token.mjs +2 -2
  20. package/dist/social-providers/apple.d.mts +1 -5
  21. package/dist/social-providers/apple.mjs +5 -5
  22. package/dist/social-providers/atlassian.d.mts +1 -5
  23. package/dist/social-providers/atlassian.mjs +4 -4
  24. package/dist/social-providers/cognito.d.mts +1 -5
  25. package/dist/social-providers/cognito.mjs +11 -18
  26. package/dist/social-providers/discord.d.mts +1 -5
  27. package/dist/social-providers/discord.mjs +6 -7
  28. package/dist/social-providers/dropbox.d.mts +1 -5
  29. package/dist/social-providers/dropbox.mjs +5 -5
  30. package/dist/social-providers/facebook.d.mts +1 -5
  31. package/dist/social-providers/facebook.mjs +5 -5
  32. package/dist/social-providers/figma.d.mts +1 -5
  33. package/dist/social-providers/figma.mjs +5 -5
  34. package/dist/social-providers/github.d.mts +1 -5
  35. package/dist/social-providers/github.mjs +4 -4
  36. package/dist/social-providers/gitlab.d.mts +1 -5
  37. package/dist/social-providers/gitlab.mjs +6 -6
  38. package/dist/social-providers/google.d.mts +8 -10
  39. package/dist/social-providers/google.mjs +12 -13
  40. package/dist/social-providers/huggingface.d.mts +1 -5
  41. package/dist/social-providers/huggingface.mjs +8 -8
  42. package/dist/social-providers/index.d.mts +35 -177
  43. package/dist/social-providers/kakao.d.mts +1 -5
  44. package/dist/social-providers/kakao.mjs +8 -8
  45. package/dist/social-providers/kick.d.mts +1 -5
  46. package/dist/social-providers/kick.mjs +4 -4
  47. package/dist/social-providers/line.d.mts +1 -5
  48. package/dist/social-providers/line.mjs +10 -10
  49. package/dist/social-providers/linear.d.mts +1 -5
  50. package/dist/social-providers/linear.mjs +4 -4
  51. package/dist/social-providers/linkedin.d.mts +1 -5
  52. package/dist/social-providers/linkedin.mjs +10 -10
  53. package/dist/social-providers/microsoft-entra-id.d.mts +1 -5
  54. package/dist/social-providers/microsoft-entra-id.mjs +10 -11
  55. package/dist/social-providers/naver.d.mts +1 -5
  56. package/dist/social-providers/naver.mjs +4 -4
  57. package/dist/social-providers/notion.d.mts +1 -5
  58. package/dist/social-providers/notion.mjs +4 -4
  59. package/dist/social-providers/paybin.d.mts +1 -5
  60. package/dist/social-providers/paybin.mjs +10 -10
  61. package/dist/social-providers/paypal.d.mts +1 -5
  62. package/dist/social-providers/paypal.mjs +2 -8
  63. package/dist/social-providers/polar.d.mts +1 -5
  64. package/dist/social-providers/polar.mjs +8 -8
  65. package/dist/social-providers/railway.d.mts +1 -5
  66. package/dist/social-providers/railway.mjs +9 -9
  67. package/dist/social-providers/reddit.d.mts +1 -5
  68. package/dist/social-providers/reddit.mjs +5 -5
  69. package/dist/social-providers/roblox.d.mts +1 -5
  70. package/dist/social-providers/roblox.mjs +5 -5
  71. package/dist/social-providers/salesforce.d.mts +1 -5
  72. package/dist/social-providers/salesforce.mjs +8 -8
  73. package/dist/social-providers/slack.d.mts +1 -5
  74. package/dist/social-providers/slack.mjs +9 -9
  75. package/dist/social-providers/spotify.d.mts +1 -5
  76. package/dist/social-providers/spotify.mjs +5 -5
  77. package/dist/social-providers/tiktok.d.mts +1 -5
  78. package/dist/social-providers/tiktok.mjs +5 -9
  79. package/dist/social-providers/twitch.d.mts +1 -5
  80. package/dist/social-providers/twitch.mjs +4 -4
  81. package/dist/social-providers/twitter.d.mts +1 -5
  82. package/dist/social-providers/twitter.mjs +9 -9
  83. package/dist/social-providers/vercel.d.mts +1 -5
  84. package/dist/social-providers/vercel.mjs +7 -4
  85. package/dist/social-providers/vk.d.mts +1 -5
  86. package/dist/social-providers/vk.mjs +5 -5
  87. package/dist/social-providers/wechat.d.mts +1 -5
  88. package/dist/social-providers/wechat.mjs +5 -9
  89. package/dist/social-providers/zoom.d.mts +1 -6
  90. package/dist/social-providers/zoom.mjs +9 -15
  91. package/dist/types/context.d.mts +6 -2
  92. package/package.json +1 -1
  93. package/src/db/get-tables.ts +3 -8
  94. package/src/db/schema/account.ts +5 -14
  95. package/src/error/codes.ts +0 -5
  96. package/src/oauth2/create-authorization-url.ts +1 -1
  97. package/src/oauth2/index.ts +2 -12
  98. package/src/oauth2/oauth-provider.ts +11 -56
  99. package/src/oauth2/refresh-access-token.ts +3 -2
  100. package/src/oauth2/utils.ts +39 -1
  101. package/src/oauth2/verify-id-token.ts +7 -5
  102. package/src/social-providers/apple.ts +8 -13
  103. package/src/social-providers/atlassian.ts +8 -12
  104. package/src/social-providers/cognito.ts +11 -18
  105. package/src/social-providers/discord.ts +8 -19
  106. package/src/social-providers/dropbox.ts +7 -13
  107. package/src/social-providers/facebook.ts +9 -13
  108. package/src/social-providers/figma.ts +9 -13
  109. package/src/social-providers/github.ts +8 -12
  110. package/src/social-providers/gitlab.ts +8 -14
  111. package/src/social-providers/google.ts +23 -29
  112. package/src/social-providers/huggingface.ts +8 -12
  113. package/src/social-providers/kakao.ts +8 -16
  114. package/src/social-providers/kick.ts +7 -12
  115. package/src/social-providers/line.ts +10 -14
  116. package/src/social-providers/linear.ts +6 -12
  117. package/src/social-providers/linkedin.ts +10 -14
  118. package/src/social-providers/microsoft-entra-id.ts +8 -18
  119. package/src/social-providers/naver.ts +6 -12
  120. package/src/social-providers/notion.ts +6 -12
  121. package/src/social-providers/paybin.ts +11 -14
  122. package/src/social-providers/paypal.ts +8 -6
  123. package/src/social-providers/polar.ts +8 -12
  124. package/src/social-providers/railway.ts +9 -13
  125. package/src/social-providers/reddit.ts +7 -18
  126. package/src/social-providers/roblox.ts +7 -18
  127. package/src/social-providers/salesforce.ts +8 -12
  128. package/src/social-providers/slack.ts +9 -18
  129. package/src/social-providers/spotify.ts +7 -13
  130. package/src/social-providers/tiktok.ts +7 -13
  131. package/src/social-providers/twitch.ts +8 -12
  132. package/src/social-providers/twitter.ts +8 -17
  133. package/src/social-providers/vercel.ts +10 -16
  134. package/src/social-providers/vk.ts +7 -13
  135. package/src/social-providers/wechat.ts +8 -20
  136. package/src/social-providers/zoom.ts +6 -19
  137. package/src/types/context.ts +8 -2
  138. package/dist/oauth2/scopes.d.mts +0 -76
  139. package/dist/oauth2/scopes.mjs +0 -96
  140. package/src/oauth2/scopes.ts +0 -118
@@ -15,7 +15,6 @@ interface RedditOptions extends ProviderOptions<RedditProfile> {
15
15
  declare const reddit: (options: RedditOptions) => {
16
16
  id: "reddit";
17
17
  name: string;
18
- callbackPath: string;
19
18
  createAuthorizationURL({
20
19
  state,
21
20
  scopes,
@@ -30,10 +29,7 @@ declare const reddit: (options: RedditOptions) => {
30
29
  loginHint?: string | undefined;
31
30
  idTokenNonce?: string | undefined;
32
31
  additionalParams?: Record<string, string> | undefined;
33
- }): Promise<{
34
- url: URL;
35
- requestedScopes: string[];
36
- }>;
32
+ }): Promise<URL>;
37
33
  validateAuthorizationCode: ({
38
34
  code,
39
35
  redirectURI
@@ -1,22 +1,22 @@
1
- import { resolveRequestedScopes } from "../oauth2/scopes.mjs";
2
1
  import { getOAuth2Tokens } from "../oauth2/utils.mjs";
3
2
  import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
4
3
  import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
5
4
  import { base64 } from "@better-auth/utils/base64";
6
5
  import { betterFetch } from "@better-fetch/fetch";
7
6
  //#region src/social-providers/reddit.ts
8
- const REDDIT_DEFAULT_SCOPES = ["identity"];
9
7
  const reddit = (options) => {
10
8
  return {
11
9
  id: "reddit",
12
10
  name: "Reddit",
13
- callbackPath: "/callback/reddit",
14
- async createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
11
+ createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
12
+ const _scopes = options.disableDefaultScope ? [] : ["identity"];
13
+ if (options.scope) _scopes.push(...options.scope);
14
+ if (scopes) _scopes.push(...scopes);
15
15
  return createAuthorizationURL({
16
16
  id: "reddit",
17
17
  options,
18
18
  authorizationEndpoint: "https://www.reddit.com/api/v1/authorize",
19
- scopes: resolveRequestedScopes(options, REDDIT_DEFAULT_SCOPES, scopes),
19
+ scopes: _scopes,
20
20
  state,
21
21
  redirectURI,
22
22
  duration: options.duration,
@@ -23,7 +23,6 @@ interface RobloxOptions extends ProviderOptions<RobloxProfile> {
23
23
  declare const roblox: (options: RobloxOptions) => {
24
24
  id: "roblox";
25
25
  name: string;
26
- callbackPath: string;
27
26
  createAuthorizationURL({
28
27
  state,
29
28
  scopes,
@@ -38,10 +37,7 @@ declare const roblox: (options: RobloxOptions) => {
38
37
  loginHint?: string | undefined;
39
38
  idTokenNonce?: string | undefined;
40
39
  additionalParams?: Record<string, string> | undefined;
41
- }): Promise<{
42
- url: URL;
43
- requestedScopes: string[];
44
- }>;
40
+ }): Promise<URL>;
45
41
  validateAuthorizationCode: ({
46
42
  code,
47
43
  redirectURI
@@ -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/roblox.ts
7
- const ROBLOX_DEFAULT_SCOPES = ["openid", "profile"];
8
6
  const roblox = (options) => {
9
7
  const tokenEndpoint = "https://apis.roblox.com/oauth/v1/token";
10
8
  return {
11
9
  id: "roblox",
12
10
  name: "Roblox",
13
- callbackPath: "/callback/roblox",
14
- async createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
11
+ createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
12
+ const _scopes = options.disableDefaultScope ? [] : ["openid", "profile"];
13
+ if (options.scope) _scopes.push(...options.scope);
14
+ if (scopes) _scopes.push(...scopes);
15
15
  return createAuthorizationURL({
16
16
  id: "roblox",
17
17
  options,
18
18
  authorizationEndpoint: "https://apis.roblox.com/oauth/v1/authorize",
19
- scopes: resolveRequestedScopes(options, ROBLOX_DEFAULT_SCOPES, scopes),
19
+ scopes: _scopes,
20
20
  state,
21
21
  redirectURI,
22
22
  prompt: options.prompt || "select_account consent",
@@ -30,7 +30,6 @@ interface SalesforceOptions extends ProviderOptions<SalesforceProfile> {
30
30
  declare const salesforce: (options: SalesforceOptions) => {
31
31
  id: "salesforce";
32
32
  name: string;
33
- callbackPath: string;
34
33
  createAuthorizationURL({
35
34
  state,
36
35
  scopes,
@@ -46,10 +45,7 @@ declare const salesforce: (options: SalesforceOptions) => {
46
45
  loginHint?: string | undefined;
47
46
  idTokenNonce?: string | undefined;
48
47
  additionalParams?: Record<string, string> | undefined;
49
- }): Promise<{
50
- url: URL;
51
- requestedScopes: string[];
52
- }>;
48
+ }): Promise<URL>;
53
49
  validateAuthorizationCode: ({
54
50
  code,
55
51
  codeVerifier,
@@ -1,16 +1,10 @@
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/salesforce.ts
9
- const SALESFORCE_DEFAULT_SCOPES = [
10
- "openid",
11
- "email",
12
- "profile"
13
- ];
14
8
  const salesforce = (options) => {
15
9
  const isSandbox = (options.environment ?? "production") === "sandbox";
16
10
  const authorizationEndpoint = options.loginUrl ? `https://${options.loginUrl}/services/oauth2/authorize` : isSandbox ? "https://test.salesforce.com/services/oauth2/authorize" : "https://login.salesforce.com/services/oauth2/authorize";
@@ -19,18 +13,24 @@ const salesforce = (options) => {
19
13
  return {
20
14
  id: "salesforce",
21
15
  name: "Salesforce",
22
- callbackPath: "/callback/salesforce",
23
16
  async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, additionalParams }) {
24
17
  if (!options.clientId || !options.clientSecret) {
25
18
  logger.error("Client Id and Client Secret are required for Salesforce. Make sure to provide them in the options.");
26
19
  throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
27
20
  }
28
21
  if (!codeVerifier) throw new BetterAuthError("codeVerifier is required for Salesforce");
22
+ const _scopes = options.disableDefaultScope ? [] : [
23
+ "openid",
24
+ "email",
25
+ "profile"
26
+ ];
27
+ if (options.scope) _scopes.push(...options.scope);
28
+ if (scopes) _scopes.push(...scopes);
29
29
  return createAuthorizationURL({
30
30
  id: "salesforce",
31
31
  options,
32
32
  authorizationEndpoint,
33
- scopes: resolveRequestedScopes(options, SALESFORCE_DEFAULT_SCOPES, scopes),
33
+ scopes: _scopes,
34
34
  state,
35
35
  codeVerifier,
36
36
  redirectURI: options.redirectURI || redirectURI,
@@ -36,7 +36,6 @@ interface SlackOptions extends ProviderOptions<SlackProfile> {
36
36
  declare const slack: (options: SlackOptions) => {
37
37
  id: "slack";
38
38
  name: string;
39
- callbackPath: string;
40
39
  createAuthorizationURL({
41
40
  state,
42
41
  scopes,
@@ -51,10 +50,7 @@ declare const slack: (options: SlackOptions) => {
51
50
  loginHint?: string | undefined;
52
51
  idTokenNonce?: string | undefined;
53
52
  additionalParams?: Record<string, string> | undefined;
54
- }): Promise<{
55
- url: URL;
56
- requestedScopes: string[];
57
- }>;
53
+ }): Promise<URL>;
58
54
  validateAuthorizationCode: ({
59
55
  code,
60
56
  redirectURI
@@ -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/slack.ts
7
- const SLACK_DEFAULT_SCOPES = [
8
- "openid",
9
- "profile",
10
- "email"
11
- ];
12
6
  const slack = (options) => {
13
7
  const tokenEndpoint = "https://slack.com/api/openid.connect.token";
14
8
  return {
15
9
  id: "slack",
16
10
  name: "Slack",
17
- callbackPath: "/callback/slack",
18
- async createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
11
+ createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
12
+ const _scopes = options.disableDefaultScope ? [] : [
13
+ "openid",
14
+ "profile",
15
+ "email"
16
+ ];
17
+ if (scopes) _scopes.push(...scopes);
18
+ if (options.scope) _scopes.push(...options.scope);
19
19
  return createAuthorizationURL({
20
20
  id: "slack",
21
21
  options,
22
22
  authorizationEndpoint: "https://slack.com/openid/connect/authorize",
23
- scopes: resolveRequestedScopes(options, SLACK_DEFAULT_SCOPES, scopes),
23
+ scopes: _scopes,
24
24
  state,
25
25
  redirectURI,
26
26
  additionalParams
@@ -14,7 +14,6 @@ interface SpotifyOptions extends ProviderOptions<SpotifyProfile> {
14
14
  declare const spotify: (options: SpotifyOptions) => {
15
15
  id: "spotify";
16
16
  name: string;
17
- callbackPath: string;
18
17
  createAuthorizationURL({
19
18
  state,
20
19
  scopes,
@@ -30,10 +29,7 @@ declare const spotify: (options: SpotifyOptions) => {
30
29
  loginHint?: string | undefined;
31
30
  idTokenNonce?: string | undefined;
32
31
  additionalParams?: Record<string, string> | undefined;
33
- }): Promise<{
34
- url: URL;
35
- requestedScopes: string[];
36
- }>;
32
+ }): Promise<URL>;
37
33
  validateAuthorizationCode: ({
38
34
  code,
39
35
  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/spotify.ts
7
- const SPOTIFY_DEFAULT_SCOPES = ["user-read-email"];
8
6
  const spotify = (options) => {
9
7
  const tokenEndpoint = "https://accounts.spotify.com/api/token";
10
8
  return {
11
9
  id: "spotify",
12
10
  name: "Spotify",
13
- callbackPath: "/callback/spotify",
14
- async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, additionalParams }) {
11
+ createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, additionalParams }) {
12
+ const _scopes = options.disableDefaultScope ? [] : ["user-read-email"];
13
+ if (options.scope) _scopes.push(...options.scope);
14
+ if (scopes) _scopes.push(...scopes);
15
15
  return createAuthorizationURL({
16
16
  id: "spotify",
17
17
  options,
18
18
  authorizationEndpoint: "https://accounts.spotify.com/authorize",
19
- scopes: resolveRequestedScopes(options, SPOTIFY_DEFAULT_SCOPES, scopes),
19
+ scopes: _scopes,
20
20
  state,
21
21
  codeVerifier,
22
22
  redirectURI,
@@ -121,7 +121,6 @@ interface TiktokOptions extends ProviderOptions {
121
121
  declare const tiktok: (options: TiktokOptions) => {
122
122
  id: "tiktok";
123
123
  name: string;
124
- callbackPath: string;
125
124
  createAuthorizationURL({
126
125
  state,
127
126
  scopes,
@@ -136,10 +135,7 @@ declare const tiktok: (options: TiktokOptions) => {
136
135
  loginHint?: string | undefined;
137
136
  idTokenNonce?: string | undefined;
138
137
  additionalParams?: Record<string, string> | undefined;
139
- }): {
140
- url: URL;
141
- requestedScopes: string[];
142
- };
138
+ }): URL;
143
139
  validateAuthorizationCode: ({
144
140
  code,
145
141
  redirectURI
@@ -1,20 +1,19 @@
1
- import { resolveRequestedScopes } from "../oauth2/scopes.mjs";
2
1
  import { RESERVED_AUTHORIZATION_PARAMS_SET } 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/tiktok.ts
7
- const TIKTOK_DEFAULT_SCOPES = ["user.info.profile"];
8
6
  const tiktok = (options) => {
9
7
  const tokenEndpoint = "https://open.tiktokapis.com/v2/oauth/token/";
10
8
  return {
11
9
  id: "tiktok",
12
10
  name: "TikTok",
13
- callbackPath: "/callback/tiktok",
14
11
  createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
15
- const requestedScopes = resolveRequestedScopes(options, TIKTOK_DEFAULT_SCOPES, scopes);
12
+ const _scopes = options.disableDefaultScope ? [] : ["user.info.profile"];
13
+ if (options.scope) _scopes.push(...options.scope);
14
+ if (scopes) _scopes.push(...scopes);
16
15
  const url = new URL("https://www.tiktok.com/v2/auth/authorize");
17
- url.searchParams.set("scope", requestedScopes.join(","));
16
+ url.searchParams.set("scope", _scopes.join(","));
18
17
  url.searchParams.set("response_type", "code");
19
18
  url.searchParams.set("client_key", options.clientKey);
20
19
  url.searchParams.set("redirect_uri", options.redirectURI || redirectURI);
@@ -24,10 +23,7 @@ const tiktok = (options) => {
24
23
  if (key === "client_key") continue;
25
24
  url.searchParams.set(key, value);
26
25
  }
27
- return {
28
- url,
29
- requestedScopes
30
- };
26
+ return url;
31
27
  },
32
28
  validateAuthorizationCode: async ({ code, redirectURI }) => {
33
29
  return validateAuthorizationCode({
@@ -32,7 +32,6 @@ interface TwitchOptions extends ProviderOptions<TwitchProfile> {
32
32
  declare const twitch: (options: TwitchOptions) => {
33
33
  id: "twitch";
34
34
  name: string;
35
- callbackPath: string;
36
35
  createAuthorizationURL({
37
36
  state,
38
37
  scopes,
@@ -47,10 +46,7 @@ declare const twitch: (options: TwitchOptions) => {
47
46
  loginHint?: string | undefined;
48
47
  idTokenNonce?: string | undefined;
49
48
  additionalParams?: Record<string, string> | undefined;
50
- }): Promise<{
51
- url: URL;
52
- requestedScopes: string[];
53
- }>;
49
+ }): Promise<URL>;
54
50
  validateAuthorizationCode: ({
55
51
  code,
56
52
  redirectURI
@@ -1,24 +1,24 @@
1
1
  import { logger } from "../env/logger.mjs";
2
- import { resolveRequestedScopes } from "../oauth2/scopes.mjs";
3
2
  import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
4
3
  import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
5
4
  import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
6
5
  import { decodeJwt } from "jose";
7
6
  //#region src/social-providers/twitch.ts
8
- const TWITCH_DEFAULT_SCOPES = ["user:read:email", "openid"];
9
7
  const twitch = (options) => {
10
8
  const tokenEndpoint = "https://id.twitch.tv/oauth2/token";
11
9
  return {
12
10
  id: "twitch",
13
11
  name: "Twitch",
14
- callbackPath: "/callback/twitch",
15
12
  createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
13
+ const _scopes = options.disableDefaultScope ? [] : ["user:read:email", "openid"];
14
+ if (options.scope) _scopes.push(...options.scope);
15
+ if (scopes) _scopes.push(...scopes);
16
16
  return createAuthorizationURL({
17
17
  id: "twitch",
18
18
  redirectURI,
19
19
  options,
20
20
  authorizationEndpoint: "https://id.twitch.tv/oauth2/authorize",
21
- scopes: resolveRequestedScopes(options, TWITCH_DEFAULT_SCOPES, scopes),
21
+ scopes: _scopes,
22
22
  state,
23
23
  claims: options.claims || [
24
24
  "email",
@@ -82,7 +82,6 @@ interface TwitterOption extends ProviderOptions<TwitterProfile> {
82
82
  declare const twitter: (options: TwitterOption) => {
83
83
  id: "twitter";
84
84
  name: string;
85
- callbackPath: string;
86
85
  createAuthorizationURL(data: {
87
86
  state: string;
88
87
  codeVerifier: string;
@@ -92,10 +91,7 @@ declare const twitter: (options: TwitterOption) => {
92
91
  loginHint?: string | undefined;
93
92
  idTokenNonce?: string | undefined;
94
93
  additionalParams?: Record<string, string> | undefined;
95
- }): Promise<{
96
- url: URL;
97
- requestedScopes: string[];
98
- }>;
94
+ }): Promise<URL>;
99
95
  validateAuthorizationCode: ({
100
96
  code,
101
97
  codeVerifier,
@@ -1,27 +1,27 @@
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/twitter.ts
7
- const TWITTER_DEFAULT_SCOPES = [
8
- "users.read",
9
- "tweet.read",
10
- "offline.access",
11
- "users.email"
12
- ];
13
6
  const twitter = (options) => {
14
7
  const tokenEndpoint = "https://api.x.com/2/oauth2/token";
15
8
  return {
16
9
  id: "twitter",
17
10
  name: "Twitter",
18
- callbackPath: "/callback/twitter",
19
11
  createAuthorizationURL(data) {
12
+ const _scopes = options.disableDefaultScope ? [] : [
13
+ "users.read",
14
+ "tweet.read",
15
+ "offline.access",
16
+ "users.email"
17
+ ];
18
+ if (options.scope) _scopes.push(...options.scope);
19
+ if (data.scopes) _scopes.push(...data.scopes);
20
20
  return createAuthorizationURL({
21
21
  id: "twitter",
22
22
  options,
23
23
  authorizationEndpoint: "https://x.com/i/oauth2/authorize",
24
- scopes: resolveRequestedScopes(options, TWITTER_DEFAULT_SCOPES, data.scopes),
24
+ scopes: _scopes,
25
25
  state: data.state,
26
26
  codeVerifier: data.codeVerifier,
27
27
  redirectURI: data.redirectURI,
@@ -14,7 +14,6 @@ interface VercelOptions extends ProviderOptions<VercelProfile> {
14
14
  declare const vercel: (options: VercelOptions) => {
15
15
  id: "vercel";
16
16
  name: string;
17
- callbackPath: string;
18
17
  createAuthorizationURL({
19
18
  state,
20
19
  scopes,
@@ -30,10 +29,7 @@ declare const vercel: (options: VercelOptions) => {
30
29
  loginHint?: string | undefined;
31
30
  idTokenNonce?: string | undefined;
32
31
  additionalParams?: Record<string, string> | undefined;
33
- }): Promise<{
34
- url: URL;
35
- requestedScopes: string[];
36
- }>;
32
+ }): Promise<URL>;
37
33
  validateAuthorizationCode: ({
38
34
  code,
39
35
  codeVerifier,
@@ -1,22 +1,25 @@
1
1
  import { BetterAuthError } from "../error/index.mjs";
2
- import { resolveRequestedScopes } from "../oauth2/scopes.mjs";
3
2
  import { createAuthorizationURL } from "../oauth2/create-authorization-url.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/vercel.ts
7
- const VERCEL_DEFAULT_SCOPES = [];
8
6
  const vercel = (options) => {
9
7
  return {
10
8
  id: "vercel",
11
9
  name: "Vercel",
12
- callbackPath: "/callback/vercel",
13
10
  createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, additionalParams }) {
14
11
  if (!codeVerifier) throw new BetterAuthError("codeVerifier is required for Vercel");
12
+ let _scopes = void 0;
13
+ if (options.scope !== void 0 || scopes !== void 0) {
14
+ _scopes = [];
15
+ if (options.scope) _scopes.push(...options.scope);
16
+ if (scopes) _scopes.push(...scopes);
17
+ }
15
18
  return createAuthorizationURL({
16
19
  id: "vercel",
17
20
  options,
18
21
  authorizationEndpoint: "https://vercel.com/oauth/authorize",
19
- scopes: resolveRequestedScopes(options, VERCEL_DEFAULT_SCOPES, scopes),
22
+ scopes: _scopes,
20
23
  state,
21
24
  codeVerifier,
22
25
  redirectURI,
@@ -20,7 +20,6 @@ interface VkOption extends ProviderOptions {
20
20
  declare const vk: (options: VkOption) => {
21
21
  id: "vk";
22
22
  name: string;
23
- callbackPath: string;
24
23
  createAuthorizationURL({
25
24
  state,
26
25
  scopes,
@@ -36,10 +35,7 @@ declare const vk: (options: VkOption) => {
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/vk.ts
7
- const VK_DEFAULT_SCOPES = ["email", "phone"];
8
6
  const vk = (options) => {
9
7
  const tokenEndpoint = "https://id.vk.com/oauth2/auth";
10
8
  return {
11
9
  id: "vk",
12
10
  name: "VK",
13
- callbackPath: "/callback/vk",
14
- createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, additionalParams }) {
11
+ async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, additionalParams }) {
12
+ const _scopes = options.disableDefaultScope ? [] : ["email", "phone"];
13
+ if (options.scope) _scopes.push(...options.scope);
14
+ if (scopes) _scopes.push(...scopes);
15
15
  return createAuthorizationURL({
16
16
  id: "vk",
17
17
  options,
18
18
  authorizationEndpoint: "https://id.vk.com/authorize",
19
- scopes: resolveRequestedScopes(options, VK_DEFAULT_SCOPES, scopes),
19
+ scopes: _scopes,
20
20
  state,
21
21
  redirectURI,
22
22
  codeVerifier,
@@ -53,7 +53,6 @@ interface WeChatOptions extends ProviderOptions<WeChatProfile> {
53
53
  declare const wechat: (options: WeChatOptions) => {
54
54
  id: "wechat";
55
55
  name: string;
56
- callbackPath: string;
57
56
  createAuthorizationURL({
58
57
  state,
59
58
  scopes,
@@ -68,10 +67,7 @@ declare const wechat: (options: WeChatOptions) => {
68
67
  loginHint?: string | undefined;
69
68
  idTokenNonce?: string | undefined;
70
69
  additionalParams?: Record<string, string> | undefined;
71
- }): {
72
- url: URL;
73
- requestedScopes: string[];
74
- };
70
+ }): URL;
75
71
  validateAuthorizationCode: ({
76
72
  code
77
73
  }: {
@@ -1,17 +1,16 @@
1
- import { resolveRequestedScopes } from "../oauth2/scopes.mjs";
2
1
  import { RESERVED_AUTHORIZATION_PARAMS_SET } from "../oauth2/create-authorization-url.mjs";
3
2
  import { betterFetch } from "@better-fetch/fetch";
4
3
  //#region src/social-providers/wechat.ts
5
- const WECHAT_DEFAULT_SCOPES = ["snsapi_login"];
6
4
  const wechat = (options) => {
7
5
  return {
8
6
  id: "wechat",
9
7
  name: "WeChat",
10
- callbackPath: "/callback/wechat",
11
8
  createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
12
- const requestedScopes = resolveRequestedScopes(options, WECHAT_DEFAULT_SCOPES, scopes);
9
+ const _scopes = options.disableDefaultScope ? [] : ["snsapi_login"];
10
+ options.scope && _scopes.push(...options.scope);
11
+ scopes && _scopes.push(...scopes);
13
12
  const url = new URL("https://open.weixin.qq.com/connect/qrconnect");
14
- url.searchParams.set("scope", requestedScopes.join(","));
13
+ url.searchParams.set("scope", _scopes.join(","));
15
14
  url.searchParams.set("response_type", "code");
16
15
  url.searchParams.set("appid", options.clientId);
17
16
  url.searchParams.set("redirect_uri", options.redirectURI || redirectURI);
@@ -23,10 +22,7 @@ const wechat = (options) => {
23
22
  url.searchParams.set(key, value);
24
23
  }
25
24
  url.hash = "wechat_redirect";
26
- return {
27
- url,
28
- requestedScopes
29
- };
25
+ return url;
30
26
  },
31
27
  validateAuthorizationCode: async ({ code }) => {
32
28
  const { data: tokenData, error } = await betterFetch("https://api.weixin.qq.com/sns/oauth2/access_token?" + new URLSearchParams({
@@ -116,10 +116,8 @@ interface ZoomOptions extends ProviderOptions<ZoomProfile> {
116
116
  declare const zoom: (userOptions: ZoomOptions) => {
117
117
  id: "zoom";
118
118
  name: string;
119
- callbackPath: string;
120
119
  createAuthorizationURL: ({
121
120
  state,
122
- scopes,
123
121
  redirectURI,
124
122
  codeVerifier,
125
123
  additionalParams
@@ -132,10 +130,7 @@ declare const zoom: (userOptions: ZoomOptions) => {
132
130
  loginHint?: string | undefined;
133
131
  idTokenNonce?: string | undefined;
134
132
  additionalParams?: Record<string, string> | undefined;
135
- }) => Promise<{
136
- url: URL;
137
- requestedScopes: string[];
138
- }>;
133
+ }) => Promise<URL>;
139
134
  validateAuthorizationCode: ({
140
135
  code,
141
136
  redirectURI,
@@ -1,10 +1,8 @@
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/zoom.ts
7
- const ZOOM_DEFAULT_SCOPES = [];
8
6
  const zoom = (userOptions) => {
9
7
  const options = {
10
8
  pkce: true,
@@ -13,19 +11,15 @@ const zoom = (userOptions) => {
13
11
  return {
14
12
  id: "zoom",
15
13
  name: "Zoom",
16
- callbackPath: "/callback/zoom",
17
- createAuthorizationURL: ({ state, scopes, redirectURI, codeVerifier, additionalParams }) => {
18
- return createAuthorizationURL({
19
- id: "zoom",
20
- options,
21
- authorizationEndpoint: "https://zoom.us/oauth/authorize",
22
- scopes: resolveRequestedScopes(options, ZOOM_DEFAULT_SCOPES, scopes),
23
- state,
24
- redirectURI,
25
- codeVerifier: options.pkce ? codeVerifier : void 0,
26
- additionalParams
27
- });
28
- },
14
+ createAuthorizationURL: async ({ state, redirectURI, codeVerifier, additionalParams }) => createAuthorizationURL({
15
+ id: "zoom",
16
+ options,
17
+ authorizationEndpoint: "https://zoom.us/oauth/authorize",
18
+ state,
19
+ redirectURI,
20
+ codeVerifier: options.pkce ? codeVerifier : void 0,
21
+ additionalParams
22
+ }),
29
23
  validateAuthorizationCode: async ({ code, redirectURI, codeVerifier }) => {
30
24
  return validateAuthorizationCode({
31
25
  code,