@better-auth/core 1.7.0-rc.1 → 1.7.0-rc.3

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 (213) hide show
  1. package/dist/api/index.d.mts +28 -28
  2. package/dist/async_hooks/index.d.mts +0 -1
  3. package/dist/async_hooks/pure.index.d.mts +0 -1
  4. package/dist/context/endpoint-context.d.mts +1 -1
  5. package/dist/context/global.d.mts +0 -1
  6. package/dist/context/global.mjs +1 -1
  7. package/dist/context/request-state.d.mts +0 -1
  8. package/dist/context/request-state.mjs +8 -5
  9. package/dist/context/transaction.d.mts +8 -3
  10. package/dist/context/transaction.mjs +27 -10
  11. package/dist/db/adapter/factory.d.mts +3 -5
  12. package/dist/db/adapter/factory.mjs +7 -5
  13. package/dist/db/adapter/get-default-field-name.d.mts +2 -9
  14. package/dist/db/adapter/get-default-model-name.d.mts +1 -5
  15. package/dist/db/adapter/get-default-model-name.mjs +6 -5
  16. package/dist/db/adapter/get-field-attributes.d.mts +4 -11
  17. package/dist/db/adapter/get-field-name.d.mts +2 -9
  18. package/dist/db/adapter/get-id-field.d.mts +4 -12
  19. package/dist/db/adapter/get-model-name.d.mts +1 -5
  20. package/dist/db/adapter/index.d.mts +7 -32
  21. package/dist/db/adapter/types.d.mts +5 -17
  22. package/dist/db/adapter/utils.d.mts +0 -1
  23. package/dist/db/database-index.d.mts +44 -0
  24. package/dist/db/database-index.mjs +168 -0
  25. package/dist/db/get-tables.d.mts +7 -1
  26. package/dist/db/get-tables.mjs +47 -6
  27. package/dist/db/index.d.mts +3 -3
  28. package/dist/db/index.mjs +2 -2
  29. package/dist/db/internal.d.mts +3 -0
  30. package/dist/db/internal.mjs +3 -0
  31. package/dist/db/plugin.d.mts +4 -3
  32. package/dist/db/schema/account.d.mts +16 -3
  33. package/dist/db/schema/account.mjs +35 -2
  34. package/dist/db/schema/rate-limit.d.mts +1 -1
  35. package/dist/db/schema/rate-limit.mjs +9 -0
  36. package/dist/db/schema/session.d.mts +1 -1
  37. package/dist/db/schema/shared.d.mts +0 -1
  38. package/dist/db/schema/user.d.mts +1 -1
  39. package/dist/db/schema/verification.d.mts +1 -1
  40. package/dist/db/type.d.mts +17 -9
  41. package/dist/env/logger.d.mts +25 -25
  42. package/dist/error/codes.d.mts +0 -1
  43. package/dist/error/index.d.mts +0 -1
  44. package/dist/index.d.mts +1 -1
  45. package/dist/instrumentation/attributes.d.mts +0 -1
  46. package/dist/instrumentation/pure.index.d.mts +0 -1
  47. package/dist/instrumentation/tracer.mjs +1 -1
  48. package/dist/oauth2/authorization-params.d.mts +0 -1
  49. package/dist/oauth2/client-assertion.d.mts +3 -13
  50. package/dist/oauth2/client-credentials-token.d.mts +3 -17
  51. package/dist/oauth2/client-credentials-token.mjs +1 -4
  52. package/dist/oauth2/create-authorization-url.d.mts +3 -21
  53. package/dist/oauth2/dpop.d.mts +2 -23
  54. package/dist/oauth2/dpop.mjs +1 -1
  55. package/dist/oauth2/index.d.mts +3 -3
  56. package/dist/oauth2/index.mjs +2 -2
  57. package/dist/oauth2/oauth-provider.d.mts +94 -36
  58. package/dist/oauth2/refresh-access-token.d.mts +3 -19
  59. package/dist/oauth2/refresh-access-token.mjs +3 -9
  60. package/dist/oauth2/reject-redirects.mjs +1 -1
  61. package/dist/oauth2/token-endpoint-auth.d.mts +0 -1
  62. package/dist/oauth2/utils.d.mts +0 -1
  63. package/dist/oauth2/utils.mjs +2 -3
  64. package/dist/oauth2/validate-authorization-code.d.mts +5 -29
  65. package/dist/oauth2/verify-id-token.d.mts +3 -2
  66. package/dist/oauth2/verify-id-token.mjs +3 -3
  67. package/dist/oauth2/verify.d.mts +18 -9
  68. package/dist/oauth2/verify.mjs +68 -5
  69. package/dist/social-providers/apple.d.mts +9 -24
  70. package/dist/social-providers/apple.mjs +2 -1
  71. package/dist/social-providers/atlassian.d.mts +18 -19
  72. package/dist/social-providers/atlassian.mjs +1 -1
  73. package/dist/social-providers/cognito.d.mts +33 -22
  74. package/dist/social-providers/cognito.mjs +2 -2
  75. package/dist/social-providers/discord.d.mts +7 -20
  76. package/dist/social-providers/discord.mjs +1 -1
  77. package/dist/social-providers/dropbox.d.mts +7 -22
  78. package/dist/social-providers/dropbox.mjs +1 -1
  79. package/dist/social-providers/facebook.d.mts +19 -27
  80. package/dist/social-providers/facebook.mjs +6 -17
  81. package/dist/social-providers/figma.d.mts +7 -22
  82. package/dist/social-providers/figma.mjs +1 -1
  83. package/dist/social-providers/github.d.mts +7 -23
  84. package/dist/social-providers/github.mjs +1 -1
  85. package/dist/social-providers/gitlab.d.mts +6 -43
  86. package/dist/social-providers/gitlab.mjs +1 -1
  87. package/dist/social-providers/google.d.mts +10 -32
  88. package/dist/social-providers/google.mjs +2 -1
  89. package/dist/social-providers/huggingface.d.mts +7 -22
  90. package/dist/social-providers/huggingface.mjs +1 -1
  91. package/dist/social-providers/index.d.mts +229 -787
  92. package/dist/social-providers/kakao.d.mts +8 -33
  93. package/dist/social-providers/kakao.mjs +1 -1
  94. package/dist/social-providers/kick.d.mts +7 -22
  95. package/dist/social-providers/kick.mjs +1 -1
  96. package/dist/social-providers/line.d.mts +8 -44
  97. package/dist/social-providers/line.mjs +4 -6
  98. package/dist/social-providers/linear.d.mts +7 -21
  99. package/dist/social-providers/linear.mjs +1 -1
  100. package/dist/social-providers/linkedin.d.mts +7 -21
  101. package/dist/social-providers/linkedin.mjs +1 -1
  102. package/dist/social-providers/microsoft-entra-id.d.mts +8 -18
  103. package/dist/social-providers/microsoft-entra-id.mjs +24 -4
  104. package/dist/social-providers/naver.d.mts +27 -42
  105. package/dist/social-providers/naver.mjs +1 -1
  106. package/dist/social-providers/notion.d.mts +7 -21
  107. package/dist/social-providers/notion.mjs +1 -1
  108. package/dist/social-providers/paybin.d.mts +8 -23
  109. package/dist/social-providers/paybin.mjs +2 -1
  110. package/dist/social-providers/paypal.d.mts +8 -33
  111. package/dist/social-providers/paypal.mjs +1 -1
  112. package/dist/social-providers/polar.d.mts +7 -22
  113. package/dist/social-providers/polar.mjs +1 -1
  114. package/dist/social-providers/railway.d.mts +7 -22
  115. package/dist/social-providers/railway.mjs +1 -1
  116. package/dist/social-providers/reddit.d.mts +7 -20
  117. package/dist/social-providers/reddit.mjs +1 -1
  118. package/dist/social-providers/roblox.d.mts +7 -20
  119. package/dist/social-providers/roblox.mjs +1 -1
  120. package/dist/social-providers/salesforce.d.mts +7 -22
  121. package/dist/social-providers/salesforce.mjs +1 -1
  122. package/dist/social-providers/slack.d.mts +7 -20
  123. package/dist/social-providers/slack.mjs +1 -1
  124. package/dist/social-providers/spotify.d.mts +7 -22
  125. package/dist/social-providers/spotify.mjs +1 -1
  126. package/dist/social-providers/tiktok.d.mts +10 -22
  127. package/dist/social-providers/tiktok.mjs +1 -1
  128. package/dist/social-providers/twitch.d.mts +7 -20
  129. package/dist/social-providers/twitch.mjs +1 -1
  130. package/dist/social-providers/twitter.d.mts +29 -26
  131. package/dist/social-providers/twitter.mjs +1 -1
  132. package/dist/social-providers/vercel.d.mts +7 -22
  133. package/dist/social-providers/vercel.mjs +1 -1
  134. package/dist/social-providers/vk.d.mts +8 -24
  135. package/dist/social-providers/vk.mjs +5 -6
  136. package/dist/social-providers/wechat.d.mts +7 -19
  137. package/dist/social-providers/wechat.mjs +1 -1
  138. package/dist/social-providers/zoom.d.mts +9 -25
  139. package/dist/social-providers/zoom.mjs +1 -1
  140. package/dist/types/context.d.mts +16 -9
  141. package/dist/types/cookie.d.mts +0 -1
  142. package/dist/types/helper.d.mts +1 -1
  143. package/dist/types/index.d.mts +1 -1
  144. package/dist/types/init-options.d.mts +37 -26
  145. package/dist/types/plugin-client.d.mts +1 -3
  146. package/dist/types/plugin.d.mts +2 -2
  147. package/dist/utils/async.d.mts +0 -1
  148. package/dist/utils/db.d.mts +1 -0
  149. package/dist/utils/deprecate.d.mts +0 -1
  150. package/dist/utils/error-codes.d.mts +2 -2
  151. package/dist/utils/host.d.mts +27 -1
  152. package/dist/utils/host.mjs +1 -1
  153. package/dist/utils/ip.d.mts +1 -0
  154. package/dist/utils/ip.mjs +1 -1
  155. package/dist/utils/is-api-error.d.mts +0 -1
  156. package/dist/utils/redirect-uri.d.mts +6 -2
  157. package/dist/utils/redirect-uri.mjs +11 -1
  158. package/package.json +10 -2
  159. package/src/context/request-state.ts +26 -6
  160. package/src/context/transaction.ts +37 -18
  161. package/src/db/adapter/factory.ts +34 -28
  162. package/src/db/adapter/get-default-model-name.ts +23 -14
  163. package/src/db/database-index.ts +351 -0
  164. package/src/db/get-tables.ts +89 -9
  165. package/src/db/index.ts +4 -0
  166. package/src/db/internal.ts +12 -0
  167. package/src/db/plugin.ts +3 -1
  168. package/src/db/schema/account.ts +27 -1
  169. package/src/db/schema/user.ts +1 -1
  170. package/src/db/type.ts +12 -0
  171. package/src/error/codes.ts +1 -0
  172. package/src/oauth2/index.ts +5 -0
  173. package/src/oauth2/oauth-provider.ts +105 -36
  174. package/src/oauth2/verify-id-token.ts +4 -2
  175. package/src/oauth2/verify.ts +121 -12
  176. package/src/social-providers/apple.ts +2 -1
  177. package/src/social-providers/atlassian.ts +1 -1
  178. package/src/social-providers/cognito.ts +2 -2
  179. package/src/social-providers/discord.ts +1 -1
  180. package/src/social-providers/dropbox.ts +1 -1
  181. package/src/social-providers/facebook.ts +21 -28
  182. package/src/social-providers/figma.ts +1 -1
  183. package/src/social-providers/github.ts +1 -1
  184. package/src/social-providers/gitlab.ts +1 -1
  185. package/src/social-providers/google.ts +2 -1
  186. package/src/social-providers/huggingface.ts +1 -1
  187. package/src/social-providers/kakao.ts +1 -1
  188. package/src/social-providers/kick.ts +1 -1
  189. package/src/social-providers/line.ts +7 -12
  190. package/src/social-providers/linear.ts +1 -1
  191. package/src/social-providers/linkedin.ts +1 -1
  192. package/src/social-providers/microsoft-entra-id.ts +36 -27
  193. package/src/social-providers/naver.ts +1 -1
  194. package/src/social-providers/notion.ts +1 -1
  195. package/src/social-providers/paybin.ts +2 -1
  196. package/src/social-providers/paypal.ts +1 -1
  197. package/src/social-providers/polar.ts +1 -1
  198. package/src/social-providers/railway.ts +1 -1
  199. package/src/social-providers/reddit.ts +1 -1
  200. package/src/social-providers/roblox.ts +1 -1
  201. package/src/social-providers/salesforce.ts +1 -1
  202. package/src/social-providers/slack.ts +1 -1
  203. package/src/social-providers/spotify.ts +1 -1
  204. package/src/social-providers/tiktok.ts +2 -2
  205. package/src/social-providers/twitch.ts +1 -1
  206. package/src/social-providers/twitter.ts +1 -1
  207. package/src/social-providers/vercel.ts +1 -1
  208. package/src/social-providers/vk.ts +2 -2
  209. package/src/social-providers/wechat.ts +1 -1
  210. package/src/social-providers/zoom.ts +1 -1
  211. package/src/types/context.ts +21 -14
  212. package/src/types/init-options.ts +15 -14
  213. package/src/utils/redirect-uri.ts +20 -0
@@ -1,32 +1,32 @@
1
1
  //#region src/env/logger.d.ts
2
2
  declare const TTY_COLORS: {
3
- readonly reset: "\u001B[0m";
4
- readonly bright: "\u001B[1m";
5
- readonly dim: "\u001B[2m";
6
- readonly undim: "\u001B[22m";
7
- readonly underscore: "\u001B[4m";
8
- readonly blink: "\u001B[5m";
9
- readonly reverse: "\u001B[7m";
10
- readonly hidden: "\u001B[8m";
3
+ readonly reset: "";
4
+ readonly bright: "";
5
+ readonly dim: "";
6
+ readonly undim: "";
7
+ readonly underscore: "";
8
+ readonly blink: "";
9
+ readonly reverse: "";
10
+ readonly hidden: "";
11
11
  readonly fg: {
12
- readonly black: "\u001B[30m";
13
- readonly red: "\u001B[31m";
14
- readonly green: "\u001B[32m";
15
- readonly yellow: "\u001B[33m";
16
- readonly blue: "\u001B[34m";
17
- readonly magenta: "\u001B[35m";
18
- readonly cyan: "\u001B[36m";
19
- readonly white: "\u001B[37m";
12
+ readonly black: "";
13
+ readonly red: "";
14
+ readonly green: "";
15
+ readonly yellow: "";
16
+ readonly blue: "";
17
+ readonly magenta: "";
18
+ readonly cyan: "";
19
+ readonly white: "";
20
20
  };
21
21
  readonly bg: {
22
- readonly black: "\u001B[40m";
23
- readonly red: "\u001B[41m";
24
- readonly green: "\u001B[42m";
25
- readonly yellow: "\u001B[43m";
26
- readonly blue: "\u001B[44m";
27
- readonly magenta: "\u001B[45m";
28
- readonly cyan: "\u001B[46m";
29
- readonly white: "\u001B[47m";
22
+ readonly black: "";
23
+ readonly red: "";
24
+ readonly green: "";
25
+ readonly yellow: "";
26
+ readonly blue: "";
27
+ readonly magenta: "";
28
+ readonly cyan: "";
29
+ readonly white: "";
30
30
  };
31
31
  };
32
32
  type LogLevel = "debug" | "info" | "success" | "warn" | "error";
@@ -39,7 +39,7 @@ interface Logger {
39
39
  log?: ((level: Exclude<LogLevel, "success">, message: string, ...args: any[]) => void) | undefined;
40
40
  }
41
41
  type LogHandlerParams = Parameters<NonNullable<Logger["log"]>> extends [LogLevel, ...infer Rest] ? Rest : never;
42
- type InternalLogger = { [K in LogLevel]: (...params: LogHandlerParams) => void } & {
42
+ type InternalLogger = { [K in LogLevel]: (...params: LogHandlerParams) => void; } & {
43
43
  get level(): LogLevel;
44
44
  };
45
45
  declare const createLogger: (options?: Logger | undefined) => InternalLogger;
@@ -1,5 +1,4 @@
1
1
  import { RawError } from "../utils/error-codes.mjs";
2
-
3
2
  //#region src/error/codes.d.ts
4
3
  declare module "@better-auth/core" {
5
4
  interface BetterAuthPluginRegistry<AuthOptions, Options> {
@@ -1,6 +1,5 @@
1
1
  import { APIErrorCode, BASE_ERROR_CODES } from "./codes.mjs";
2
2
  import { APIError as APIError$1 } from "better-call/error";
3
-
4
3
  //#region src/error/index.d.ts
5
4
  declare class BetterAuthError extends Error {
6
5
  constructor(message: string, options?: {
package/dist/index.d.mts CHANGED
@@ -6,4 +6,4 @@ import { SecretConfig } from "./types/secret.mjs";
6
6
  import { AuthContext, BetterAuthPluginRegistry, BetterAuthPluginRegistryIdentifier, GenericEndpointContext, InfoContext, InternalAdapter, PluginContext } from "./types/context.mjs";
7
7
  import { BetterAuthClientOptions, BetterAuthClientPlugin, ClientAtomListener, ClientFetchOption, ClientStore } from "./types/plugin-client.mjs";
8
8
  import { StandardSchemaV1 } from "./types/index.mjs";
9
- export { AuthContext, Awaitable, AwaitableFunction, BaseURLConfig, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookie, BetterAuthCookies, BetterAuthDBOptions, BetterAuthOptions, BetterAuthPlugin, BetterAuthPluginErrorCodePart, BetterAuthPluginRegistry, BetterAuthPluginRegistryIdentifier, BetterAuthRateLimitOptions, BetterAuthRateLimitRule, BetterAuthRateLimitStorage, ClientAtomListener, ClientFetchOption, ClientStore, DynamicBaseURLConfig, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InfoContext, InternalAdapter, LiteralString, LiteralUnion, PluginContext, Prettify, Primitive, SecretConfig, StandardSchemaV1, StoreIdentifierOption, UnionToIntersection, UserProvisioningSource, ValidateUserInfoAction, ValidateUserInfoMethod, ValidateUserInfoOAuthInfo, ValidateUserInfoResult, ValidateUserInfoSSOInfo, ValidateUserInfoSource };
9
+ export type { AuthContext, Awaitable, AwaitableFunction, BaseURLConfig, BetterAuthAdvancedOptions, BetterAuthClientOptions, BetterAuthClientPlugin, BetterAuthCookie, BetterAuthCookies, BetterAuthDBOptions, BetterAuthOptions, BetterAuthPlugin, BetterAuthPluginErrorCodePart, BetterAuthPluginRegistry, BetterAuthPluginRegistryIdentifier, BetterAuthRateLimitOptions, BetterAuthRateLimitRule, BetterAuthRateLimitStorage, ClientAtomListener, ClientFetchOption, ClientStore, DynamicBaseURLConfig, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InfoContext, InternalAdapter, LiteralString, LiteralUnion, PluginContext, Prettify, Primitive, SecretConfig, StandardSchemaV1, StoreIdentifierOption, UnionToIntersection, UserProvisioningSource, ValidateUserInfoAction, ValidateUserInfoMethod, ValidateUserInfoOAuthInfo, ValidateUserInfoResult, ValidateUserInfoSSOInfo, ValidateUserInfoSource };
@@ -1,5 +1,4 @@
1
1
  import { ATTR_DB_COLLECTION_NAME, ATTR_DB_OPERATION_NAME, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE } from "@opentelemetry/semantic-conventions";
2
-
3
2
  //#region src/instrumentation/attributes.d.ts
4
3
  /** Operation identifier (e.g. getSession, signUpWithEmailAndPassword). Uses endpoint operationId when set, otherwise the endpoint key. */
5
4
  declare const ATTR_OPERATION_ID: "better_auth.operation_id";
@@ -1,5 +1,4 @@
1
1
  import { ATTR_CONTEXT, ATTR_DB_COLLECTION_NAME, ATTR_DB_OPERATION_NAME, ATTR_HOOK_TYPE, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, ATTR_OPERATION_ID } from "./attributes.mjs";
2
-
3
2
  //#region src/instrumentation/pure.index.d.ts
4
3
  declare function withSpan<T>(name: string, attributes: Record<string, string | number | boolean>, fn: () => T): T;
5
4
  declare function withSpan<T>(name: string, attributes: Record<string, string | number | boolean>, fn: () => Promise<T>): Promise<T>;
@@ -2,7 +2,7 @@ import { ATTR_HTTP_RESPONSE_STATUS_CODE } from "./attributes.mjs";
2
2
  import { getOpenTelemetryAPI } from "./api.mjs";
3
3
  //#region src/instrumentation/tracer.ts
4
4
  const INSTRUMENTATION_SCOPE = "better-auth";
5
- const INSTRUMENTATION_VERSION = "1.7.0-rc.1";
5
+ const INSTRUMENTATION_VERSION = "1.7.0-rc.3";
6
6
  /**
7
7
  * Better-auth uses `throw ctx.redirect(url)` for flow control (e.g. OAuth
8
8
  * callbacks). These are APIErrors with 3xx status codes and should not be
@@ -1,5 +1,4 @@
1
1
  import * as z from "zod";
2
-
3
2
  //#region src/oauth2/authorization-params.d.ts
4
3
  /**
5
4
  * Zod schema for the `additionalParams` field on social sign-in and
@@ -1,4 +1,5 @@
1
1
  import { Awaitable } from "../types/helper.mjs";
2
+ import "../types/index.mjs";
2
3
  //#region src/oauth2/client-assertion.d.ts
3
4
  /** Asymmetric signing algorithms compatible with private_key_jwt (RFC 7523). */
4
5
  declare const PRIVATE_KEY_JWT_SIGNING_ALGORITHMS: readonly ["RS256", "RS384", "RS512", "PS256", "PS384", "PS512", "ES256", "ES384", "ES512", "EdDSA"];
@@ -35,15 +36,7 @@ interface PrivateKeyJwtClientAssertionGetterOptions {
35
36
  * - jti=unique
36
37
  * - iat=now
37
38
  */
38
- declare function signPrivateKeyJwtClientAssertion({
39
- clientId,
40
- tokenEndpoint,
41
- privateKeyJwk,
42
- privateKeyPem,
43
- kid,
44
- algorithm,
45
- expiresIn
46
- }: {
39
+ declare function signPrivateKeyJwtClientAssertion({ clientId, tokenEndpoint, privateKeyJwk, privateKeyPem, kid, algorithm, expiresIn }: {
47
40
  clientId: string;
48
41
  tokenEndpoint: string;
49
42
  privateKeyJwk?: JsonWebKey;
@@ -64,10 +57,7 @@ declare function createPrivateKeyJwtClientAssertionGetter(options: PrivateKeyJwt
64
57
  /**
65
58
  * Resolves a client assertion getter into `client_assertion` + `client_assertion_type` params for injection into a token request body.
66
59
  */
67
- declare function resolveClientAssertionParams({
68
- getClientAssertion,
69
- context
70
- }: {
60
+ declare function resolveClientAssertionParams({ getClientAssertion, context }: {
71
61
  getClientAssertion: ClientAssertionGetter;
72
62
  context: ClientAssertionContext;
73
63
  }): Promise<Record<string, string>>;
@@ -1,7 +1,7 @@
1
1
  import { AwaitableFunction } from "../types/helper.mjs";
2
+ import "../types/index.mjs";
2
3
  import { OAuth2Tokens, ProviderOptions } from "./oauth-provider.mjs";
3
4
  import { TokenEndpointAuth, TokenEndpointSecretAuthentication } from "./token-endpoint-auth.mjs";
4
-
5
5
  //#region src/oauth2/client-credentials-token.d.ts
6
6
  interface ClientCredentialsTokenRequestInput {
7
7
  options: AwaitableFunction<ProviderOptions>;
@@ -15,24 +15,10 @@ interface ClientCredentialsTokenInput extends ClientCredentialsTokenRequestInput
15
15
  tokenEndpoint: string;
16
16
  scope: string;
17
17
  }
18
- declare function clientCredentialsTokenRequest({
19
- options,
20
- scope,
21
- authentication,
22
- tokenEndpointAuth,
23
- tokenEndpoint,
24
- resource
25
- }: ClientCredentialsTokenRequestInput): Promise<{
18
+ declare function clientCredentialsTokenRequest({ options, scope, authentication, tokenEndpointAuth, tokenEndpoint, resource }: ClientCredentialsTokenRequestInput): Promise<{
26
19
  body: URLSearchParams;
27
20
  headers: Record<string, string>;
28
21
  }>;
29
- declare function clientCredentialsToken({
30
- options,
31
- tokenEndpoint,
32
- scope,
33
- authentication,
34
- tokenEndpointAuth,
35
- resource
36
- }: ClientCredentialsTokenInput): Promise<OAuth2Tokens>;
22
+ declare function clientCredentialsToken({ options, tokenEndpoint, scope, authentication, tokenEndpointAuth, resource }: ClientCredentialsTokenInput): Promise<OAuth2Tokens>;
37
23
  //#endregion
38
24
  export { clientCredentialsToken, clientCredentialsTokenRequest };
@@ -57,10 +57,7 @@ async function clientCredentialsToken({ options, tokenEndpoint, scope, authentic
57
57
  tokenType: data.token_type,
58
58
  scopes: data.scope?.split(" ")
59
59
  };
60
- if (data.expires_in) {
61
- const now = /* @__PURE__ */ new Date();
62
- tokens.accessTokenExpiresAt = new Date(now.getTime() + data.expires_in * 1e3);
63
- }
60
+ if (data.expires_in) tokens.accessTokenExpiresAt = new Date((/* @__PURE__ */ new Date()).getTime() + data.expires_in * 1e3);
64
61
  return tokens;
65
62
  }
66
63
  //#endregion
@@ -1,5 +1,7 @@
1
1
  import { AwaitableFunction } from "../types/helper.mjs";
2
+ import "../types/index.mjs";
2
3
  import { ProviderOptions } from "./oauth-provider.mjs";
4
+ import "./index.mjs";
3
5
  //#region src/oauth2/create-authorization-url.d.ts
4
6
  /**
5
7
  * Query-parameter names that are populated by the framework as part of the
@@ -9,27 +11,7 @@ import { ProviderOptions } from "./oauth-provider.mjs";
9
11
  */
10
12
  declare const RESERVED_AUTHORIZATION_PARAMS: readonly ["state", "client_id", "redirect_uri", "response_type", "code_challenge", "code_challenge_method", "nonce", "scope"];
11
13
  declare const RESERVED_AUTHORIZATION_PARAMS_SET: ReadonlySet<string>;
12
- declare function createAuthorizationURL({
13
- id,
14
- options,
15
- authorizationEndpoint,
16
- state,
17
- codeVerifier,
18
- scopes,
19
- claims,
20
- redirectURI,
21
- duration,
22
- prompt,
23
- accessType,
24
- responseType,
25
- display,
26
- loginHint,
27
- nonce,
28
- hd,
29
- responseMode,
30
- additionalParams,
31
- scopeJoiner
32
- }: {
14
+ declare function createAuthorizationURL({ id, options, authorizationEndpoint, state, codeVerifier, scopes, claims, redirectURI, duration, prompt, accessType, responseType, display, loginHint, nonce, hd, responseMode, additionalParams, scopeJoiner }: {
33
15
  id: string;
34
16
  options: AwaitableFunction<ProviderOptions>;
35
17
  redirectURI: string;
@@ -1,5 +1,4 @@
1
1
  import { JWK, JWTPayload } from "jose";
2
-
3
2
  //#region src/oauth2/dpop.d.ts
4
3
  declare const DPOP_AUTHORIZATION_SCHEME = "DPoP";
5
4
  declare const BEARER_AUTHORIZATION_SCHEME = "Bearer";
@@ -86,18 +85,7 @@ declare function deriveDpopJkt(jwk: JWK): Promise<string>;
86
85
  */
87
86
  declare function getConfirmationJkt(confirmation: unknown): string | undefined;
88
87
  declare function getDpopJktFromPayload(payload: JWTPayload): string | undefined;
89
- declare function verifyDpopProof({
90
- proofJwt,
91
- method,
92
- url,
93
- accessToken,
94
- expectedJkt,
95
- requireAth,
96
- nowSeconds,
97
- proofMaxAgeSeconds,
98
- signingAlgorithms,
99
- replayStore
100
- }: VerifyDpopProofOptions): Promise<VerifiedDpopProof>;
88
+ declare function verifyDpopProof({ proofJwt, method, url, accessToken, expectedJkt, requireAth, nowSeconds, proofMaxAgeSeconds, signingAlgorithms, replayStore }: VerifyDpopProofOptions): Promise<VerifiedDpopProof>;
101
89
  type DpopBindingErrorCode = "invalid_token" | "invalid_dpop_proof";
102
90
  type DpopBindingError = Error & {
103
91
  code: DpopBindingErrorCode;
@@ -128,15 +116,6 @@ interface EnforceDpopBindingParams {
128
116
  * `invalid_token` / `invalid_dpop_proof` code into their own transport. Returns
129
117
  * normally for a valid bearer token (no `cnf.jkt`, no DPoP scheme).
130
118
  */
131
- declare function enforceDpopBinding({
132
- payload,
133
- authorization,
134
- proofJwt,
135
- method,
136
- url,
137
- replayStore,
138
- proofMaxAgeSeconds,
139
- signingAlgorithms
140
- }: EnforceDpopBindingParams): Promise<void>;
119
+ declare function enforceDpopBinding({ payload, authorization, proofJwt, method, url, replayStore, proofMaxAgeSeconds, signingAlgorithms }: EnforceDpopBindingParams): Promise<void>;
141
120
  //#endregion
142
121
  export { AccessTokenAuthorization, AccessTokenAuthorizationScheme, BEARER_AUTHORIZATION_SCHEME, DPOP_AUTHORIZATION_SCHEME, DPOP_PROOF_TYPE, DPOP_SIGNING_ALGORITHMS, DpopBindingError, DpopBindingErrorCode, DpopProofError, DpopProofErrorCode, DpopReplayReservation, DpopReplayReservations, DpopReplayStore, DpopSigningAlgorithm, EnforceDpopBindingParams, VerifiedDpopProof, VerifyDpopProofOptions, createDpopBindingError, createDpopProofError, createDpopReplayStore, createInMemoryDpopReplayStore, deriveDpopAth, deriveDpopJkt, enforceDpopBinding, getConfirmationJkt, getDpopJktFromPayload, isDpopBindingError, isDpopProofError, normalizeDpopHtu, parseAccessTokenAuthorization, stripAccessTokenAuthorizationScheme, verifyDpopProof };
@@ -12,7 +12,7 @@ const DPOP_SIGNING_ALGORITHMS = [
12
12
  ];
13
13
  const DEFAULT_DPOP_PROOF_MAX_AGE_SECONDS = 300;
14
14
  const MAX_DPOP_JTI_LENGTH = 512;
15
- const JWK_PRIVATE_FIELDS = new Set([
15
+ const JWK_PRIVATE_FIELDS = /* @__PURE__ */ new Set([
16
16
  "d",
17
17
  "p",
18
18
  "q",
@@ -1,7 +1,7 @@
1
1
  import { additionalAuthorizationParamsSchema } from "./authorization-params.mjs";
2
2
  import { decodeBasicCredentials, encodeBasicCredentials } from "./basic-credentials.mjs";
3
3
  import { CLIENT_ASSERTION_TYPE, ClientAssertionContext, ClientAssertionGetter, ClientAssertionGrantType, PRIVATE_KEY_JWT_SIGNING_ALGORITHMS, PrivateKeyJwtClientAssertionGetterOptions, PrivateKeyJwtSigningAlgorithm, createPrivateKeyJwtClientAssertionGetter, resolveClientAssertionParams, signPrivateKeyJwtClientAssertion } from "./client-assertion.mjs";
4
- import { OAuth2Tokens, OAuth2UserInfo, OAuthIdTokenConfig, OAuthProvider, OAuthRefreshContext, ProviderOptions } from "./oauth-provider.mjs";
4
+ import { OAuth2Tokens, OAuth2UserInfo, OAuthAccountKeyContext, OAuthAccountSubject, OAuthIdTokenConfig, OAuthMappedUser, OAuthProvider, OAuthRefreshContext, ProviderOptions } from "./oauth-provider.mjs";
5
5
  import { TokenEndpointAuth, TokenEndpointAuthMethod, TokenEndpointSecretAuthentication } from "./token-endpoint-auth.mjs";
6
6
  import { clientCredentialsToken, clientCredentialsTokenRequest } from "./client-credentials-token.mjs";
7
7
  import { RESERVED_AUTHORIZATION_PARAMS, RESERVED_AUTHORIZATION_PARAMS_SET, createAuthorizationURL } from "./create-authorization-url.mjs";
@@ -9,6 +9,6 @@ import { AccessTokenAuthorization, AccessTokenAuthorizationScheme, BEARER_AUTHOR
9
9
  import { refreshAccessToken, refreshAccessTokenRequest } from "./refresh-access-token.mjs";
10
10
  import { applyDefaultAccessTokenExpiry, generateCodeChallenge, getOAuth2Tokens, getPrimaryClientId, mergeScopes } from "./utils.mjs";
11
11
  import { authorizationCodeRequest, validateAuthorizationCode, validateToken } from "./validate-authorization-code.mjs";
12
- import { ResourceRequestInput, VerifyAccessTokenOptions, VerifyAccessTokenRequestOptions, getJwks, requestToResourceInput, verifyAccessTokenRequest, verifyBearerToken, verifyJwsAccessToken } from "./verify.mjs";
12
+ import { ResourceRequestInput, VerifyAccessTokenOptions, VerifyAccessTokenRequestOptions, createInsufficientScopeError, getJwks, isInsufficientScopeError, requestToResourceInput, verifyAccessTokenRequest, verifyBearerToken, verifyJwsAccessToken } from "./verify.mjs";
13
13
  import { supportsIdTokenSignIn, verifyProviderIdToken } from "./verify-id-token.mjs";
14
- export { type AccessTokenAuthorization, type AccessTokenAuthorizationScheme, BEARER_AUTHORIZATION_SCHEME, CLIENT_ASSERTION_TYPE, type ClientAssertionContext, type ClientAssertionGetter, type ClientAssertionGrantType, DPOP_AUTHORIZATION_SCHEME, DPOP_PROOF_TYPE, DPOP_SIGNING_ALGORITHMS, type DpopBindingError, type DpopBindingErrorCode, type DpopProofError, type DpopProofErrorCode, type DpopReplayReservation, type DpopReplayReservations, type DpopReplayStore, type DpopSigningAlgorithm, type EnforceDpopBindingParams, type OAuth2Tokens, type OAuth2UserInfo, type OAuthIdTokenConfig, type OAuthProvider, type OAuthRefreshContext, PRIVATE_KEY_JWT_SIGNING_ALGORITHMS, type PrivateKeyJwtClientAssertionGetterOptions, type PrivateKeyJwtSigningAlgorithm, type ProviderOptions, RESERVED_AUTHORIZATION_PARAMS, RESERVED_AUTHORIZATION_PARAMS_SET, type ResourceRequestInput, type TokenEndpointAuth, type TokenEndpointAuthMethod, type TokenEndpointSecretAuthentication, type VerifiedDpopProof, type VerifyAccessTokenOptions, type VerifyAccessTokenRequestOptions, type VerifyDpopProofOptions, additionalAuthorizationParamsSchema, applyDefaultAccessTokenExpiry, authorizationCodeRequest, clientCredentialsToken, clientCredentialsTokenRequest, createAuthorizationURL, createDpopBindingError, createDpopProofError, createDpopReplayStore, createInMemoryDpopReplayStore, createPrivateKeyJwtClientAssertionGetter, decodeBasicCredentials, deriveDpopAth, deriveDpopJkt, encodeBasicCredentials, enforceDpopBinding, generateCodeChallenge, getConfirmationJkt, getDpopJktFromPayload, getJwks, getOAuth2Tokens, getPrimaryClientId, isDpopBindingError, isDpopProofError, mergeScopes, normalizeDpopHtu, parseAccessTokenAuthorization, refreshAccessToken, refreshAccessTokenRequest, requestToResourceInput, resolveClientAssertionParams, signPrivateKeyJwtClientAssertion, stripAccessTokenAuthorizationScheme, supportsIdTokenSignIn, validateAuthorizationCode, validateToken, verifyAccessTokenRequest, verifyBearerToken, verifyDpopProof, verifyJwsAccessToken, verifyProviderIdToken };
14
+ export { type AccessTokenAuthorization, type AccessTokenAuthorizationScheme, BEARER_AUTHORIZATION_SCHEME, CLIENT_ASSERTION_TYPE, type ClientAssertionContext, type ClientAssertionGetter, type ClientAssertionGrantType, DPOP_AUTHORIZATION_SCHEME, DPOP_PROOF_TYPE, DPOP_SIGNING_ALGORITHMS, type DpopBindingError, type DpopBindingErrorCode, type DpopProofError, type DpopProofErrorCode, type DpopReplayReservation, type DpopReplayReservations, type DpopReplayStore, type DpopSigningAlgorithm, type EnforceDpopBindingParams, type OAuth2Tokens, type OAuth2UserInfo, type OAuthAccountKeyContext, type OAuthAccountSubject, type OAuthIdTokenConfig, type OAuthMappedUser, type OAuthProvider, type OAuthRefreshContext, PRIVATE_KEY_JWT_SIGNING_ALGORITHMS, type PrivateKeyJwtClientAssertionGetterOptions, type PrivateKeyJwtSigningAlgorithm, type ProviderOptions, RESERVED_AUTHORIZATION_PARAMS, RESERVED_AUTHORIZATION_PARAMS_SET, type ResourceRequestInput, type TokenEndpointAuth, type TokenEndpointAuthMethod, type TokenEndpointSecretAuthentication, type VerifiedDpopProof, type VerifyAccessTokenOptions, type VerifyAccessTokenRequestOptions, type VerifyDpopProofOptions, additionalAuthorizationParamsSchema, applyDefaultAccessTokenExpiry, authorizationCodeRequest, clientCredentialsToken, clientCredentialsTokenRequest, createAuthorizationURL, createDpopBindingError, createDpopProofError, createDpopReplayStore, createInMemoryDpopReplayStore, createInsufficientScopeError, createPrivateKeyJwtClientAssertionGetter, decodeBasicCredentials, deriveDpopAth, deriveDpopJkt, encodeBasicCredentials, enforceDpopBinding, generateCodeChallenge, getConfirmationJkt, getDpopJktFromPayload, getJwks, getOAuth2Tokens, getPrimaryClientId, isDpopBindingError, isDpopProofError, isInsufficientScopeError, mergeScopes, normalizeDpopHtu, parseAccessTokenAuthorization, refreshAccessToken, refreshAccessTokenRequest, requestToResourceInput, resolveClientAssertionParams, signPrivateKeyJwtClientAssertion, stripAccessTokenAuthorizationScheme, supportsIdTokenSignIn, validateAuthorizationCode, validateToken, verifyAccessTokenRequest, verifyBearerToken, verifyDpopProof, verifyJwsAccessToken, verifyProviderIdToken };
@@ -7,6 +7,6 @@ import { clientCredentialsToken, clientCredentialsTokenRequest } from "./client-
7
7
  import { BEARER_AUTHORIZATION_SCHEME, DPOP_AUTHORIZATION_SCHEME, DPOP_PROOF_TYPE, DPOP_SIGNING_ALGORITHMS, createDpopBindingError, createDpopProofError, createDpopReplayStore, createInMemoryDpopReplayStore, deriveDpopAth, deriveDpopJkt, enforceDpopBinding, getConfirmationJkt, getDpopJktFromPayload, isDpopBindingError, isDpopProofError, normalizeDpopHtu, parseAccessTokenAuthorization, stripAccessTokenAuthorizationScheme, verifyDpopProof } from "./dpop.mjs";
8
8
  import { refreshAccessToken, refreshAccessTokenRequest } from "./refresh-access-token.mjs";
9
9
  import { authorizationCodeRequest, validateAuthorizationCode, validateToken } from "./validate-authorization-code.mjs";
10
- import { getJwks, requestToResourceInput, verifyAccessTokenRequest, verifyBearerToken, verifyJwsAccessToken } from "./verify.mjs";
10
+ import { createInsufficientScopeError, getJwks, isInsufficientScopeError, requestToResourceInput, verifyAccessTokenRequest, verifyBearerToken, verifyJwsAccessToken } from "./verify.mjs";
11
11
  import { supportsIdTokenSignIn, verifyProviderIdToken } from "./verify-id-token.mjs";
12
- export { BEARER_AUTHORIZATION_SCHEME, CLIENT_ASSERTION_TYPE, DPOP_AUTHORIZATION_SCHEME, DPOP_PROOF_TYPE, DPOP_SIGNING_ALGORITHMS, PRIVATE_KEY_JWT_SIGNING_ALGORITHMS, RESERVED_AUTHORIZATION_PARAMS, RESERVED_AUTHORIZATION_PARAMS_SET, additionalAuthorizationParamsSchema, applyDefaultAccessTokenExpiry, authorizationCodeRequest, clientCredentialsToken, clientCredentialsTokenRequest, createAuthorizationURL, createDpopBindingError, createDpopProofError, createDpopReplayStore, createInMemoryDpopReplayStore, createPrivateKeyJwtClientAssertionGetter, decodeBasicCredentials, deriveDpopAth, deriveDpopJkt, encodeBasicCredentials, enforceDpopBinding, generateCodeChallenge, getConfirmationJkt, getDpopJktFromPayload, getJwks, getOAuth2Tokens, getPrimaryClientId, isDpopBindingError, isDpopProofError, mergeScopes, normalizeDpopHtu, parseAccessTokenAuthorization, refreshAccessToken, refreshAccessTokenRequest, requestToResourceInput, resolveClientAssertionParams, signPrivateKeyJwtClientAssertion, stripAccessTokenAuthorizationScheme, supportsIdTokenSignIn, validateAuthorizationCode, validateToken, verifyAccessTokenRequest, verifyBearerToken, verifyDpopProof, verifyJwsAccessToken, verifyProviderIdToken };
12
+ export { BEARER_AUTHORIZATION_SCHEME, CLIENT_ASSERTION_TYPE, DPOP_AUTHORIZATION_SCHEME, DPOP_PROOF_TYPE, DPOP_SIGNING_ALGORITHMS, PRIVATE_KEY_JWT_SIGNING_ALGORITHMS, RESERVED_AUTHORIZATION_PARAMS, RESERVED_AUTHORIZATION_PARAMS_SET, additionalAuthorizationParamsSchema, applyDefaultAccessTokenExpiry, authorizationCodeRequest, clientCredentialsToken, clientCredentialsTokenRequest, createAuthorizationURL, createDpopBindingError, createDpopProofError, createDpopReplayStore, createInMemoryDpopReplayStore, createInsufficientScopeError, createPrivateKeyJwtClientAssertionGetter, decodeBasicCredentials, deriveDpopAth, deriveDpopJkt, encodeBasicCredentials, enforceDpopBinding, generateCodeChallenge, getConfirmationJkt, getDpopJktFromPayload, getJwks, getOAuth2Tokens, getPrimaryClientId, isDpopBindingError, isDpopProofError, isInsufficientScopeError, mergeScopes, normalizeDpopHtu, parseAccessTokenAuthorization, refreshAccessToken, refreshAccessTokenRequest, requestToResourceInput, resolveClientAssertionParams, signPrivateKeyJwtClientAssertion, stripAccessTokenAuthorizationScheme, supportsIdTokenSignIn, validateAuthorizationCode, validateToken, verifyAccessTokenRequest, verifyBearerToken, verifyDpopProof, verifyJwsAccessToken, verifyProviderIdToken };
@@ -1,6 +1,7 @@
1
1
  import { Awaitable, LiteralString } from "../types/helper.mjs";
2
+ import { GenericEndpointContext } from "../types/context.mjs";
3
+ import "../types/index.mjs";
2
4
  import { JWTVerifyGetKey } from "jose";
3
-
4
5
  //#region src/oauth2/oauth-provider.d.ts
5
6
  /**
6
7
  * id_token verification config for a social provider.
@@ -16,10 +17,14 @@ type OAuthIdTokenConfig = {
16
17
  * `createRemoteJWKSet` resolver or a key-resolving function
17
18
  * `(protectedHeader) => key`.
18
19
  */
19
- jwks: JWTVerifyGetKey; /** Expected `iss`. Omit for providers whose issuer varies per tenant. */
20
- issuer?: (string | string[]) | undefined; /** Expected `aud`, usually the client ID. */
21
- audience: string | string[]; /** Permitted JWS algorithms. Defaults to the token's `alg` header. */
22
- algorithms?: string[] | undefined; /** Maximum token age passed to jose (e.g. `"1h"`). */
20
+ jwks: JWTVerifyGetKey;
21
+ /** Expected `iss`. Omit for providers whose issuer varies per tenant. */
22
+ issuer?: (string | string[]) | undefined;
23
+ /** Expected `aud`, usually the client ID. */
24
+ audience: string | string[];
25
+ /** Permitted JWS algorithms. Defaults to the token's `alg` header. */
26
+ algorithms?: string[] | undefined;
27
+ /** Maximum token age passed to jose (e.g. `"1h"`). */
23
28
  maxTokenAge?: string | undefined;
24
29
  /**
25
30
  * How the `nonce` claim is compared to the expected nonce.
@@ -46,7 +51,7 @@ type OAuthIdTokenConfig = {
46
51
  * Custom verifier for providers that cannot verify against a local JWKS, such as a
47
52
  * remote verification endpoint (e.g. LINE).
48
53
  */
49
- verify: (token: string, nonce?: string) => Promise<boolean>;
54
+ verify: (token: string, nonce?: string, ctx?: GenericEndpointContext) => Promise<boolean>;
50
55
  };
51
56
  interface OAuth2Tokens {
52
57
  tokenType?: string | undefined;
@@ -62,13 +67,46 @@ interface OAuth2Tokens {
62
67
  */
63
68
  raw?: Record<string, unknown> | undefined;
64
69
  }
70
+ /** Mutable local-user attributes normalized from an OAuth provider profile. */
65
71
  type OAuth2UserInfo = {
66
- id: string | number;
72
+ /** Provider identity belongs in raw profile data and `accountSubject`. */
73
+ id?: never;
67
74
  name?: string | undefined;
68
75
  email?: (string | null) | undefined;
69
76
  image?: string | undefined;
70
77
  emailVerified: boolean;
71
78
  };
79
+ /**
80
+ * Verified provider data available when deriving a stable OAuth account key.
81
+ *
82
+ * Account-key resolvers must use the raw provider profile or verified token
83
+ * response. They never receive the mapped local user, so profile mapping
84
+ * cannot redefine provider identity.
85
+ */
86
+ interface OAuthAccountKeyContext<Profile extends object = object> {
87
+ tokens: OAuth2Tokens;
88
+ profile: Profile;
89
+ }
90
+ /**
91
+ * Resolves one part of an account key from a profile returned by the same
92
+ * provider. The method-derived callback keeps that profile pairing intact when
93
+ * providers with different profile shapes share an `OAuthProvider[]`.
94
+ */
95
+ type OAuthAccountKeyResolver<Profile extends object, Value> = {
96
+ resolve(context: OAuthAccountKeyContext<Profile>): Awaitable<Value>;
97
+ }["resolve"];
98
+ /** Resolves the stable provider subject used to build an OAuth account key. */
99
+ type OAuthAccountSubject<Profile extends object = object> = OAuthAccountKeyResolver<Profile, string | number>;
100
+ /** Mutable local-user attributes returned by `mapProfileToUser`. */
101
+ type OAuthMappedUser = {
102
+ /** Provider identity is defined by `accountSubject`, not local user mapping. */
103
+ id?: never;
104
+ name?: string;
105
+ email?: string | null;
106
+ image?: string;
107
+ emailVerified?: boolean;
108
+ [key: string]: unknown;
109
+ };
72
110
  /**
73
111
  * Request metadata available to provider refresh hooks.
74
112
  *
@@ -80,7 +118,7 @@ interface OAuthRefreshContext {
80
118
  headers?: Headers | undefined;
81
119
  request?: Request | undefined;
82
120
  }
83
- interface OAuthProvider<T extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Partial<ProviderOptions>> {
121
+ interface OAuthProvider<T extends object = object, O extends object = Partial<ProviderOptions>> {
84
122
  id: LiteralString;
85
123
  /**
86
124
  * Optional path under the resolved per-request `baseURL` where this
@@ -115,6 +153,15 @@ interface OAuthProvider<T extends Record<string, any> = Record<string, any>, O e
115
153
  additionalParams?: Record<string, string> | undefined;
116
154
  }) => Awaitable<URL>;
117
155
  name: string;
156
+ /**
157
+ * Stable subject that identifies the provider account.
158
+ *
159
+ * Read this value from the raw, provider-verified profile. For OpenID
160
+ * Connect providers, use the `sub` claim. For OAuth providers, use the
161
+ * provider's documented immutable user identifier. Never derive this value
162
+ * from `mapProfileToUser`.
163
+ */
164
+ accountSubject: OAuthAccountSubject<T>;
118
165
  validateAuthorizationCode: (data: {
119
166
  code: string;
120
167
  redirectURI: string;
@@ -152,6 +199,15 @@ interface OAuthProvider<T extends Record<string, any> = Record<string, any>, O e
152
199
  */
153
200
  refreshAccessToken?: ((refreshToken: string, ctx?: OAuthRefreshContext) => Promise<OAuth2Tokens>) | undefined;
154
201
  revokeToken?: ((token: string) => Promise<void>) | undefined;
202
+ /**
203
+ * Builds an OpenID Connect RP-Initiated Logout URL for this provider.
204
+ * Returns `null` when provider logout is unavailable or disabled.
205
+ */
206
+ createEndSessionURL?: ((data: {
207
+ idToken?: string | null | undefined;
208
+ postLogoutRedirectURI?: string | undefined;
209
+ state?: string | undefined;
210
+ }) => Awaitable<URL | null>) | undefined;
155
211
  /**
156
212
  * Declarative id_token verification config consumed by the shared
157
213
  * `verifyProviderIdToken` verifier. Providers set this instead of implementing a boolean
@@ -164,6 +220,16 @@ interface OAuthProvider<T extends Record<string, any> = Record<string, any>, O e
164
220
  * against this value to prevent authorization server mix-up attacks.
165
221
  */
166
222
  issuer?: string | undefined;
223
+ /**
224
+ * Stable issuer used with the provider subject to recognize an account.
225
+ *
226
+ * Use the validated OpenID Connect issuer for OIDC providers. A resolver is
227
+ * supported for tenant-specific issuers and receives only provider-verified
228
+ * data. OAuth providers without an issuer omit this property and are scoped
229
+ * to the synthetic `local:oauth:<encoded providerId>` issuer, where the
230
+ * provider ID segment is percent-encoded.
231
+ */
232
+ accountIssuer?: string | OAuthAccountKeyResolver<T, string> | undefined;
167
233
  /**
168
234
  * Require shared OAuth redirect routes to bind ID-token verification to an
169
235
  * authorization request nonce. When true, routes generate `idTokenNonce`,
@@ -196,7 +262,14 @@ interface OAuthProvider<T extends Record<string, any> = Record<string, any>, O e
196
262
  */
197
263
  options?: O | undefined;
198
264
  }
199
- type ProviderOptions<Profile extends Record<string, any> = any> = {
265
+ /**
266
+ * Maps a provider-specific profile while remaining compatible with the erased
267
+ * profile type used by shared OAuth helpers.
268
+ */
269
+ type OAuthProfileMapper<Profile extends object> = {
270
+ map(profile: Profile): Awaitable<OAuthMappedUser>;
271
+ }["map"];
272
+ type ProviderOptions<Profile extends object = object> = {
200
273
  /**
201
274
  * The client ID of your application.
202
275
  *
@@ -240,22 +313,21 @@ type ProviderOptions<Profile extends Record<string, any> = any> = {
240
313
  */
241
314
  disableIdTokenSignIn?: boolean | undefined;
242
315
  /**
243
- * verifyIdToken function to verify the id token
316
+ * verifyIdToken function to verify the id token.
317
+ *
318
+ * The optional endpoint context exposes request metadata to custom
319
+ * verifiers without coupling built-in provider verification to a runtime.
244
320
  */
245
- verifyIdToken?: ((token: string, nonce?: string) => Promise<boolean>) | undefined;
321
+ verifyIdToken?: ((token: string, nonce?: string, ctx?: GenericEndpointContext) => Promise<boolean>) | undefined;
246
322
  /**
247
323
  * Custom function to get user info from the provider
324
+ *
325
+ * `data` must preserve the declared raw profile shape because account-key
326
+ * resolvers consume it after this hook returns.
248
327
  */
249
328
  getUserInfo?: ((token: OAuth2Tokens) => Promise<{
250
- user: {
251
- id: string;
252
- name?: string;
253
- email?: string | null;
254
- image?: string;
255
- emailVerified: boolean;
256
- [key: string]: any;
257
- };
258
- data: any;
329
+ user: OAuth2UserInfo & Record<string, unknown>;
330
+ data: Profile;
259
331
  } | null>) | undefined;
260
332
  /**
261
333
  * Custom function to refresh a token
@@ -265,21 +337,7 @@ type ProviderOptions<Profile extends Record<string, any> = any> = {
265
337
  * Custom function to map the provider profile to a
266
338
  * user.
267
339
  */
268
- mapProfileToUser?: ((profile: Profile) => {
269
- id?: string;
270
- name?: string;
271
- email?: string | null;
272
- image?: string;
273
- emailVerified?: boolean;
274
- [key: string]: any;
275
- } | Promise<{
276
- id?: string;
277
- name?: string;
278
- email?: string | null;
279
- image?: string;
280
- emailVerified?: boolean;
281
- [key: string]: any;
282
- }>) | undefined;
340
+ mapProfileToUser?: OAuthProfileMapper<Profile> | undefined;
283
341
  /**
284
342
  * Disable implicit sign up for new users. When set to true for the provider,
285
343
  * sign-in need to be called with with requestSignUp as true to create new users.
@@ -329,4 +387,4 @@ type ProviderOptions<Profile extends Record<string, any> = any> = {
329
387
  requireEmailVerification?: boolean | undefined;
330
388
  };
331
389
  //#endregion
332
- export { OAuth2Tokens, OAuth2UserInfo, OAuthIdTokenConfig, OAuthProvider, OAuthRefreshContext, ProviderOptions };
390
+ export { OAuth2Tokens, OAuth2UserInfo, OAuthAccountKeyContext, OAuthAccountSubject, OAuthIdTokenConfig, OAuthMappedUser, OAuthProvider, OAuthRefreshContext, ProviderOptions };
@@ -1,7 +1,7 @@
1
1
  import { AwaitableFunction } from "../types/helper.mjs";
2
+ import "../types/index.mjs";
2
3
  import { OAuth2Tokens, ProviderOptions } from "./oauth-provider.mjs";
3
4
  import { TokenEndpointAuth, TokenEndpointSecretAuthentication } from "./token-endpoint-auth.mjs";
4
-
5
5
  //#region src/oauth2/refresh-access-token.d.ts
6
6
  interface RefreshAccessTokenRequestInput {
7
7
  refreshToken: string;
@@ -16,26 +16,10 @@ interface RefreshAccessTokenInput extends RefreshAccessTokenRequestInput {
16
16
  options: Partial<ProviderOptions>;
17
17
  tokenEndpoint: string;
18
18
  }
19
- declare function refreshAccessTokenRequest({
20
- refreshToken,
21
- options,
22
- authentication,
23
- tokenEndpointAuth,
24
- tokenEndpoint,
25
- extraParams,
26
- resource
27
- }: RefreshAccessTokenRequestInput): Promise<{
19
+ declare function refreshAccessTokenRequest({ refreshToken, options, authentication, tokenEndpointAuth, tokenEndpoint, extraParams, resource }: RefreshAccessTokenRequestInput): Promise<{
28
20
  body: URLSearchParams;
29
21
  headers: Record<string, string>;
30
22
  }>;
31
- declare function refreshAccessToken({
32
- refreshToken,
33
- options,
34
- tokenEndpoint,
35
- authentication,
36
- tokenEndpointAuth,
37
- extraParams,
38
- resource
39
- }: RefreshAccessTokenInput): Promise<OAuth2Tokens>;
23
+ declare function refreshAccessToken({ refreshToken, options, tokenEndpoint, authentication, tokenEndpointAuth, extraParams, resource }: RefreshAccessTokenInput): Promise<OAuth2Tokens>;
40
24
  //#endregion
41
25
  export { refreshAccessToken, refreshAccessTokenRequest };
@@ -2,7 +2,7 @@ import { parseScopeField } from "./utils.mjs";
2
2
  import { fetchRefusingRedirects } from "./reject-redirects.mjs";
3
3
  import { applyTokenEndpointAuth } from "./token-endpoint-auth.mjs";
4
4
  //#region src/oauth2/refresh-access-token.ts
5
- const BLOCKED_REFRESH_TOKEN_PARAMS_SET = new Set([
5
+ const BLOCKED_REFRESH_TOKEN_PARAMS_SET = /* @__PURE__ */ new Set([
6
6
  "grant_type",
7
7
  "refresh_token",
8
8
  "__proto__",
@@ -74,14 +74,8 @@ async function refreshAccessToken({ refreshToken, options, tokenEndpoint, authen
74
74
  scopes: parseScopeField(data.scope),
75
75
  idToken: data.id_token
76
76
  };
77
- if (data.expires_in) {
78
- const now = /* @__PURE__ */ new Date();
79
- tokens.accessTokenExpiresAt = new Date(now.getTime() + data.expires_in * 1e3);
80
- }
81
- if (data.refresh_token_expires_in) {
82
- const now = /* @__PURE__ */ new Date();
83
- tokens.refreshTokenExpiresAt = new Date(now.getTime() + data.refresh_token_expires_in * 1e3);
84
- }
77
+ if (data.expires_in) tokens.accessTokenExpiresAt = new Date((/* @__PURE__ */ new Date()).getTime() + data.expires_in * 1e3);
78
+ if (data.refresh_token_expires_in) tokens.refreshTokenExpiresAt = new Date((/* @__PURE__ */ new Date()).getTime() + data.refresh_token_expires_in * 1e3);
85
79
  return tokens;
86
80
  }
87
81
  //#endregion
@@ -1,7 +1,7 @@
1
1
  import { BetterAuthError } from "../error/index.mjs";
2
2
  import { betterFetch } from "@better-fetch/fetch";
3
3
  //#region src/oauth2/reject-redirects.ts
4
- const httpRedirectStatuses = new Set([
4
+ const httpRedirectStatuses = /* @__PURE__ */ new Set([
5
5
  301,
6
6
  302,
7
7
  303,
@@ -1,5 +1,4 @@
1
1
  import { ClientAssertionGetter } from "./client-assertion.mjs";
2
-
3
2
  //#region src/oauth2/token-endpoint-auth.d.ts
4
3
  type TokenEndpointAuth = {
5
4
  method: "none";
@@ -1,5 +1,4 @@
1
1
  import { OAuth2Tokens } from "./oauth-provider.mjs";
2
-
3
2
  //#region src/oauth2/utils.d.ts
4
3
  declare function getOAuth2Tokens(data: Record<string, any>): OAuth2Tokens;
5
4
  /**