@better-auth/core 1.7.0-rc.0 → 1.7.0-rc.2
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.
- package/dist/api/index.d.mts +28 -28
- package/dist/async_hooks/index.d.mts +0 -1
- package/dist/async_hooks/pure.index.d.mts +0 -1
- package/dist/context/endpoint-context.d.mts +1 -1
- package/dist/context/global.d.mts +0 -1
- package/dist/context/global.mjs +1 -1
- package/dist/context/request-state.d.mts +0 -1
- package/dist/context/request-state.mjs +8 -5
- package/dist/context/transaction.d.mts +8 -3
- package/dist/context/transaction.mjs +27 -10
- package/dist/db/adapter/factory.d.mts +3 -5
- package/dist/db/adapter/factory.mjs +7 -5
- package/dist/db/adapter/get-default-field-name.d.mts +2 -9
- package/dist/db/adapter/get-default-model-name.d.mts +1 -5
- package/dist/db/adapter/get-default-model-name.mjs +6 -5
- package/dist/db/adapter/get-field-attributes.d.mts +4 -11
- package/dist/db/adapter/get-field-name.d.mts +2 -9
- package/dist/db/adapter/get-id-field.d.mts +4 -12
- package/dist/db/adapter/get-model-name.d.mts +1 -5
- package/dist/db/adapter/index.d.mts +7 -32
- package/dist/db/adapter/types.d.mts +5 -17
- package/dist/db/adapter/utils.d.mts +0 -1
- package/dist/db/database-index.d.mts +44 -0
- package/dist/db/database-index.mjs +168 -0
- package/dist/db/get-tables.d.mts +7 -1
- package/dist/db/get-tables.mjs +47 -6
- package/dist/db/index.d.mts +3 -3
- package/dist/db/index.mjs +2 -2
- package/dist/db/internal.d.mts +3 -0
- package/dist/db/internal.mjs +3 -0
- package/dist/db/plugin.d.mts +4 -3
- package/dist/db/schema/account.d.mts +16 -3
- package/dist/db/schema/account.mjs +35 -2
- package/dist/db/schema/rate-limit.d.mts +1 -1
- package/dist/db/schema/rate-limit.mjs +9 -0
- package/dist/db/schema/session.d.mts +1 -1
- package/dist/db/schema/shared.d.mts +0 -1
- package/dist/db/schema/user.d.mts +1 -1
- package/dist/db/schema/verification.d.mts +1 -1
- package/dist/db/type.d.mts +17 -9
- package/dist/env/logger.d.mts +25 -25
- package/dist/error/codes.d.mts +0 -1
- package/dist/error/index.d.mts +0 -1
- package/dist/index.d.mts +1 -1
- package/dist/instrumentation/attributes.d.mts +0 -1
- package/dist/instrumentation/pure.index.d.mts +0 -1
- package/dist/instrumentation/tracer.mjs +1 -1
- package/dist/oauth2/authorization-params.d.mts +0 -1
- package/dist/oauth2/client-assertion.d.mts +3 -13
- package/dist/oauth2/client-credentials-token.d.mts +3 -17
- package/dist/oauth2/client-credentials-token.mjs +1 -4
- package/dist/oauth2/create-authorization-url.d.mts +3 -21
- package/dist/oauth2/dpop.d.mts +2 -23
- package/dist/oauth2/dpop.mjs +1 -1
- package/dist/oauth2/index.d.mts +2 -2
- package/dist/oauth2/oauth-provider.d.mts +85 -36
- package/dist/oauth2/refresh-access-token.d.mts +3 -19
- package/dist/oauth2/refresh-access-token.mjs +3 -9
- package/dist/oauth2/reject-redirects.mjs +1 -1
- package/dist/oauth2/token-endpoint-auth.d.mts +0 -1
- package/dist/oauth2/utils.d.mts +0 -1
- package/dist/oauth2/utils.mjs +2 -3
- package/dist/oauth2/validate-authorization-code.d.mts +5 -29
- package/dist/oauth2/verify-id-token.d.mts +3 -2
- package/dist/oauth2/verify-id-token.mjs +3 -3
- package/dist/oauth2/verify.d.mts +5 -7
- package/dist/oauth2/verify.mjs +2 -2
- package/dist/social-providers/apple.d.mts +9 -24
- package/dist/social-providers/apple.mjs +2 -1
- package/dist/social-providers/atlassian.d.mts +18 -19
- package/dist/social-providers/atlassian.mjs +1 -1
- package/dist/social-providers/cognito.d.mts +33 -22
- package/dist/social-providers/cognito.mjs +2 -2
- package/dist/social-providers/discord.d.mts +7 -20
- package/dist/social-providers/discord.mjs +1 -1
- package/dist/social-providers/dropbox.d.mts +7 -22
- package/dist/social-providers/dropbox.mjs +1 -1
- package/dist/social-providers/facebook.d.mts +19 -27
- package/dist/social-providers/facebook.mjs +6 -17
- package/dist/social-providers/figma.d.mts +7 -22
- package/dist/social-providers/figma.mjs +1 -1
- package/dist/social-providers/github.d.mts +7 -23
- package/dist/social-providers/github.mjs +1 -1
- package/dist/social-providers/gitlab.d.mts +6 -43
- package/dist/social-providers/gitlab.mjs +1 -1
- package/dist/social-providers/google.d.mts +10 -32
- package/dist/social-providers/google.mjs +2 -1
- package/dist/social-providers/huggingface.d.mts +7 -22
- package/dist/social-providers/huggingface.mjs +1 -1
- package/dist/social-providers/index.d.mts +229 -787
- package/dist/social-providers/kakao.d.mts +8 -33
- package/dist/social-providers/kakao.mjs +1 -1
- package/dist/social-providers/kick.d.mts +7 -22
- package/dist/social-providers/kick.mjs +1 -1
- package/dist/social-providers/line.d.mts +8 -44
- package/dist/social-providers/line.mjs +4 -6
- package/dist/social-providers/linear.d.mts +7 -21
- package/dist/social-providers/linear.mjs +1 -1
- package/dist/social-providers/linkedin.d.mts +7 -21
- package/dist/social-providers/linkedin.mjs +1 -1
- package/dist/social-providers/microsoft-entra-id.d.mts +8 -18
- package/dist/social-providers/microsoft-entra-id.mjs +18 -2
- package/dist/social-providers/naver.d.mts +27 -42
- package/dist/social-providers/naver.mjs +1 -1
- package/dist/social-providers/notion.d.mts +7 -21
- package/dist/social-providers/notion.mjs +1 -1
- package/dist/social-providers/paybin.d.mts +8 -23
- package/dist/social-providers/paybin.mjs +2 -1
- package/dist/social-providers/paypal.d.mts +8 -33
- package/dist/social-providers/paypal.mjs +1 -1
- package/dist/social-providers/polar.d.mts +7 -22
- package/dist/social-providers/polar.mjs +1 -1
- package/dist/social-providers/railway.d.mts +7 -22
- package/dist/social-providers/railway.mjs +1 -1
- package/dist/social-providers/reddit.d.mts +7 -20
- package/dist/social-providers/reddit.mjs +1 -1
- package/dist/social-providers/roblox.d.mts +7 -20
- package/dist/social-providers/roblox.mjs +1 -1
- package/dist/social-providers/salesforce.d.mts +7 -22
- package/dist/social-providers/salesforce.mjs +1 -1
- package/dist/social-providers/slack.d.mts +7 -20
- package/dist/social-providers/slack.mjs +1 -1
- package/dist/social-providers/spotify.d.mts +7 -22
- package/dist/social-providers/spotify.mjs +1 -1
- package/dist/social-providers/tiktok.d.mts +10 -22
- package/dist/social-providers/tiktok.mjs +1 -1
- package/dist/social-providers/twitch.d.mts +7 -20
- package/dist/social-providers/twitch.mjs +1 -1
- package/dist/social-providers/twitter.d.mts +29 -26
- package/dist/social-providers/twitter.mjs +1 -1
- package/dist/social-providers/vercel.d.mts +7 -22
- package/dist/social-providers/vercel.mjs +1 -1
- package/dist/social-providers/vk.d.mts +8 -24
- package/dist/social-providers/vk.mjs +5 -6
- package/dist/social-providers/wechat.d.mts +7 -19
- package/dist/social-providers/wechat.mjs +1 -1
- package/dist/social-providers/zoom.d.mts +9 -25
- package/dist/social-providers/zoom.mjs +1 -1
- package/dist/types/context.d.mts +16 -9
- package/dist/types/cookie.d.mts +0 -1
- package/dist/types/helper.d.mts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/init-options.d.mts +37 -26
- package/dist/types/plugin-client.d.mts +1 -3
- package/dist/types/plugin.d.mts +2 -2
- package/dist/utils/async.d.mts +0 -1
- package/dist/utils/db.d.mts +1 -0
- package/dist/utils/deprecate.d.mts +0 -1
- package/dist/utils/error-codes.d.mts +2 -2
- package/dist/utils/host.d.mts +27 -1
- package/dist/utils/host.mjs +1 -1
- package/dist/utils/ip.d.mts +1 -0
- package/dist/utils/ip.mjs +1 -1
- package/dist/utils/is-api-error.d.mts +0 -1
- package/dist/utils/redirect-uri.d.mts +0 -1
- package/package.json +10 -2
- package/src/context/request-state.ts +26 -6
- package/src/context/transaction.ts +37 -18
- package/src/db/adapter/factory.ts +24 -18
- package/src/db/adapter/get-default-model-name.ts +23 -14
- package/src/db/database-index.ts +351 -0
- package/src/db/get-tables.ts +89 -9
- package/src/db/index.ts +4 -0
- package/src/db/internal.ts +12 -0
- package/src/db/plugin.ts +3 -1
- package/src/db/schema/account.ts +27 -1
- package/src/db/schema/user.ts +1 -1
- package/src/db/type.ts +12 -0
- package/src/oauth2/index.ts +3 -0
- package/src/oauth2/oauth-provider.ts +94 -36
- package/src/oauth2/verify-id-token.ts +4 -2
- package/src/social-providers/apple.ts +2 -1
- package/src/social-providers/atlassian.ts +1 -1
- package/src/social-providers/cognito.ts +2 -2
- package/src/social-providers/discord.ts +1 -1
- package/src/social-providers/dropbox.ts +1 -1
- package/src/social-providers/facebook.ts +21 -28
- package/src/social-providers/figma.ts +1 -1
- package/src/social-providers/github.ts +1 -1
- package/src/social-providers/gitlab.ts +1 -1
- package/src/social-providers/google.ts +2 -1
- package/src/social-providers/huggingface.ts +1 -1
- package/src/social-providers/kakao.ts +1 -1
- package/src/social-providers/kick.ts +1 -1
- package/src/social-providers/line.ts +7 -12
- package/src/social-providers/linear.ts +1 -1
- package/src/social-providers/linkedin.ts +1 -1
- package/src/social-providers/microsoft-entra-id.ts +3 -2
- package/src/social-providers/naver.ts +1 -1
- package/src/social-providers/notion.ts +1 -1
- package/src/social-providers/paybin.ts +2 -1
- package/src/social-providers/paypal.ts +1 -1
- package/src/social-providers/polar.ts +1 -1
- package/src/social-providers/railway.ts +1 -1
- package/src/social-providers/reddit.ts +1 -1
- package/src/social-providers/roblox.ts +1 -1
- package/src/social-providers/salesforce.ts +1 -1
- package/src/social-providers/slack.ts +1 -1
- package/src/social-providers/spotify.ts +1 -1
- package/src/social-providers/tiktok.ts +2 -2
- package/src/social-providers/twitch.ts +1 -1
- package/src/social-providers/twitter.ts +1 -1
- package/src/social-providers/vercel.ts +1 -1
- package/src/social-providers/vk.ts +2 -2
- package/src/social-providers/wechat.ts +1 -1
- package/src/social-providers/zoom.ts +1 -1
- package/src/types/context.ts +21 -14
- package/src/types/init-options.ts +15 -14
package/dist/env/logger.d.mts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
//#region src/env/logger.d.ts
|
|
2
2
|
declare const TTY_COLORS: {
|
|
3
|
-
readonly reset: "
|
|
4
|
-
readonly bright: "
|
|
5
|
-
readonly dim: "
|
|
6
|
-
readonly undim: "
|
|
7
|
-
readonly underscore: "
|
|
8
|
-
readonly blink: "
|
|
9
|
-
readonly reverse: "
|
|
10
|
-
readonly hidden: "
|
|
3
|
+
readonly reset: "[0m";
|
|
4
|
+
readonly bright: "[1m";
|
|
5
|
+
readonly dim: "[2m";
|
|
6
|
+
readonly undim: "[22m";
|
|
7
|
+
readonly underscore: "[4m";
|
|
8
|
+
readonly blink: "[5m";
|
|
9
|
+
readonly reverse: "[7m";
|
|
10
|
+
readonly hidden: "[8m";
|
|
11
11
|
readonly fg: {
|
|
12
|
-
readonly black: "
|
|
13
|
-
readonly red: "
|
|
14
|
-
readonly green: "
|
|
15
|
-
readonly yellow: "
|
|
16
|
-
readonly blue: "
|
|
17
|
-
readonly magenta: "
|
|
18
|
-
readonly cyan: "
|
|
19
|
-
readonly white: "
|
|
12
|
+
readonly black: "[30m";
|
|
13
|
+
readonly red: "[31m";
|
|
14
|
+
readonly green: "[32m";
|
|
15
|
+
readonly yellow: "[33m";
|
|
16
|
+
readonly blue: "[34m";
|
|
17
|
+
readonly magenta: "[35m";
|
|
18
|
+
readonly cyan: "[36m";
|
|
19
|
+
readonly white: "[37m";
|
|
20
20
|
};
|
|
21
21
|
readonly bg: {
|
|
22
|
-
readonly black: "
|
|
23
|
-
readonly red: "
|
|
24
|
-
readonly green: "
|
|
25
|
-
readonly yellow: "
|
|
26
|
-
readonly blue: "
|
|
27
|
-
readonly magenta: "
|
|
28
|
-
readonly cyan: "
|
|
29
|
-
readonly white: "
|
|
22
|
+
readonly black: "[40m";
|
|
23
|
+
readonly red: "[41m";
|
|
24
|
+
readonly green: "[42m";
|
|
25
|
+
readonly yellow: "[43m";
|
|
26
|
+
readonly blue: "[44m";
|
|
27
|
+
readonly magenta: "[45m";
|
|
28
|
+
readonly cyan: "[46m";
|
|
29
|
+
readonly white: "[47m";
|
|
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;
|
package/dist/error/codes.d.mts
CHANGED
package/dist/error/index.d.mts
CHANGED
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.
|
|
5
|
+
const INSTRUMENTATION_VERSION = "1.7.0-rc.2";
|
|
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,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;
|
package/dist/oauth2/dpop.d.mts
CHANGED
|
@@ -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 };
|
package/dist/oauth2/dpop.mjs
CHANGED
package/dist/oauth2/index.d.mts
CHANGED
|
@@ -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";
|
|
@@ -11,4 +11,4 @@ import { applyDefaultAccessTokenExpiry, generateCodeChallenge, getOAuth2Tokens,
|
|
|
11
11
|
import { authorizationCodeRequest, validateAuthorizationCode, validateToken } from "./validate-authorization-code.mjs";
|
|
12
12
|
import { ResourceRequestInput, VerifyAccessTokenOptions, VerifyAccessTokenRequestOptions, getJwks, 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, 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 };
|
|
@@ -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;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
|
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;
|
|
@@ -164,6 +211,16 @@ interface OAuthProvider<T extends Record<string, any> = Record<string, any>, O e
|
|
|
164
211
|
* against this value to prevent authorization server mix-up attacks.
|
|
165
212
|
*/
|
|
166
213
|
issuer?: string | undefined;
|
|
214
|
+
/**
|
|
215
|
+
* Stable issuer used with the provider subject to recognize an account.
|
|
216
|
+
*
|
|
217
|
+
* Use the validated OpenID Connect issuer for OIDC providers. A resolver is
|
|
218
|
+
* supported for tenant-specific issuers and receives only provider-verified
|
|
219
|
+
* data. OAuth providers without an issuer omit this property and are scoped
|
|
220
|
+
* to the synthetic `local:oauth:<encoded providerId>` issuer, where the
|
|
221
|
+
* provider ID segment is percent-encoded.
|
|
222
|
+
*/
|
|
223
|
+
accountIssuer?: string | OAuthAccountKeyResolver<T, string> | undefined;
|
|
167
224
|
/**
|
|
168
225
|
* Require shared OAuth redirect routes to bind ID-token verification to an
|
|
169
226
|
* authorization request nonce. When true, routes generate `idTokenNonce`,
|
|
@@ -196,7 +253,14 @@ interface OAuthProvider<T extends Record<string, any> = Record<string, any>, O e
|
|
|
196
253
|
*/
|
|
197
254
|
options?: O | undefined;
|
|
198
255
|
}
|
|
199
|
-
|
|
256
|
+
/**
|
|
257
|
+
* Maps a provider-specific profile while remaining compatible with the erased
|
|
258
|
+
* profile type used by shared OAuth helpers.
|
|
259
|
+
*/
|
|
260
|
+
type OAuthProfileMapper<Profile extends object> = {
|
|
261
|
+
map(profile: Profile): Awaitable<OAuthMappedUser>;
|
|
262
|
+
}["map"];
|
|
263
|
+
type ProviderOptions<Profile extends object = object> = {
|
|
200
264
|
/**
|
|
201
265
|
* The client ID of your application.
|
|
202
266
|
*
|
|
@@ -240,22 +304,21 @@ type ProviderOptions<Profile extends Record<string, any> = any> = {
|
|
|
240
304
|
*/
|
|
241
305
|
disableIdTokenSignIn?: boolean | undefined;
|
|
242
306
|
/**
|
|
243
|
-
* verifyIdToken function to verify the id token
|
|
307
|
+
* verifyIdToken function to verify the id token.
|
|
308
|
+
*
|
|
309
|
+
* The optional endpoint context exposes request metadata to custom
|
|
310
|
+
* verifiers without coupling built-in provider verification to a runtime.
|
|
244
311
|
*/
|
|
245
|
-
verifyIdToken?: ((token: string, nonce?: string) => Promise<boolean>) | undefined;
|
|
312
|
+
verifyIdToken?: ((token: string, nonce?: string, ctx?: GenericEndpointContext) => Promise<boolean>) | undefined;
|
|
246
313
|
/**
|
|
247
314
|
* Custom function to get user info from the provider
|
|
315
|
+
*
|
|
316
|
+
* `data` must preserve the declared raw profile shape because account-key
|
|
317
|
+
* resolvers consume it after this hook returns.
|
|
248
318
|
*/
|
|
249
319
|
getUserInfo?: ((token: OAuth2Tokens) => Promise<{
|
|
250
|
-
user:
|
|
251
|
-
|
|
252
|
-
name?: string;
|
|
253
|
-
email?: string | null;
|
|
254
|
-
image?: string;
|
|
255
|
-
emailVerified: boolean;
|
|
256
|
-
[key: string]: any;
|
|
257
|
-
};
|
|
258
|
-
data: any;
|
|
320
|
+
user: OAuth2UserInfo & Record<string, unknown>;
|
|
321
|
+
data: Profile;
|
|
259
322
|
} | null>) | undefined;
|
|
260
323
|
/**
|
|
261
324
|
* Custom function to refresh a token
|
|
@@ -265,21 +328,7 @@ type ProviderOptions<Profile extends Record<string, any> = any> = {
|
|
|
265
328
|
* Custom function to map the provider profile to a
|
|
266
329
|
* user.
|
|
267
330
|
*/
|
|
268
|
-
mapProfileToUser?:
|
|
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;
|
|
331
|
+
mapProfileToUser?: OAuthProfileMapper<Profile> | undefined;
|
|
283
332
|
/**
|
|
284
333
|
* Disable implicit sign up for new users. When set to true for the provider,
|
|
285
334
|
* sign-in need to be called with with requestSignUp as true to create new users.
|
|
@@ -329,4 +378,4 @@ type ProviderOptions<Profile extends Record<string, any> = any> = {
|
|
|
329
378
|
requireEmailVerification?: boolean | undefined;
|
|
330
379
|
};
|
|
331
380
|
//#endregion
|
|
332
|
-
export { OAuth2Tokens, OAuth2UserInfo, OAuthIdTokenConfig, OAuthProvider, OAuthRefreshContext, ProviderOptions };
|
|
381
|
+
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
|
-
|
|
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,
|
package/dist/oauth2/utils.d.mts
CHANGED
package/dist/oauth2/utils.mjs
CHANGED
|
@@ -16,8 +16,7 @@ function parseScopeField(scope) {
|
|
|
16
16
|
}
|
|
17
17
|
function getOAuth2Tokens(data) {
|
|
18
18
|
const getDate = (seconds) => {
|
|
19
|
-
|
|
20
|
-
return new Date(now.getTime() + seconds * 1e3);
|
|
19
|
+
return new Date((/* @__PURE__ */ new Date()).getTime() + seconds * 1e3);
|
|
21
20
|
};
|
|
22
21
|
return {
|
|
23
22
|
tokenType: data.token_type,
|
|
@@ -48,7 +47,7 @@ function applyDefaultAccessTokenExpiry(tokens, accessTokenExpiresIn) {
|
|
|
48
47
|
function mergeScopes(stored, incoming) {
|
|
49
48
|
const existing = stored ? stored.split(",").map((scope) => scope.trim()).filter(Boolean) : [];
|
|
50
49
|
const next = (incoming ?? []).map((scope) => scope.trim()).filter(Boolean);
|
|
51
|
-
return [
|
|
50
|
+
return [.../* @__PURE__ */ new Set([...existing, ...next])].join(",");
|
|
52
51
|
}
|
|
53
52
|
/**
|
|
54
53
|
* Return the provider's primary Client ID: the single string, or the entry at
|