@better-auth/core 1.7.0-beta.7 → 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 (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
@@ -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/kakao.ts
7
- const KAKAO_DEFAULT_SCOPES = [
8
- "account_email",
9
- "profile_image",
10
- "profile_nickname"
11
- ];
12
6
  const kakao = (options) => {
13
7
  const tokenEndpoint = "https://kauth.kakao.com/oauth/token";
14
8
  return {
15
9
  id: "kakao",
16
10
  name: "Kakao",
17
- callbackPath: "/callback/kakao",
18
11
  createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
12
+ const _scopes = options.disableDefaultScope ? [] : [
13
+ "account_email",
14
+ "profile_image",
15
+ "profile_nickname"
16
+ ];
17
+ if (options.scope) _scopes.push(...options.scope);
18
+ if (scopes) _scopes.push(...scopes);
19
19
  return createAuthorizationURL({
20
20
  id: "kakao",
21
21
  options,
22
22
  authorizationEndpoint: "https://kauth.kakao.com/oauth/authorize",
23
- scopes: resolveRequestedScopes(options, KAKAO_DEFAULT_SCOPES, scopes),
23
+ scopes: _scopes,
24
24
  state,
25
25
  redirectURI,
26
26
  additionalParams
@@ -24,7 +24,6 @@ interface KickOptions extends ProviderOptions<KickProfile> {
24
24
  declare const kick: (options: KickOptions) => {
25
25
  id: "kick";
26
26
  name: string;
27
- callbackPath: string;
28
27
  createAuthorizationURL({
29
28
  state,
30
29
  scopes,
@@ -40,10 +39,7 @@ declare const kick: (options: KickOptions) => {
40
39
  loginHint?: string | undefined;
41
40
  idTokenNonce?: string | undefined;
42
41
  additionalParams?: Record<string, string> | undefined;
43
- }): Promise<{
44
- url: URL;
45
- requestedScopes: string[];
46
- }>;
42
+ }): Promise<URL>;
47
43
  validateAuthorizationCode({
48
44
  code,
49
45
  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/kick.ts
7
- const KICK_DEFAULT_SCOPES = ["user:read"];
8
6
  const kick = (options) => {
9
7
  return {
10
8
  id: "kick",
11
9
  name: "Kick",
12
- callbackPath: "/callback/kick",
13
10
  createAuthorizationURL({ state, scopes, redirectURI, codeVerifier, additionalParams }) {
11
+ const _scopes = options.disableDefaultScope ? [] : ["user:read"];
12
+ if (options.scope) _scopes.push(...options.scope);
13
+ if (scopes) _scopes.push(...scopes);
14
14
  return createAuthorizationURL({
15
15
  id: "kick",
16
16
  redirectURI,
17
17
  options,
18
18
  authorizationEndpoint: "https://id.kick.com/oauth/authorize",
19
- scopes: resolveRequestedScopes(options, KICK_DEFAULT_SCOPES, scopes),
19
+ scopes: _scopes,
20
20
  codeVerifier,
21
21
  state,
22
22
  additionalParams
@@ -33,7 +33,6 @@ interface LineOptions extends ProviderOptions<LineUserInfo | LineIdTokenPayload>
33
33
  declare const line: (options: LineOptions) => {
34
34
  id: "line";
35
35
  name: string;
36
- callbackPath: string;
37
36
  createAuthorizationURL({
38
37
  state,
39
38
  scopes,
@@ -50,10 +49,7 @@ declare const line: (options: LineOptions) => {
50
49
  loginHint?: string | undefined;
51
50
  idTokenNonce?: string | undefined;
52
51
  additionalParams?: Record<string, string> | undefined;
53
- }): Promise<{
54
- url: URL;
55
- requestedScopes: string[];
56
- }>;
52
+ }): Promise<URL>;
57
53
  validateAuthorizationCode: ({
58
54
  code,
59
55
  codeVerifier,
@@ -1,15 +1,9 @@
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 { decodeJwt } from "jose";
6
5
  import { betterFetch } from "@better-fetch/fetch";
7
6
  //#region src/social-providers/line.ts
8
- const LINE_DEFAULT_SCOPES = [
9
- "openid",
10
- "profile",
11
- "email"
12
- ];
13
7
  /**
14
8
  * LINE Login v2.1
15
9
  * - Authorization endpoint: https://access.line.me/oauth2/v2.1/authorize
@@ -27,13 +21,19 @@ const line = (options) => {
27
21
  return {
28
22
  id: "line",
29
23
  name: "LINE",
30
- callbackPath: "/callback/line",
31
- createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, loginHint, additionalParams }) {
32
- return createAuthorizationURL({
24
+ async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, loginHint, additionalParams }) {
25
+ const _scopes = options.disableDefaultScope ? [] : [
26
+ "openid",
27
+ "profile",
28
+ "email"
29
+ ];
30
+ if (options.scope) _scopes.push(...options.scope);
31
+ if (scopes) _scopes.push(...scopes);
32
+ return await createAuthorizationURL({
33
33
  id: "line",
34
34
  options,
35
35
  authorizationEndpoint,
36
- scopes: resolveRequestedScopes(options, LINE_DEFAULT_SCOPES, scopes),
36
+ scopes: _scopes,
37
37
  state,
38
38
  codeVerifier,
39
39
  redirectURI,
@@ -20,7 +20,6 @@ interface LinearOptions extends ProviderOptions<LinearUser> {
20
20
  declare const linear: (options: LinearOptions) => {
21
21
  id: "linear";
22
22
  name: string;
23
- callbackPath: string;
24
23
  createAuthorizationURL({
25
24
  state,
26
25
  scopes,
@@ -36,10 +35,7 @@ declare const linear: (options: LinearOptions) => {
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
  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/linear.ts
7
- const LINEAR_DEFAULT_SCOPES = ["read"];
8
6
  const linear = (options) => {
9
7
  const tokenEndpoint = "https://api.linear.app/oauth/token";
10
8
  return {
11
9
  id: "linear",
12
10
  name: "Linear",
13
- callbackPath: "/callback/linear",
14
11
  createAuthorizationURL({ state, scopes, loginHint, redirectURI, additionalParams }) {
12
+ const _scopes = options.disableDefaultScope ? [] : ["read"];
13
+ if (options.scope) _scopes.push(...options.scope);
14
+ if (scopes) _scopes.push(...scopes);
15
15
  return createAuthorizationURL({
16
16
  id: "linear",
17
17
  options,
18
18
  authorizationEndpoint: "https://linear.app/oauth/authorize",
19
- scopes: resolveRequestedScopes(options, LINEAR_DEFAULT_SCOPES, scopes),
19
+ scopes: _scopes,
20
20
  state,
21
21
  redirectURI,
22
22
  loginHint,
@@ -19,7 +19,6 @@ interface LinkedInOptions extends ProviderOptions<LinkedInProfile> {
19
19
  declare const linkedin: (options: LinkedInOptions) => {
20
20
  id: "linkedin";
21
21
  name: string;
22
- callbackPath: string;
23
22
  createAuthorizationURL: ({
24
23
  state,
25
24
  scopes,
@@ -35,10 +34,7 @@ declare const linkedin: (options: LinkedInOptions) => {
35
34
  loginHint?: string | undefined;
36
35
  idTokenNonce?: string | undefined;
37
36
  additionalParams?: Record<string, string> | undefined;
38
- }) => Promise<{
39
- url: URL;
40
- requestedScopes: string[];
41
- }>;
37
+ }) => Promise<URL>;
42
38
  validateAuthorizationCode: ({
43
39
  code,
44
40
  redirectURI
@@ -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/linkedin.ts
7
- const LINKEDIN_DEFAULT_SCOPES = [
8
- "profile",
9
- "email",
10
- "openid"
11
- ];
12
6
  const linkedin = (options) => {
13
7
  const authorizationEndpoint = "https://www.linkedin.com/oauth/v2/authorization";
14
8
  const tokenEndpoint = "https://www.linkedin.com/oauth/v2/accessToken";
15
9
  return {
16
10
  id: "linkedin",
17
11
  name: "Linkedin",
18
- callbackPath: "/callback/linkedin",
19
- createAuthorizationURL: ({ state, scopes, redirectURI, loginHint, additionalParams }) => {
20
- return createAuthorizationURL({
12
+ createAuthorizationURL: async ({ state, scopes, redirectURI, loginHint, additionalParams }) => {
13
+ const _scopes = options.disableDefaultScope ? [] : [
14
+ "profile",
15
+ "email",
16
+ "openid"
17
+ ];
18
+ if (options.scope) _scopes.push(...options.scope);
19
+ if (scopes) _scopes.push(...scopes);
20
+ return await createAuthorizationURL({
21
21
  id: "linkedin",
22
22
  options,
23
23
  authorizationEndpoint,
24
- scopes: resolveRequestedScopes(options, LINKEDIN_DEFAULT_SCOPES, scopes),
24
+ scopes: _scopes,
25
25
  state,
26
26
  loginHint,
27
27
  redirectURI,
@@ -139,7 +139,6 @@ interface MicrosoftOptions extends ProviderOptions<MicrosoftEntraIDProfile> {
139
139
  declare const microsoft: (options: MicrosoftOptions) => {
140
140
  id: "microsoft";
141
141
  name: string;
142
- callbackPath: string;
143
142
  createAuthorizationURL(data: {
144
143
  state: string;
145
144
  codeVerifier: string;
@@ -149,10 +148,7 @@ declare const microsoft: (options: MicrosoftOptions) => {
149
148
  loginHint?: string | undefined;
150
149
  idTokenNonce?: string | undefined;
151
150
  additionalParams?: Record<string, string> | undefined;
152
- }): Promise<{
153
- url: URL;
154
- requestedScopes: string[];
155
- }>;
151
+ }): Promise<URL>;
156
152
  validateAuthorizationCode({
157
153
  code,
158
154
  codeVerifier,
@@ -1,6 +1,5 @@
1
1
  import { APIError, BetterAuthError } from "../error/index.mjs";
2
2
  import { logger } from "../env/logger.mjs";
3
- import { resolveRequestedScopes } from "../oauth2/scopes.mjs";
4
3
  import { getPrimaryClientId } from "../oauth2/utils.mjs";
5
4
  import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
6
5
  import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
@@ -16,13 +15,6 @@ import { betterFetch } from "@better-fetch/fetch";
16
15
  * @see https://learn.microsoft.com/en-us/entra/identity-platform/id-token-claims-reference
17
16
  */
18
17
  const MICROSOFT_CONSUMER_TENANT_ID = "9188040d-6c67-4c5b-b112-36a304b66dad";
19
- const MICROSOFT_ENTRA_ID_DEFAULT_SCOPES = [
20
- "openid",
21
- "profile",
22
- "email",
23
- "User.Read",
24
- "offline_access"
25
- ];
26
18
  const microsoft = (options) => {
27
19
  const tenant = options.tenantId || "common";
28
20
  let authority = options.authority || "https://login.microsoftonline.com";
@@ -37,20 +29,27 @@ const microsoft = (options) => {
37
29
  return {
38
30
  id: "microsoft",
39
31
  name: "Microsoft EntraID",
40
- callbackPath: "/callback/microsoft",
41
32
  createAuthorizationURL(data) {
42
33
  if (!getPrimaryClientId(options.clientId)) {
43
34
  logger.error("Client Id is required for Microsoft Entra ID. Make sure to provide it in the options.");
44
35
  throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
45
36
  }
46
- const requestedScopes = resolveRequestedScopes(options, MICROSOFT_ENTRA_ID_DEFAULT_SCOPES, data.scopes);
37
+ const scopes = options.disableDefaultScope ? [] : [
38
+ "openid",
39
+ "profile",
40
+ "email",
41
+ "User.Read",
42
+ "offline_access"
43
+ ];
44
+ if (options.scope) scopes.push(...options.scope);
45
+ if (data.scopes) scopes.push(...data.scopes);
47
46
  return createAuthorizationURL({
48
47
  id: "microsoft",
49
48
  options,
50
49
  authorizationEndpoint,
51
50
  state: data.state,
52
51
  codeVerifier: data.codeVerifier,
53
- scopes: requestedScopes,
52
+ scopes,
54
53
  redirectURI: data.redirectURI,
55
54
  prompt: options.prompt,
56
55
  loginHint: data.loginHint,
@@ -24,7 +24,6 @@ interface NaverOptions extends ProviderOptions<NaverProfile> {
24
24
  declare const naver: (options: NaverOptions) => {
25
25
  id: "naver";
26
26
  name: string;
27
- callbackPath: string;
28
27
  createAuthorizationURL({
29
28
  state,
30
29
  scopes,
@@ -39,10 +38,7 @@ declare const naver: (options: NaverOptions) => {
39
38
  loginHint?: string | undefined;
40
39
  idTokenNonce?: string | undefined;
41
40
  additionalParams?: Record<string, string> | undefined;
42
- }): Promise<{
43
- url: URL;
44
- requestedScopes: string[];
45
- }>;
41
+ }): Promise<URL>;
46
42
  validateAuthorizationCode: ({
47
43
  code,
48
44
  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/naver.ts
7
- const NAVER_DEFAULT_SCOPES = ["profile", "email"];
8
6
  const naver = (options) => {
9
7
  const tokenEndpoint = "https://nid.naver.com/oauth2.0/token";
10
8
  return {
11
9
  id: "naver",
12
10
  name: "Naver",
13
- callbackPath: "/callback/naver",
14
11
  createAuthorizationURL({ state, scopes, redirectURI, additionalParams }) {
12
+ const _scopes = options.disableDefaultScope ? [] : ["profile", "email"];
13
+ if (options.scope) _scopes.push(...options.scope);
14
+ if (scopes) _scopes.push(...scopes);
15
15
  return createAuthorizationURL({
16
16
  id: "naver",
17
17
  options,
18
18
  authorizationEndpoint: "https://nid.naver.com/oauth2.0/authorize",
19
- scopes: resolveRequestedScopes(options, NAVER_DEFAULT_SCOPES, scopes),
19
+ scopes: _scopes,
20
20
  state,
21
21
  redirectURI,
22
22
  additionalParams
@@ -16,7 +16,6 @@ interface NotionOptions extends ProviderOptions<NotionProfile> {
16
16
  declare const notion: (options: NotionOptions) => {
17
17
  id: "notion";
18
18
  name: string;
19
- callbackPath: string;
20
19
  createAuthorizationURL({
21
20
  state,
22
21
  scopes,
@@ -32,10 +31,7 @@ declare const notion: (options: NotionOptions) => {
32
31
  loginHint?: string | undefined;
33
32
  idTokenNonce?: string | undefined;
34
33
  additionalParams?: Record<string, string> | undefined;
35
- }): Promise<{
36
- url: URL;
37
- requestedScopes: string[];
38
- }>;
34
+ }): Promise<URL>;
39
35
  validateAuthorizationCode: ({
40
36
  code,
41
37
  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/notion.ts
7
- const NOTION_DEFAULT_SCOPES = [];
8
6
  const notion = (options) => {
9
7
  const tokenEndpoint = "https://api.notion.com/v1/oauth/token";
10
8
  return {
11
9
  id: "notion",
12
10
  name: "Notion",
13
- callbackPath: "/callback/notion",
14
11
  createAuthorizationURL({ state, scopes, loginHint, redirectURI, additionalParams }) {
12
+ const _scopes = options.disableDefaultScope ? [] : [];
13
+ if (options.scope) _scopes.push(...options.scope);
14
+ if (scopes) _scopes.push(...scopes);
15
15
  return createAuthorizationURL({
16
16
  id: "notion",
17
17
  options,
18
18
  authorizationEndpoint: "https://api.notion.com/v1/oauth/authorize",
19
- scopes: resolveRequestedScopes(options, NOTION_DEFAULT_SCOPES, scopes),
19
+ scopes: _scopes,
20
20
  state,
21
21
  redirectURI,
22
22
  loginHint,
@@ -21,7 +21,6 @@ interface PaybinOptions extends ProviderOptions<PaybinProfile> {
21
21
  declare const paybin: (options: PaybinOptions) => {
22
22
  id: "paybin";
23
23
  name: string;
24
- callbackPath: string;
25
24
  createAuthorizationURL({
26
25
  state,
27
26
  scopes,
@@ -38,10 +37,7 @@ declare const paybin: (options: PaybinOptions) => {
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
  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 { decodeJwt } from "jose";
8
7
  //#region src/social-providers/paybin.ts
9
- const PAYBIN_DEFAULT_SCOPES = [
10
- "openid",
11
- "email",
12
- "profile"
13
- ];
14
8
  const paybin = (options) => {
15
9
  const issuer = options.issuer || "https://idp.paybin.io";
16
10
  const authorizationEndpoint = `${issuer}/oauth2/authorize`;
@@ -18,18 +12,24 @@ const paybin = (options) => {
18
12
  return {
19
13
  id: "paybin",
20
14
  name: "Paybin",
21
- callbackPath: "/callback/paybin",
22
- createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, loginHint, additionalParams }) {
15
+ async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, loginHint, additionalParams }) {
23
16
  if (!options.clientId || !options.clientSecret) {
24
17
  logger.error("Client Id and Client Secret is required for Paybin. Make sure to provide them in the options.");
25
18
  throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
26
19
  }
27
20
  if (!codeVerifier) throw new BetterAuthError("codeVerifier is required for Paybin");
28
- return createAuthorizationURL({
21
+ const _scopes = options.disableDefaultScope ? [] : [
22
+ "openid",
23
+ "email",
24
+ "profile"
25
+ ];
26
+ if (options.scope) _scopes.push(...options.scope);
27
+ if (scopes) _scopes.push(...scopes);
28
+ return await createAuthorizationURL({
29
29
  id: "paybin",
30
30
  options,
31
31
  authorizationEndpoint,
32
- scopes: resolveRequestedScopes(options, PAYBIN_DEFAULT_SCOPES, scopes),
32
+ scopes: _scopes,
33
33
  state,
34
34
  codeVerifier,
35
35
  redirectURI,
@@ -51,7 +51,6 @@ interface PayPalOptions extends ProviderOptions<PayPalProfile> {
51
51
  declare const paypal: (options: PayPalOptions) => {
52
52
  id: "paypal";
53
53
  name: string;
54
- callbackPath: string;
55
54
  createAuthorizationURL({
56
55
  state,
57
56
  codeVerifier,
@@ -66,10 +65,7 @@ declare const paypal: (options: PayPalOptions) => {
66
65
  loginHint?: string | undefined;
67
66
  idTokenNonce?: string | undefined;
68
67
  additionalParams?: Record<string, string> | undefined;
69
- }): Promise<{
70
- url: URL;
71
- requestedScopes: string[];
72
- }>;
68
+ }): Promise<URL>;
73
69
  validateAuthorizationCode: ({
74
70
  code,
75
71
  redirectURI
@@ -12,18 +12,12 @@ const paypal = (options) => {
12
12
  return {
13
13
  id: "paypal",
14
14
  name: "PayPal",
15
- callbackPath: "/callback/paypal",
16
- createAuthorizationURL({ state, codeVerifier, redirectURI, additionalParams }) {
15
+ async createAuthorizationURL({ state, codeVerifier, redirectURI, additionalParams }) {
17
16
  if (!options.clientId || !options.clientSecret) {
18
17
  logger.error("Client Id and Client Secret is required for PayPal. Make sure to provide them in the options.");
19
18
  throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
20
19
  }
21
- /**
22
- * Log in with PayPal doesn't use traditional OAuth2 scopes
23
- * Instead, permissions are configured in the PayPal Developer Dashboard
24
- * We don't pass any scopes to avoid "invalid scope" errors
25
- **/
26
- return createAuthorizationURL({
20
+ return await createAuthorizationURL({
27
21
  id: "paypal",
28
22
  options,
29
23
  authorizationEndpoint,
@@ -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,
@@ -41,10 +40,7 @@ declare const polar: (options: PolarOptions) => {
41
40
  loginHint?: string | undefined;
42
41
  idTokenNonce?: string | undefined;
43
42
  additionalParams?: Record<string, string> | undefined;
44
- }): Promise<{
45
- url: URL;
46
- requestedScopes: string[];
47
- }>;
43
+ }): Promise<URL>;
48
44
  validateAuthorizationCode: ({
49
45
  code,
50
46
  codeVerifier,
@@ -1,26 +1,26 @@
1
- import { resolveRequestedScopes } from "../oauth2/scopes.mjs";
2
1
  import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
3
2
  import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
4
3
  import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
5
4
  import { betterFetch } from "@better-fetch/fetch";
6
5
  //#region src/social-providers/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,
@@ -32,10 +31,7 @@ declare const railway: (options: RailwayOptions) => {
32
31
  loginHint?: string | undefined;
33
32
  idTokenNonce?: string | undefined;
34
33
  additionalParams?: Record<string, string> | undefined;
35
- }): Promise<{
36
- url: URL;
37
- requestedScopes: string[];
38
- }>;
34
+ }): Promise<URL>;
39
35
  validateAuthorizationCode: ({
40
36
  code,
41
37
  codeVerifier,
@@ -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,