@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
@@ -25,7 +25,6 @@ interface PolarOptions extends ProviderOptions<PolarProfile> {}
25
25
  declare const polar: (options: PolarOptions) => {
26
26
  id: "polar";
27
27
  name: string;
28
- callbackPath: string;
29
28
  createAuthorizationURL({
30
29
  state,
31
30
  scopes,
@@ -39,11 +38,9 @@ declare const polar: (options: PolarOptions) => {
39
38
  redirectURI: string;
40
39
  display?: string | undefined;
41
40
  loginHint?: string | undefined;
41
+ idTokenNonce?: string | undefined;
42
42
  additionalParams?: Record<string, string> | undefined;
43
- }): Promise<{
44
- url: URL;
45
- requestedScopes: string[];
46
- }>;
43
+ }): Promise<URL>;
47
44
  validateAuthorizationCode: ({
48
45
  code,
49
46
  codeVerifier,
@@ -56,6 +53,7 @@ declare const polar: (options: PolarOptions) => {
56
53
  }) => Promise<OAuth2Tokens>;
57
54
  refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
58
55
  getUserInfo(token: OAuth2Tokens & {
56
+ expectedIdTokenNonce?: string | undefined;
59
57
  user?: {
60
58
  name?: {
61
59
  firstName?: string;
@@ -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/polar.ts
7
- const POLAR_DEFAULT_SCOPES = [
8
- "openid",
9
- "profile",
10
- "email"
11
- ];
12
6
  const polar = (options) => {
13
7
  const tokenEndpoint = "https://api.polar.sh/v1/oauth2/token";
14
8
  return {
15
9
  id: "polar",
16
10
  name: "Polar",
17
- callbackPath: "/callback/polar",
18
11
  createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, additionalParams }) {
12
+ const _scopes = options.disableDefaultScope ? [] : [
13
+ "openid",
14
+ "profile",
15
+ "email"
16
+ ];
17
+ if (options.scope) _scopes.push(...options.scope);
18
+ if (scopes) _scopes.push(...scopes);
19
19
  return createAuthorizationURL({
20
20
  id: "polar",
21
21
  options,
22
22
  authorizationEndpoint: "https://polar.sh/oauth2/authorize",
23
- scopes: resolveRequestedScopes(options, POLAR_DEFAULT_SCOPES, scopes),
23
+ scopes: _scopes,
24
24
  state,
25
25
  codeVerifier,
26
26
  redirectURI,
@@ -16,7 +16,6 @@ interface RailwayOptions extends ProviderOptions<RailwayProfile> {
16
16
  declare const railway: (options: RailwayOptions) => {
17
17
  id: "railway";
18
18
  name: string;
19
- callbackPath: string;
20
19
  createAuthorizationURL({
21
20
  state,
22
21
  scopes,
@@ -30,11 +29,9 @@ declare const railway: (options: RailwayOptions) => {
30
29
  redirectURI: string;
31
30
  display?: string | undefined;
32
31
  loginHint?: string | undefined;
32
+ idTokenNonce?: string | undefined;
33
33
  additionalParams?: Record<string, string> | undefined;
34
- }): Promise<{
35
- url: URL;
36
- requestedScopes: string[];
37
- }>;
34
+ }): Promise<URL>;
38
35
  validateAuthorizationCode: ({
39
36
  code,
40
37
  codeVerifier,
@@ -47,6 +44,7 @@ declare const railway: (options: RailwayOptions) => {
47
44
  }) => Promise<OAuth2Tokens>;
48
45
  refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
49
46
  getUserInfo(token: OAuth2Tokens & {
47
+ expectedIdTokenNonce?: string | undefined;
50
48
  user?: {
51
49
  name?: {
52
50
  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";
@@ -7,22 +6,23 @@ import { betterFetch } from "@better-fetch/fetch";
7
6
  const authorizationEndpoint = "https://backboard.railway.com/oauth/auth";
8
7
  const tokenEndpoint = "https://backboard.railway.com/oauth/token";
9
8
  const userinfoEndpoint = "https://backboard.railway.com/oauth/me";
10
- const RAILWAY_DEFAULT_SCOPES = [
11
- "openid",
12
- "email",
13
- "profile"
14
- ];
15
9
  const railway = (options) => {
16
10
  return {
17
11
  id: "railway",
18
12
  name: "Railway",
19
- callbackPath: "/callback/railway",
20
- async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, additionalParams }) {
13
+ createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, additionalParams }) {
14
+ const _scopes = options.disableDefaultScope ? [] : [
15
+ "openid",
16
+ "email",
17
+ "profile"
18
+ ];
19
+ if (options.scope) _scopes.push(...options.scope);
20
+ if (scopes) _scopes.push(...scopes);
21
21
  return createAuthorizationURL({
22
22
  id: "railway",
23
23
  options,
24
24
  authorizationEndpoint,
25
- scopes: resolveRequestedScopes(options, RAILWAY_DEFAULT_SCOPES, scopes),
25
+ scopes: _scopes,
26
26
  state,
27
27
  codeVerifier,
28
28
  redirectURI,
@@ -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,
@@ -28,11 +27,9 @@ declare const reddit: (options: RedditOptions) => {
28
27
  redirectURI: string;
29
28
  display?: string | undefined;
30
29
  loginHint?: string | undefined;
30
+ idTokenNonce?: string | undefined;
31
31
  additionalParams?: Record<string, string> | undefined;
32
- }): Promise<{
33
- url: URL;
34
- requestedScopes: string[];
35
- }>;
32
+ }): Promise<URL>;
36
33
  validateAuthorizationCode: ({
37
34
  code,
38
35
  redirectURI
@@ -44,6 +41,7 @@ declare const reddit: (options: RedditOptions) => {
44
41
  }) => Promise<OAuth2Tokens>;
45
42
  refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
46
43
  getUserInfo(token: OAuth2Tokens & {
44
+ expectedIdTokenNonce?: string | undefined;
47
45
  user?: {
48
46
  name?: {
49
47
  firstName?: string;
@@ -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,
@@ -36,11 +35,9 @@ declare const roblox: (options: RobloxOptions) => {
36
35
  redirectURI: string;
37
36
  display?: string | undefined;
38
37
  loginHint?: string | undefined;
38
+ idTokenNonce?: string | undefined;
39
39
  additionalParams?: Record<string, string> | undefined;
40
- }): Promise<{
41
- url: URL;
42
- requestedScopes: string[];
43
- }>;
40
+ }): Promise<URL>;
44
41
  validateAuthorizationCode: ({
45
42
  code,
46
43
  redirectURI
@@ -52,6 +49,7 @@ declare const roblox: (options: RobloxOptions) => {
52
49
  }) => Promise<OAuth2Tokens>;
53
50
  refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
54
51
  getUserInfo(token: OAuth2Tokens & {
52
+ expectedIdTokenNonce?: string | undefined;
55
53
  user?: {
56
54
  name?: {
57
55
  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/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,
@@ -44,11 +43,9 @@ declare const salesforce: (options: SalesforceOptions) => {
44
43
  redirectURI: string;
45
44
  display?: string | undefined;
46
45
  loginHint?: string | undefined;
46
+ idTokenNonce?: string | undefined;
47
47
  additionalParams?: Record<string, string> | undefined;
48
- }): Promise<{
49
- url: URL;
50
- requestedScopes: string[];
51
- }>;
48
+ }): Promise<URL>;
52
49
  validateAuthorizationCode: ({
53
50
  code,
54
51
  codeVerifier,
@@ -61,6 +58,7 @@ declare const salesforce: (options: SalesforceOptions) => {
61
58
  }) => Promise<OAuth2Tokens>;
62
59
  refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
63
60
  getUserInfo(token: OAuth2Tokens & {
61
+ expectedIdTokenNonce?: string | undefined;
64
62
  user?: {
65
63
  name?: {
66
64
  firstName?: string;
@@ -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,
@@ -49,11 +48,9 @@ declare const slack: (options: SlackOptions) => {
49
48
  redirectURI: string;
50
49
  display?: string | undefined;
51
50
  loginHint?: string | undefined;
51
+ idTokenNonce?: string | undefined;
52
52
  additionalParams?: Record<string, string> | undefined;
53
- }): Promise<{
54
- url: URL;
55
- requestedScopes: string[];
56
- }>;
53
+ }): Promise<URL>;
57
54
  validateAuthorizationCode: ({
58
55
  code,
59
56
  redirectURI
@@ -65,6 +62,7 @@ declare const slack: (options: SlackOptions) => {
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;
@@ -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,
@@ -28,11 +27,9 @@ declare const spotify: (options: SpotifyOptions) => {
28
27
  redirectURI: string;
29
28
  display?: string | undefined;
30
29
  loginHint?: string | undefined;
30
+ idTokenNonce?: string | undefined;
31
31
  additionalParams?: Record<string, string> | undefined;
32
- }): Promise<{
33
- url: URL;
34
- requestedScopes: string[];
35
- }>;
32
+ }): Promise<URL>;
36
33
  validateAuthorizationCode: ({
37
34
  code,
38
35
  codeVerifier,
@@ -45,6 +42,7 @@ declare const spotify: (options: SpotifyOptions) => {
45
42
  }) => Promise<OAuth2Tokens>;
46
43
  refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
47
44
  getUserInfo(token: OAuth2Tokens & {
45
+ expectedIdTokenNonce?: string | undefined;
48
46
  user?: {
49
47
  name?: {
50
48
  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/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,
@@ -134,11 +133,9 @@ declare const tiktok: (options: TiktokOptions) => {
134
133
  redirectURI: string;
135
134
  display?: string | undefined;
136
135
  loginHint?: string | undefined;
136
+ idTokenNonce?: string | undefined;
137
137
  additionalParams?: Record<string, string> | undefined;
138
- }): {
139
- url: URL;
140
- requestedScopes: string[];
141
- };
138
+ }): URL;
142
139
  validateAuthorizationCode: ({
143
140
  code,
144
141
  redirectURI
@@ -150,6 +147,7 @@ declare const tiktok: (options: TiktokOptions) => {
150
147
  }) => Promise<OAuth2Tokens>;
151
148
  refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
152
149
  getUserInfo(token: OAuth2Tokens & {
150
+ expectedIdTokenNonce?: string | undefined;
153
151
  user?: {
154
152
  name?: {
155
153
  firstName?: string;
@@ -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,
@@ -45,11 +44,9 @@ declare const twitch: (options: TwitchOptions) => {
45
44
  redirectURI: string;
46
45
  display?: string | undefined;
47
46
  loginHint?: string | undefined;
47
+ idTokenNonce?: string | undefined;
48
48
  additionalParams?: Record<string, string> | undefined;
49
- }): Promise<{
50
- url: URL;
51
- requestedScopes: string[];
52
- }>;
49
+ }): Promise<URL>;
53
50
  validateAuthorizationCode: ({
54
51
  code,
55
52
  redirectURI
@@ -61,6 +58,7 @@ declare const twitch: (options: TwitchOptions) => {
61
58
  }) => Promise<OAuth2Tokens>;
62
59
  refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
63
60
  getUserInfo(token: OAuth2Tokens & {
61
+ expectedIdTokenNonce?: string | undefined;
64
62
  user?: {
65
63
  name?: {
66
64
  firstName?: string;
@@ -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;
@@ -90,11 +89,9 @@ declare const twitter: (options: TwitterOption) => {
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
  codeVerifier,
@@ -107,6 +104,7 @@ declare const twitter: (options: TwitterOption) => {
107
104
  }) => Promise<OAuth2Tokens>;
108
105
  refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
109
106
  getUserInfo(token: OAuth2Tokens & {
107
+ expectedIdTokenNonce?: string | undefined;
110
108
  user?: {
111
109
  name?: {
112
110
  firstName?: string;
@@ -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,