better-auth 1.7.11 → 1.7.13
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/adapters/index.d.mts +5 -10
- package/dist/api/dispatch.d.mts +3 -5
- package/dist/api/dispatch.mjs +6 -4
- package/dist/api/index.d.mts +506 -508
- package/dist/api/index.mjs +35 -34
- package/dist/api/middlewares/authorization.d.mts +15 -12
- package/dist/api/middlewares/authorization.mjs +2 -1
- package/dist/api/middlewares/index.d.mts +2 -1
- package/dist/api/middlewares/origin-check.d.mts +4 -7
- package/dist/api/routes/account.d.mts +11 -15
- package/dist/api/routes/account.mjs +7 -4
- package/dist/api/routes/callback.d.mts +2 -5
- package/dist/api/routes/callback.mjs +14 -53
- package/dist/api/routes/email-verification.d.mts +7 -12
- package/dist/api/routes/error.d.mts +2 -5
- package/dist/api/routes/index.d.mts +2 -1
- package/dist/api/routes/ok.d.mts +2 -5
- package/dist/api/routes/password.d.mts +8 -11
- package/dist/api/routes/password.mjs +3 -2
- package/dist/api/routes/session.d.mts +26 -29
- package/dist/api/routes/session.mjs +1 -1
- package/dist/api/routes/sign-in.d.mts +4 -6
- package/dist/api/routes/sign-out.d.mts +2 -5
- package/dist/api/routes/sign-up.d.mts +4 -6
- package/dist/api/routes/update-session.d.mts +4 -6
- package/dist/api/routes/update-user.d.mts +14 -16
- package/dist/api/routes/update-user.mjs +1 -1
- package/dist/api/state/oauth.d.mts +0 -3
- package/dist/api/state/oauth.mjs +2 -1
- package/dist/auth/full.d.mts +3 -4
- package/dist/auth/minimal.d.mts +3 -3
- package/dist/client/broadcast-channel.d.mts +6 -7
- package/dist/client/config.d.mts +15 -19
- package/dist/client/config.mjs +2 -2
- package/dist/client/equality.d.mts +3 -5
- package/dist/client/focus-manager.d.mts +4 -5
- package/dist/client/index.d.mts +8 -7
- package/dist/client/lynx/index.d.mts +6 -7
- package/dist/client/lynx/index.mjs +3 -2
- package/dist/client/lynx/lynx-store.d.mts +3 -4
- package/dist/client/online-manager.d.mts +4 -5
- package/dist/client/parser.d.mts +9 -5
- package/dist/client/path-to-object.d.mts +13 -14
- package/dist/client/plugins/index.d.mts +1 -1
- package/dist/client/plugins/infer-plugin.d.mts +2 -4
- package/dist/client/query.d.mts +4 -6
- package/dist/client/react/index.d.mts +6 -7
- package/dist/client/react/index.mjs +3 -2
- package/dist/client/react/react-store.d.mts +3 -4
- package/dist/client/session-atom.d.mts +4 -4
- package/dist/client/session-refresh.d.mts +3 -5
- package/dist/client/solid/index.d.mts +6 -7
- package/dist/client/solid/index.mjs +3 -2
- package/dist/client/svelte/index.d.mts +6 -7
- package/dist/client/svelte/index.mjs +3 -2
- package/dist/client/types.d.mts +11 -11
- package/dist/client/vanilla.d.mts +4 -5
- package/dist/client/vanilla.mjs +3 -2
- package/dist/client/vue/index.d.mts +6 -7
- package/dist/client/vue/index.mjs +3 -2
- package/dist/context/create-context.mjs +7 -7
- package/dist/context/helpers.mjs +9 -7
- package/dist/cookies/cookie-utils.d.mts +13 -13
- package/dist/cookies/cookie-utils.mjs +1 -3
- package/dist/cookies/index.d.mts +17 -18
- package/dist/cookies/index.mjs +11 -7
- package/dist/cookies/jwt.mjs +2 -1
- package/dist/cookies/session-store.d.mts +6 -5
- package/dist/cookies/session-store.mjs +3 -2
- package/dist/crypto/buffer.d.mts +2 -3
- package/dist/crypto/index.d.mts +9 -16
- package/dist/crypto/index.mjs +2 -1
- package/dist/crypto/jwt.d.mts +5 -7
- package/dist/crypto/jwt.mjs +2 -1
- package/dist/crypto/password.d.mts +1 -5
- package/dist/crypto/random.d.mts +2 -3
- package/dist/db/adapter-base.d.mts +2 -4
- package/dist/db/adapter-kysely.d.mts +2 -4
- package/dist/db/field-converter.d.mts +3 -5
- package/dist/db/field.d.mts +11 -12
- package/dist/db/get-migration.d.mts +4 -8
- package/dist/db/get-migration.mjs +22 -22
- package/dist/db/get-schema.d.mts +2 -4
- package/dist/db/internal-adapter.d.mts +2 -4
- package/dist/db/internal-adapter.mjs +6 -4
- package/dist/db/revoke-unproven-account-access.d.mts +3 -4
- package/dist/db/schema.d.mts +15 -16
- package/dist/db/schema.mjs +6 -3
- package/dist/db/to-zod.d.mts +5 -9
- package/dist/db/with-hooks.d.mts +3 -5
- package/dist/index.d.mts +4 -3
- package/dist/integrations/next-js.d.mts +7 -11
- package/dist/integrations/node.d.mts +5 -7
- package/dist/integrations/node.mjs +4 -2
- package/dist/integrations/solid-start.d.mts +2 -3
- package/dist/integrations/svelte-kit.d.mts +6 -14
- package/dist/integrations/tanstack-start-solid.d.mts +4 -8
- package/dist/integrations/tanstack-start.d.mts +4 -8
- package/dist/oauth2/callback.mjs +68 -0
- package/dist/oauth2/link-account.d.mts +5 -11
- package/dist/oauth2/link-account.mjs +12 -6
- package/dist/oauth2/state.d.mts +5 -7
- package/dist/oauth2/state.mjs +1 -1
- package/dist/oauth2/utils.d.mts +4 -6
- package/dist/package.mjs +1 -1
- package/dist/plugins/access/access.d.mts +4 -6
- package/dist/plugins/access/index.mjs +1 -2
- package/dist/plugins/access/types.d.mts +12 -14
- package/dist/plugins/additional-fields/client.d.mts +2 -4
- package/dist/plugins/admin/access/index.mjs +1 -2
- package/dist/plugins/admin/access/statement.d.mts +7 -7
- package/dist/plugins/admin/admin.d.mts +122 -128
- package/dist/plugins/admin/client.d.mts +32 -32
- package/dist/plugins/admin/client.mjs +1 -1
- package/dist/plugins/admin/error-codes.d.mts +25 -28
- package/dist/plugins/admin/index.d.mts +1 -1
- package/dist/plugins/admin/index.mjs +1 -2
- package/dist/plugins/admin/schema.d.mts +3 -4
- package/dist/plugins/admin/types.d.mts +8 -8
- package/dist/plugins/anonymous/client.d.mts +10 -12
- package/dist/plugins/anonymous/client.mjs +1 -1
- package/dist/plugins/anonymous/error-codes.d.mts +10 -13
- package/dist/plugins/anonymous/index.d.mts +17 -21
- package/dist/plugins/anonymous/schema.d.mts +2 -3
- package/dist/plugins/anonymous/types.d.mts +5 -6
- package/dist/plugins/bearer/index.d.mts +7 -11
- package/dist/plugins/captcha/constants.d.mts +2 -3
- package/dist/plugins/captcha/index.d.mts +6 -9
- package/dist/plugins/captcha/types.d.mts +11 -13
- package/dist/plugins/custom-session/client.d.mts +2 -4
- package/dist/plugins/custom-session/index.d.mts +10 -16
- package/dist/plugins/device-authorization/client.d.mts +2 -4
- package/dist/plugins/device-authorization/index.d.mts +39 -44
- package/dist/plugins/device-authorization/index.mjs +10 -9
- package/dist/plugins/device-authorization/routes.d.mts +7 -5
- package/dist/plugins/device-authorization/routes.mjs +6 -5
- package/dist/plugins/device-authorization/schema.d.mts +2 -3
- package/dist/plugins/email-otp/client.d.mts +5 -7
- package/dist/plugins/email-otp/client.mjs +1 -1
- package/dist/plugins/email-otp/error-codes.d.mts +5 -8
- package/dist/plugins/email-otp/index.d.mts +69 -76
- package/dist/plugins/email-otp/otp-token.mjs +19 -7
- package/dist/plugins/email-otp/types.d.mts +2 -4
- package/dist/plugins/generic-oauth/index.d.mts +9 -13
- package/dist/plugins/generic-oauth/index.mjs +6 -4
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/hubspot.mjs +2 -1
- package/dist/plugins/generic-oauth/providers/index.d.mts +2 -1
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/line.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/okta.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/slack.d.mts +3 -5
- package/dist/plugins/generic-oauth/providers/yandex.d.mts +3 -5
- package/dist/plugins/generic-oauth/types.d.mts +6 -7
- package/dist/plugins/haveibeenpwned/index.d.mts +7 -11
- package/dist/plugins/index.d.mts +4 -1
- package/dist/plugins/jwt/adapter.mjs +14 -3
- package/dist/plugins/jwt/client.d.mts +2 -3
- package/dist/plugins/jwt/cookie-cache.mjs +3 -8
- package/dist/plugins/jwt/index.d.mts +11 -14
- package/dist/plugins/jwt/index.mjs +3 -3
- package/dist/plugins/jwt/schema.d.mts +2 -3
- package/dist/plugins/jwt/sign.d.mts +9 -8
- package/dist/plugins/jwt/sign.mjs +6 -5
- package/dist/plugins/jwt/types.d.mts +7 -8
- package/dist/plugins/jwt/utils.d.mts +6 -9
- package/dist/plugins/jwt/verify.d.mts +2 -4
- package/dist/plugins/jwt/verify.mjs +10 -4
- package/dist/plugins/last-login-method/client.d.mts +3 -4
- package/dist/plugins/last-login-method/index.d.mts +5 -9
- package/dist/plugins/last-login-method/index.mjs +1 -1
- package/dist/plugins/magic-link/client.d.mts +2 -4
- package/dist/plugins/magic-link/index.d.mts +7 -10
- package/dist/plugins/magic-link/index.mjs +20 -17
- package/dist/plugins/multi-session/client.d.mts +3 -5
- package/dist/plugins/multi-session/client.mjs +1 -1
- package/dist/plugins/multi-session/error-codes.d.mts +3 -6
- package/dist/plugins/multi-session/index.d.mts +10 -14
- package/dist/plugins/oauth-popup/client.d.mts +11 -17
- package/dist/plugins/oauth-popup/client.mjs +6 -4
- package/dist/plugins/oauth-popup/constants.d.mts +5 -6
- package/dist/plugins/oauth-popup/error-codes.d.mts +6 -9
- package/dist/plugins/oauth-popup/index.d.mts +11 -15
- package/dist/plugins/oauth-popup/index.mjs +8 -7
- package/dist/plugins/oauth-popup/types.d.mts +4 -6
- package/dist/plugins/oauth-proxy/index.d.mts +11 -15
- package/dist/plugins/oauth-proxy/index.mjs +24 -48
- package/dist/plugins/one-tap/client.d.mts +6 -9
- package/dist/plugins/one-tap/index.d.mts +4 -7
- package/dist/plugins/one-time-token/client.d.mts +2 -3
- package/dist/plugins/one-time-token/index.d.mts +8 -10
- package/dist/plugins/open-api/generator.d.mts +8 -8
- package/dist/plugins/open-api/generator.mjs +5 -5
- package/dist/plugins/open-api/index.d.mts +5 -7
- package/dist/plugins/organization/access/index.mjs +1 -2
- package/dist/plugins/organization/access/statement.d.mts +8 -8
- package/dist/plugins/organization/adapter.d.mts +60 -87
- package/dist/plugins/organization/adapter.mjs +14 -10
- package/dist/plugins/organization/client.d.mts +108 -107
- package/dist/plugins/organization/client.mjs +9 -5
- package/dist/plugins/organization/error-codes.d.mts +61 -64
- package/dist/plugins/organization/has-permission.d.mts +2 -4
- package/dist/plugins/organization/has-permission.mjs +1 -1
- package/dist/plugins/organization/index.d.mts +1 -1
- package/dist/plugins/organization/organization.d.mts +20 -20
- package/dist/plugins/organization/organization.mjs +13 -8
- package/dist/plugins/organization/permission.d.mts +4 -5
- package/dist/plugins/organization/routes/crud-access-control.d.mts +28 -28
- package/dist/plugins/organization/routes/crud-invites.d.mts +64 -65
- package/dist/plugins/organization/routes/crud-invites.mjs +21 -18
- package/dist/plugins/organization/routes/crud-members.d.mts +53 -56
- package/dist/plugins/organization/routes/crud-members.mjs +23 -21
- package/dist/plugins/organization/routes/crud-org.d.mts +63 -65
- package/dist/plugins/organization/routes/crud-org.mjs +4 -2
- package/dist/plugins/organization/routes/crud-team.d.mts +65 -66
- package/dist/plugins/organization/routes/crud-team.mjs +4 -2
- package/dist/plugins/organization/schema.d.mts +33 -33
- package/dist/plugins/organization/schema.mjs +1 -1
- package/dist/plugins/organization/types.d.mts +16 -17
- package/dist/plugins/phone-number/client.d.mts +14 -16
- package/dist/plugins/phone-number/client.mjs +1 -1
- package/dist/plugins/phone-number/error-codes.d.mts +14 -17
- package/dist/plugins/phone-number/index.d.mts +48 -54
- package/dist/plugins/phone-number/schema.d.mts +2 -3
- package/dist/plugins/phone-number/types.d.mts +4 -5
- package/dist/plugins/siwe/client.d.mts +2 -4
- package/dist/plugins/siwe/index.d.mts +7 -9
- package/dist/plugins/siwe/index.mjs +1 -1
- package/dist/plugins/siwe/parse-message.mjs +1 -3
- package/dist/plugins/siwe/schema.d.mts +3 -4
- package/dist/plugins/siwe/types.d.mts +4 -4
- package/dist/plugins/test-utils/auth-helpers.mjs +4 -2
- package/dist/plugins/test-utils/index.d.mts +3 -5
- package/dist/plugins/test-utils/types.d.mts +7 -7
- package/dist/plugins/two-factor/backup-codes/index.d.mts +11 -14
- package/dist/plugins/two-factor/backup-codes/index.mjs +12 -6
- package/dist/plugins/two-factor/client.d.mts +16 -19
- package/dist/plugins/two-factor/client.mjs +1 -1
- package/dist/plugins/two-factor/constant.mjs +1 -1
- package/dist/plugins/two-factor/error-code.d.mts +15 -18
- package/dist/plugins/two-factor/index.d.mts +31 -35
- package/dist/plugins/two-factor/index.mjs +6 -3
- package/dist/plugins/two-factor/otp/index.d.mts +5 -8
- package/dist/plugins/two-factor/otp/index.mjs +159 -154
- package/dist/plugins/two-factor/schema.d.mts +2 -3
- package/dist/plugins/two-factor/totp/index.d.mts +7 -10
- package/dist/plugins/two-factor/totp/index.mjs +153 -148
- package/dist/plugins/two-factor/types.d.mts +6 -7
- package/dist/plugins/username/client.d.mts +12 -14
- package/dist/plugins/username/client.mjs +1 -1
- package/dist/plugins/username/error-codes.d.mts +11 -14
- package/dist/plugins/username/index.d.mts +26 -31
- package/dist/plugins/username/schema.d.mts +7 -10
- package/dist/state.d.mts +4 -5
- package/dist/test-utils/headers.d.mts +2 -3
- package/dist/test-utils/http-test-instance.d.mts +26 -29
- package/dist/test-utils/test-instance.d.mts +7 -6
- package/dist/test-utils/test-instance.mjs +4 -2
- package/dist/types/adapter.d.mts +1 -1
- package/dist/types/api.d.mts +4 -6
- package/dist/types/auth.d.mts +2 -4
- package/dist/types/helper.d.mts +11 -12
- package/dist/types/index.d.mts +2 -2
- package/dist/types/models.d.mts +4 -5
- package/dist/types/plugins.d.mts +7 -8
- package/dist/utils/hide-metadata.d.mts +2 -3
- package/dist/utils/index.d.mts +2 -1
- package/dist/utils/is-api-error.mjs +1 -2
- package/dist/utils/time.d.mts +4 -4
- package/dist/utils/url.d.mts +13 -15
- package/dist/utils/wildcard.mjs +5 -3
- package/package.json +13 -13
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Awaitable } from "@better-auth/core";
|
|
2
2
|
import { OAuth2Tokens, OAuth2UserInfo, OAuthAccountKeyContext, OAuthMappedUser, OAuthRefreshContext, TokenEndpointAuth } from "@better-auth/core/oauth2";
|
|
3
|
-
|
|
4
3
|
//#region src/plugins/generic-oauth/types.d.ts
|
|
5
4
|
/** Raw profile returned by a Generic OAuth provider. */
|
|
6
|
-
type GenericOAuthUserInfo = Omit<OAuth2UserInfo, "id"> & {
|
|
5
|
+
export type GenericOAuthUserInfo = Omit<OAuth2UserInfo, "id"> & {
|
|
7
6
|
id?: string | number | null | undefined;
|
|
8
7
|
sub?: string | number | null | undefined;
|
|
9
8
|
[key: string]: unknown;
|
|
10
9
|
};
|
|
11
|
-
interface GenericOAuthOptions<ID extends string = string> {
|
|
10
|
+
export interface GenericOAuthOptions<ID extends string = string> {
|
|
12
11
|
/**
|
|
13
12
|
* Array of OAuth provider configurations.
|
|
14
13
|
*/
|
|
@@ -17,7 +16,7 @@ interface GenericOAuthOptions<ID extends string = string> {
|
|
|
17
16
|
/**
|
|
18
17
|
* Configuration interface for generic OAuth providers.
|
|
19
18
|
*/
|
|
20
|
-
interface GenericOAuthConfig<ID extends string = string> {
|
|
19
|
+
export interface GenericOAuthConfig<ID extends string = string> {
|
|
21
20
|
/** Unique identifier for the OAuth provider */
|
|
22
21
|
providerId: ID;
|
|
23
22
|
/**
|
|
@@ -112,7 +111,8 @@ interface GenericOAuthConfig<ID extends string = string> {
|
|
|
112
111
|
responseType?: string | undefined;
|
|
113
112
|
/**
|
|
114
113
|
* The response mode to use for the authorization code request.
|
|
115
|
-
|
|
114
|
+
|
|
115
|
+
*/
|
|
116
116
|
responseMode?: ("query" | "form_post") | undefined;
|
|
117
117
|
/**
|
|
118
118
|
* Prompt parameter for the authorization request.
|
|
@@ -264,5 +264,4 @@ interface GenericOAuthConfig<ID extends string = string> {
|
|
|
264
264
|
*/
|
|
265
265
|
disableIdTokenNonceBinding?: boolean | undefined;
|
|
266
266
|
}
|
|
267
|
-
//#endregion
|
|
268
|
-
export { GenericOAuthConfig, GenericOAuthOptions, GenericOAuthUserInfo };
|
|
267
|
+
//#endregion
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as _$_better_auth_core0 from "@better-auth/core";
|
|
2
|
-
import * as _$_better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
|
|
3
|
-
|
|
4
1
|
//#region src/plugins/haveibeenpwned/index.d.ts
|
|
5
2
|
declare module "@better-auth/core" {
|
|
6
3
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -16,8 +13,8 @@ declare module "@better-auth/core" {
|
|
|
16
13
|
* @returns Whether the password has been compromised.
|
|
17
14
|
* @throws {APIError} When the password could not be checked.
|
|
18
15
|
*/
|
|
19
|
-
declare function isPasswordCompromised(password: string): Promise<boolean>;
|
|
20
|
-
interface HaveIBeenPwnedOptions {
|
|
16
|
+
export declare function isPasswordCompromised(password: string): Promise<boolean>;
|
|
17
|
+
export interface HaveIBeenPwnedOptions {
|
|
21
18
|
/**
|
|
22
19
|
* Custom error message shown when a compromised password is detected.
|
|
23
20
|
*/
|
|
@@ -35,10 +32,10 @@ interface HaveIBeenPwnedOptions {
|
|
|
35
32
|
*/
|
|
36
33
|
enabled?: boolean | undefined;
|
|
37
34
|
}
|
|
38
|
-
declare const haveIBeenPwned: (options?: HaveIBeenPwnedOptions | undefined) => {
|
|
35
|
+
export declare const haveIBeenPwned: (options?: HaveIBeenPwnedOptions | undefined) => {
|
|
39
36
|
id: "have-i-been-pwned";
|
|
40
37
|
version: string;
|
|
41
|
-
init(ctx:
|
|
38
|
+
init(ctx: import("@better-auth/core").AuthContext): {
|
|
42
39
|
context: {
|
|
43
40
|
password: {
|
|
44
41
|
hash(password: string): Promise<string>;
|
|
@@ -50,14 +47,13 @@ declare const haveIBeenPwned: (options?: HaveIBeenPwnedOptions | undefined) => {
|
|
|
50
47
|
minPasswordLength: number;
|
|
51
48
|
maxPasswordLength: number;
|
|
52
49
|
};
|
|
53
|
-
checkPassword: (userId: string, ctx:
|
|
50
|
+
checkPassword: (userId: string, ctx: import("@better-auth/core").GenericEndpointContext<import("@better-auth/core").BetterAuthOptions>) => Promise<boolean>;
|
|
54
51
|
};
|
|
55
52
|
};
|
|
56
53
|
};
|
|
57
54
|
options: HaveIBeenPwnedOptions | undefined;
|
|
58
55
|
$ERROR_CODES: {
|
|
59
|
-
PASSWORD_COMPROMISED:
|
|
56
|
+
PASSWORD_COMPROMISED: import("@better-auth/core/utils/error-codes").RawError<"PASSWORD_COMPROMISED">;
|
|
60
57
|
};
|
|
61
58
|
};
|
|
62
|
-
//#endregion
|
|
63
|
-
export { HaveIBeenPwnedOptions, haveIBeenPwned, isPasswordCompromised };
|
|
59
|
+
//#endregion
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -2,11 +2,13 @@ import { InferOptionSchema, InferPluginContext, InferPluginErrorCodes, InferPlug
|
|
|
2
2
|
import { HIDE_METADATA } from "../utils/hide-metadata.mjs";
|
|
3
3
|
import { AccessControl, ArrayElement, ExactRoleStatements, Role, RoleAuthorizeRequest, RoleInput, RoleStatements, Statements, SubArray, Subset } from "./access/types.mjs";
|
|
4
4
|
import { AuthorizeResponse, createAccessControl, role } from "./access/access.mjs";
|
|
5
|
+
import "./access/index.mjs";
|
|
5
6
|
import { OrganizationOptions } from "./organization/types.mjs";
|
|
6
7
|
import { InferInvitation, InferMember, InferOrganization, InferOrganizationRolesFromOption, InferOrganizationZodRolesFromOption, InferTeam, Invitation, InvitationInput, InvitationStatus, Member, MemberInput, Organization, OrganizationInput, OrganizationRole, OrganizationSchema, Team, TeamInput, TeamMember, TeamMemberInput, defaultRolesSchema, invitationSchema, invitationStatus, memberSchema, organizationRoleSchema, organizationSchema, roleSchema, teamMemberSchema, teamSchema } from "./organization/schema.mjs";
|
|
7
8
|
import { getOrgAdapter } from "./organization/adapter.mjs";
|
|
8
9
|
import { AdminOptions, InferAdminRolesFromOption, SessionWithImpersonatedBy, UserWithRole } from "./admin/types.mjs";
|
|
9
10
|
import { admin } from "./admin/admin.mjs";
|
|
11
|
+
import "./admin/index.mjs";
|
|
10
12
|
import { AnonymousOptions, AnonymousSession, UserWithAnonymous } from "./anonymous/types.mjs";
|
|
11
13
|
import { anonymous } from "./anonymous/index.mjs";
|
|
12
14
|
import { BearerOptions, bearer } from "./bearer/index.mjs";
|
|
@@ -66,4 +68,5 @@ import { USERNAME_ERROR_CODES } from "./username/error-codes.mjs";
|
|
|
66
68
|
import { UsernameOptions, UsernamePlugin, UsernamePluginWithoutDisplayUsername, username } from "./username/index.mjs";
|
|
67
69
|
import { hasPermission } from "./organization/has-permission.mjs";
|
|
68
70
|
import { DefaultOrganizationPlugin, DynamicAccessControlEndpoints, OrganizationCreator, OrganizationEndpoints, OrganizationPlugin, TeamEndpoints, organization, parseRoles } from "./organization/organization.mjs";
|
|
69
|
-
|
|
71
|
+
import "./organization/index.mjs";
|
|
72
|
+
export { AccessControl, type AdminOptions, type AnonymousOptions, type AnonymousSession, ArrayElement, type Auth0Options, AuthorizeResponse, type BackupCodeOptions, type BaseCaptchaOptions, BaseOAuthProviderOptions, BearerOptions, type BotIdVerification, type CaptchaFoxOptions, type CaptchaOptions, type CloudflareTurnstileOptions, CustomSessionPluginOptions, DefaultOrganizationPlugin, DeviceAuthorizationGrant, DeviceAuthorizationGrantAuthorization, DeviceAuthorizationOptions, DeviceAuthorizationPluginOptions, DeviceAuthorizationRequest, type DeviceCode, type DeviceCodeRedemptionAuthorization, type DeviceCodeRedemptionResult, DynamicAccessControlEndpoints, MULTI_SESSION_ERROR_CODES as ERROR_CODES, type EmailOTPOptions, ExactRoleStatements, type FieldSchema, type GenericOAuthConfig, type GenericOAuthOptions, type GenericOAuthUserInfo, type GoogleRecaptchaOptions, type GumroadOptions, type HCaptchaOptions, HIDE_METADATA, HaveIBeenPwnedOptions, type HubSpotOptions, type InferAdminRolesFromOption, type InferInvitation, type InferMember, InferOptionSchema, type InferOrganization, type InferOrganizationRolesFromOption, type InferOrganizationZodRolesFromOption, InferPluginContext, InferPluginErrorCodes, InferPluginIDs, type InferTeam, type Invitation, type InvitationInput, type InvitationStatus, type JWKOptions, type JWSAlgorithms, type Jwk, type JwtOptions, type KeycloakOptions, LastLoginMethodOptions, type LineOptions, type LoginResult, MagicLinkOptions, type Member, type MemberInput, type MicrosoftEntraIdOptions, MultiSessionConfig, OAUTH_POPUP_COMPLETE_SCRIPT, OAUTH_POPUP_DATA_ELEMENT_ID, OAUTH_POPUP_ERROR_CODES, OAUTH_POPUP_MESSAGE_TYPE, OAUTH_POPUP_SCRIPT_CSP_HASH, type OAuthPopupData, type OAuthPopupMessage, OAuthProxyOptions, type OTPOptions, type OktaOptions, OneTapOptions, OneTimeTokenOptions, type OpenAPIModelSchema, OpenAPIOptions, type OpenAPIParameter, type OpenAPISchema, type Organization, OrganizationCreator, OrganizationEndpoints, type OrganizationInput, type OrganizationOptions, OrganizationPlugin, type OrganizationRole, type OrganizationSchema, POPUP_MARKER_COOKIE, type Path, type PatreonOptions, type PhoneNumberOptions, type Provider, type ResolvedSigningKey, Role, RoleAuthorizeRequest, RoleInput, RoleStatements, SIWEPluginOptions, type SessionWithImpersonatedBy, type SlackOptions, Statements, SubArray, Subset, type TOTPOptions, TWO_FACTOR_ERROR_CODES, type Team, TeamEndpoints, type TeamInput, type TeamMember, type TeamMemberInput, type TestAuthOptions, type TestCookie, type TestHelpers, type TestUtilsOptions, type TimeString, TwoFactorOptions, TwoFactorProvider, TwoFactorTable, USERNAME_ERROR_CODES, type UserWithAnonymous, type UserWithPhoneNumber, type UserWithRole, UserWithTwoFactor, UsernameOptions, UsernamePlugin, UsernamePluginWithoutDisplayUsername, type ValidateRequestContext, type VercelBotIdOptions, type YandexOptions, admin, anonymous, auth0, type backupCode2fa, bearer, captcha, createAccessControl, createJwk, customSession, type defaultRolesSchema, deviceAuthorization, deviceAuthorizationOptionsSchema, emailOTP, type encodeBackupCodes, type generateBackupCodes, generateExportedKeyPair, type generator, genericOAuth, type getBackupCodes, getJwtToken, getOrgAdapter, gumroad, hasPermission, haveIBeenPwned, hubspot, type invitationSchema, type invitationStatus, isPasswordCompromised, jwt, keycloak, lastLoginMethod, line, magicLink, type memberSchema, microsoftEntraId, type ms, multiSession, oAuthProxy, oauthPopup, okta, oneTap, oneTimeToken, openAPI, organization, type organizationRoleSchema, type organizationSchema, type otp2fa, parseRoles, patreon, phoneNumber, redeemDeviceCode, resolveSigningKey, role, type roleSchema, type sec, signJWT, siwe, slack, type teamMemberSchema, type teamSchema, testUtils, toExpJWT, type totp2fa, twoFactor, twoFactorClient, username, type verifyBackupCode, verifyJWT, yandex };
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { getCurrentAdapter } from "@better-auth/core/context";
|
|
2
2
|
//#region src/plugins/jwt/adapter.ts
|
|
3
|
+
/**
|
|
4
|
+
* Algorithm of the key the plugin generates when `jwks.keyPairConfig` is unset.
|
|
5
|
+
*/
|
|
6
|
+
const DEFAULT_JWK_ALG = "EdDSA";
|
|
7
|
+
/**
|
|
8
|
+
* Algorithm for new keys, and for stored keys saved before the `alg` column
|
|
9
|
+
* existed.
|
|
10
|
+
*/
|
|
11
|
+
function getDefaultKeyAlg(options) {
|
|
12
|
+
return options?.jwks?.keyPairConfig?.alg ?? "EdDSA";
|
|
13
|
+
}
|
|
3
14
|
const getJwksAdapter = (baseAdapter, options) => {
|
|
4
15
|
return {
|
|
5
16
|
getAllKeys: async (ctx) => {
|
|
@@ -38,7 +49,7 @@ const getJwksAdapter = (baseAdapter, options) => {
|
|
|
38
49
|
*
|
|
39
50
|
* Legacy rows persisted before the `alg` column existed have
|
|
40
51
|
* `alg: null`. Per `schema.ts`, those rows are treated as the
|
|
41
|
-
* configured default alg (
|
|
52
|
+
* configured default alg ({@link getDefaultKeyAlg}),
|
|
42
53
|
* so deployments that have only legacy rows can still satisfy an
|
|
43
54
|
* audience-pinned `signingAlgorithm` matching the default.
|
|
44
55
|
*
|
|
@@ -48,7 +59,7 @@ const getJwksAdapter = (baseAdapter, options) => {
|
|
|
48
59
|
getLatestKeyByAlg: async (ctx, alg) => {
|
|
49
60
|
const candidates = options?.adapter?.getJwks ? await options.adapter.getJwks(ctx) : await (await getCurrentAdapter(baseAdapter)).findMany({ model: "jwks" });
|
|
50
61
|
if (!candidates) return void 0;
|
|
51
|
-
const configAlg = options
|
|
62
|
+
const configAlg = getDefaultKeyAlg(options);
|
|
52
63
|
const now = /* @__PURE__ */ new Date();
|
|
53
64
|
return candidates.filter((k) => k.alg === alg || k.alg == null && configAlg === alg).filter((k) => !k.expiresAt || k.expiresAt > now).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())[0];
|
|
54
65
|
},
|
|
@@ -65,4 +76,4 @@ const getJwksAdapter = (baseAdapter, options) => {
|
|
|
65
76
|
};
|
|
66
77
|
};
|
|
67
78
|
//#endregion
|
|
68
|
-
export { getJwksAdapter };
|
|
79
|
+
export { DEFAULT_JWK_ALG, getDefaultKeyAlg, getJwksAdapter };
|
|
@@ -3,7 +3,6 @@ import { jwt } from "./index.mjs";
|
|
|
3
3
|
import { BetterAuthClientOptions, ClientFetchOption, ClientStore } from "@better-auth/core";
|
|
4
4
|
import { JSONWebKeySet } from "jose";
|
|
5
5
|
import { BetterFetch } from "@better-fetch/fetch";
|
|
6
|
-
|
|
7
6
|
//#region src/plugins/jwt/client.d.ts
|
|
8
7
|
interface JwtClientOptions {
|
|
9
8
|
jwks?: {
|
|
@@ -16,7 +15,7 @@ interface JwtClientOptions {
|
|
|
16
15
|
jwksPath?: string;
|
|
17
16
|
};
|
|
18
17
|
}
|
|
19
|
-
declare const jwtClient: (options?: JwtClientOptions) => {
|
|
18
|
+
export declare const jwtClient: (options?: JwtClientOptions) => {
|
|
20
19
|
id: "better-auth-client";
|
|
21
20
|
version: string;
|
|
22
21
|
$InferServerPlugin: ReturnType<typeof jwt>;
|
|
@@ -38,4 +37,4 @@ declare const jwtClient: (options?: JwtClientOptions) => {
|
|
|
38
37
|
};
|
|
39
38
|
};
|
|
40
39
|
//#endregion
|
|
41
|
-
export {
|
|
40
|
+
export type { JWKOptions, JWSAlgorithms, Jwk, JwtOptions, ResolvedSigningKey };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SESSION_COOKIE_JWT_AUDIENCE, SESSION_COOKIE_JWT_TYPE, getSessionCookieJwtVerifyOptions, parseSessionCookieJwtPayload } from "../../cookies/jwt.mjs";
|
|
2
|
-
import { getJwksAdapter } from "./adapter.mjs";
|
|
2
|
+
import { getDefaultKeyAlg, getJwksAdapter } from "./adapter.mjs";
|
|
3
3
|
import { resolveSigningKey } from "./sign.mjs";
|
|
4
4
|
import { BetterAuthError } from "@better-auth/core/error";
|
|
5
5
|
import { SignJWT, decodeProtectedHeader, importJWK, jwtVerify } from "jose";
|
|
@@ -9,8 +9,7 @@ function getCookieCacheJwtIssuer(ctx) {
|
|
|
9
9
|
return typeof baseURL === "string" ? baseURL || "better-auth:session-cache" : ctx.context.baseURL || "better-auth:session-cache";
|
|
10
10
|
}
|
|
11
11
|
async function importLocalPublicKey(ctx, token, options) {
|
|
12
|
-
const
|
|
13
|
-
const kid = header.kid;
|
|
12
|
+
const kid = decodeProtectedHeader(token).kid;
|
|
14
13
|
if (!kid) {
|
|
15
14
|
ctx.context.logger.debug("Cookie-cache JWT missing kid in header");
|
|
16
15
|
return null;
|
|
@@ -25,11 +24,7 @@ async function importLocalPublicKey(ctx, token, options) {
|
|
|
25
24
|
ctx.context.logger.debug(`No JWKS key found for cookie-cache JWT kid: ${kid}`);
|
|
26
25
|
return null;
|
|
27
26
|
}
|
|
28
|
-
const alg = key.alg ?? options
|
|
29
|
-
if (!alg) {
|
|
30
|
-
ctx.context.logger.debug(`No JWT algorithm available for cookie-cache JWT kid: ${kid}`);
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
27
|
+
const alg = key.alg ?? getDefaultKeyAlg(options);
|
|
33
28
|
return {
|
|
34
29
|
alg,
|
|
35
30
|
publicKey: await importJWK(JSON.parse(key.publicKey), alg)
|
|
@@ -2,11 +2,8 @@ import { JWKOptions, JWSAlgorithms, Jwk, JwtOptions, ResolvedSigningKey } from "
|
|
|
2
2
|
import { getJwtToken, resolveSigningKey, signJWT } from "./sign.mjs";
|
|
3
3
|
import { createJwk, generateExportedKeyPair, toExpJWT } from "./utils.mjs";
|
|
4
4
|
import { verifyJWT } from "./verify.mjs";
|
|
5
|
-
import * as _$_better_auth_core0 from "@better-auth/core";
|
|
6
|
-
import * as _$better_call0 from "better-call";
|
|
7
5
|
import * as z from "zod";
|
|
8
6
|
import { JSONWebKeySet, JWTPayload } from "jose";
|
|
9
|
-
|
|
10
7
|
//#region src/plugins/jwt/index.d.ts
|
|
11
8
|
declare module "@better-auth/core" {
|
|
12
9
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -15,14 +12,14 @@ declare module "@better-auth/core" {
|
|
|
15
12
|
};
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
|
-
declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
15
|
+
export declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
19
16
|
id: "jwt";
|
|
20
17
|
version: string;
|
|
21
18
|
options: NoInfer<O>;
|
|
22
|
-
init(ctx:
|
|
19
|
+
init(ctx: import("@better-auth/core").AuthContext): {
|
|
23
20
|
context: {
|
|
24
21
|
sessionConfig: {
|
|
25
|
-
cookieCacheSigner:
|
|
22
|
+
cookieCacheSigner: import("@better-auth/core").CookieCacheSigner;
|
|
26
23
|
updateAge: number;
|
|
27
24
|
expiresIn: number;
|
|
28
25
|
freshAge: number;
|
|
@@ -34,7 +31,7 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
34
31
|
};
|
|
35
32
|
} | undefined;
|
|
36
33
|
endpoints: {
|
|
37
|
-
getJwks:
|
|
34
|
+
getJwks: import("better-call").StrictEndpoint<string, {
|
|
38
35
|
method: "GET";
|
|
39
36
|
metadata: {
|
|
40
37
|
openapi: {
|
|
@@ -111,10 +108,10 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
111
108
|
};
|
|
112
109
|
};
|
|
113
110
|
}, JSONWebKeySet>;
|
|
114
|
-
getToken:
|
|
111
|
+
getToken: import("better-call").StrictEndpoint<"/token", {
|
|
115
112
|
method: "GET";
|
|
116
113
|
requireHeaders: true;
|
|
117
|
-
use:
|
|
114
|
+
use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
118
115
|
session: {
|
|
119
116
|
session: Record<string, any> & {
|
|
120
117
|
id: string;
|
|
@@ -163,7 +160,7 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
163
160
|
}, {
|
|
164
161
|
token: string;
|
|
165
162
|
}>;
|
|
166
|
-
signJWT:
|
|
163
|
+
signJWT: import("better-call").StrictEndpoint<string, {
|
|
167
164
|
method: "POST";
|
|
168
165
|
metadata: {
|
|
169
166
|
$Infer: {
|
|
@@ -180,7 +177,7 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
180
177
|
}, {
|
|
181
178
|
token: string;
|
|
182
179
|
}>;
|
|
183
|
-
verifyJWT:
|
|
180
|
+
verifyJWT: import("better-call").StrictEndpoint<string, {
|
|
184
181
|
method: "POST";
|
|
185
182
|
metadata: {
|
|
186
183
|
$Infer: {
|
|
@@ -207,8 +204,8 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
207
204
|
};
|
|
208
205
|
hooks: {
|
|
209
206
|
after: {
|
|
210
|
-
matcher(context:
|
|
211
|
-
handler:
|
|
207
|
+
matcher(context: import("@better-auth/core").HookEndpointContext): boolean;
|
|
208
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
212
209
|
}[];
|
|
213
210
|
};
|
|
214
211
|
schema: {
|
|
@@ -243,4 +240,4 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
243
240
|
};
|
|
244
241
|
};
|
|
245
242
|
//#endregion
|
|
246
|
-
export { JWKOptions, JWSAlgorithms, Jwk, JwtOptions, ResolvedSigningKey, createJwk, generateExportedKeyPair, getJwtToken,
|
|
243
|
+
export { type JWKOptions, type JWSAlgorithms, type Jwk, type JwtOptions, type ResolvedSigningKey, createJwk, generateExportedKeyPair, getJwtToken, resolveSigningKey, signJWT, toExpJWT, verifyJWT };
|
|
@@ -2,7 +2,7 @@ import { mergeSchema } from "../../db/schema.mjs";
|
|
|
2
2
|
import { sessionMiddleware } from "../../api/routes/session.mjs";
|
|
3
3
|
import { APIError as APIError$1 } from "../../api/index.mjs";
|
|
4
4
|
import { PACKAGE_VERSION } from "../../version.mjs";
|
|
5
|
-
import { getJwksAdapter } from "./adapter.mjs";
|
|
5
|
+
import { getDefaultKeyAlg, getJwksAdapter } from "./adapter.mjs";
|
|
6
6
|
import { createJwk, generateExportedKeyPair, toExpJWT } from "./utils.mjs";
|
|
7
7
|
import { getJwtToken, resolveSigningKey, signJWT } from "./sign.mjs";
|
|
8
8
|
import { createCookieCacheSigner } from "./cookie-cache.mjs";
|
|
@@ -122,7 +122,7 @@ const jwt = (options) => {
|
|
|
122
122
|
}
|
|
123
123
|
if (!keySets?.length) throw new BetterAuthError("No key sets found. Make sure you have a key in your database.");
|
|
124
124
|
const now = Date.now();
|
|
125
|
-
const gracePeriod = (options?.jwks?.gracePeriod ??
|
|
125
|
+
const gracePeriod = (options?.jwks?.gracePeriod ?? 2592e3) * 1e3;
|
|
126
126
|
const keys = keySets.filter((key) => {
|
|
127
127
|
if (!key.expiresAt) return true;
|
|
128
128
|
return key.expiresAt.getTime() + gracePeriod > now;
|
|
@@ -131,7 +131,7 @@ const jwt = (options) => {
|
|
|
131
131
|
const defaultCrv = keyPairConfig ? "crv" in keyPairConfig ? keyPairConfig.crv : void 0 : void 0;
|
|
132
132
|
return ctx.json({ keys: keys.map((keySet) => {
|
|
133
133
|
return {
|
|
134
|
-
alg: keySet.alg ?? options
|
|
134
|
+
alg: keySet.alg ?? getDefaultKeyAlg(options),
|
|
135
135
|
crv: keySet.crv ?? defaultCrv,
|
|
136
136
|
...JSON.parse(keySet.publicKey),
|
|
137
137
|
kid: keySet.id
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { JWSAlgorithms, JwtOptions, ResolvedSigningKey } from "./types.mjs";
|
|
2
2
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
3
|
-
|
|
4
3
|
//#region src/plugins/jwt/sign.d.ts
|
|
5
4
|
type JWTPayloadWithOptional = {
|
|
6
5
|
/**
|
|
@@ -44,7 +43,8 @@ type JWTPayloadWithOptional = {
|
|
|
44
43
|
*
|
|
45
44
|
* @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6 RFC7519#section-4.1.6}
|
|
46
45
|
*/
|
|
47
|
-
iat?: number | undefined;
|
|
46
|
+
iat?: number | undefined;
|
|
47
|
+
/** Any other JWT Claim Set member. */
|
|
48
48
|
[propName: string]: unknown | undefined;
|
|
49
49
|
};
|
|
50
50
|
/**
|
|
@@ -65,7 +65,7 @@ type JWTPayloadWithOptional = {
|
|
|
65
65
|
* Used by the OAuth provider plugin to honor per-resource `signingAlgorithm` /
|
|
66
66
|
* `signingKeyId` overrides without re-implementing key resolution.
|
|
67
67
|
*/
|
|
68
|
-
interface SigningKeyOverrides {
|
|
68
|
+
export interface SigningKeyOverrides {
|
|
69
69
|
signingKeyId?: string | undefined;
|
|
70
70
|
signingAlgorithm?: JWSAlgorithms | undefined;
|
|
71
71
|
}
|
|
@@ -86,10 +86,11 @@ interface SigningKeyOverrides {
|
|
|
86
86
|
* tokens stay on the configured default algorithm even after extra algorithms
|
|
87
87
|
* have been lazy-minted for audience pinning.
|
|
88
88
|
*/
|
|
89
|
-
declare function resolveSigningKey(ctx: GenericEndpointContext, options?: JwtOptions, overrides?: SigningKeyOverrides): Promise<ResolvedSigningKey | null>;
|
|
90
|
-
declare function signJWT(ctx: GenericEndpointContext, config: {
|
|
89
|
+
export declare function resolveSigningKey(ctx: GenericEndpointContext, options?: JwtOptions, overrides?: SigningKeyOverrides): Promise<ResolvedSigningKey | null>;
|
|
90
|
+
export declare function signJWT(ctx: GenericEndpointContext, config: {
|
|
91
91
|
options?: JwtOptions | undefined;
|
|
92
|
-
payload: JWTPayloadWithOptional;
|
|
92
|
+
payload: JWTPayloadWithOptional;
|
|
93
|
+
/** Pre-resolved key from resolveSigningKey. Skips redundant DB lookup. */
|
|
93
94
|
resolvedKey?: ResolvedSigningKey;
|
|
94
95
|
/**
|
|
95
96
|
* Extra JWS Protected Header parameters to merge with the defaults
|
|
@@ -123,6 +124,6 @@ declare function signJWT(ctx: GenericEndpointContext, config: {
|
|
|
123
124
|
*/
|
|
124
125
|
signingAlgorithm?: JWSAlgorithms | undefined;
|
|
125
126
|
}): Promise<string>;
|
|
126
|
-
declare function getJwtToken(ctx: GenericEndpointContext, options?: JwtOptions | undefined): Promise<string>;
|
|
127
|
+
export declare function getJwtToken(ctx: GenericEndpointContext, options?: JwtOptions | undefined): Promise<string>;
|
|
127
128
|
//#endregion
|
|
128
|
-
export {
|
|
129
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { symmetricDecrypt } from "../../crypto/index.mjs";
|
|
2
|
-
import { getJwksAdapter } from "./adapter.mjs";
|
|
2
|
+
import { getDefaultKeyAlg, getJwksAdapter } from "./adapter.mjs";
|
|
3
3
|
import { createJwk, toExpJWT } from "./utils.mjs";
|
|
4
4
|
import { BetterAuthError } from "@better-auth/core/error";
|
|
5
5
|
import { SignJWT, importJWK } from "jose";
|
|
@@ -29,13 +29,13 @@ async function resolveSigningKey(ctx, options, overrides) {
|
|
|
29
29
|
key = await adapter.getKeyById(ctx, overrides.signingKeyId);
|
|
30
30
|
if (!key) throw new BetterAuthError(`signJWT: signingKeyId "${overrides.signingKeyId}" not found in JWKS. The key must be provisioned before it can be referenced.`);
|
|
31
31
|
if (overrides.signingAlgorithm !== void 0) {
|
|
32
|
-
const configAlg = options
|
|
32
|
+
const configAlg = getDefaultKeyAlg(options);
|
|
33
33
|
if ((key.alg ?? configAlg) !== overrides.signingAlgorithm) throw new BetterAuthError(`signJWT: signingKeyId "${overrides.signingKeyId}" has alg "${key.alg ?? `unset (inherits keyPairConfig.alg "${configAlg}")`}" but signingAlgorithm was set to "${overrides.signingAlgorithm}".`);
|
|
34
34
|
}
|
|
35
35
|
} else if (overrides?.signingAlgorithm !== void 0) {
|
|
36
36
|
key = await adapter.getLatestKeyByAlg(ctx, overrides.signingAlgorithm);
|
|
37
37
|
if (!key) {
|
|
38
|
-
const primaryAlg = options
|
|
38
|
+
const primaryAlg = getDefaultKeyAlg(options);
|
|
39
39
|
const preconfig = options?.jwks?.keyPairConfigs?.find((c) => c.alg === overrides.signingAlgorithm);
|
|
40
40
|
const isPrimary = primaryAlg === overrides.signingAlgorithm;
|
|
41
41
|
if (preconfig || isPrimary) key = await createJwk(ctx, {
|
|
@@ -51,7 +51,7 @@ async function resolveSigningKey(ctx, options, overrides) {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
} else {
|
|
54
|
-
const primaryAlg = options
|
|
54
|
+
const primaryAlg = getDefaultKeyAlg(options);
|
|
55
55
|
key = await adapter.getLatestKeyByAlg(ctx, primaryAlg) ?? await adapter.getLatestKey(ctx);
|
|
56
56
|
}
|
|
57
57
|
if (!key || key.expiresAt && key.expiresAt < /* @__PURE__ */ new Date()) {
|
|
@@ -64,7 +64,7 @@ async function resolveSigningKey(ctx, options, overrides) {
|
|
|
64
64
|
}).catch(() => {
|
|
65
65
|
throw new BetterAuthError("Failed to decrypt private key. Make sure the secret currently in use is the same as the one used to encrypt the private key. If you are using a different secret, either clean up your JWKS or disable private key encryption.");
|
|
66
66
|
}) : key.privateKey;
|
|
67
|
-
const alg = key.alg ?? options
|
|
67
|
+
const alg = key.alg ?? getDefaultKeyAlg(options);
|
|
68
68
|
const privateKey = await importJWK(JSON.parse(privateWebKey), alg);
|
|
69
69
|
return {
|
|
70
70
|
alg,
|
|
@@ -86,6 +86,7 @@ async function signJWT(ctx, config) {
|
|
|
86
86
|
const defaultIss = options?.jwt?.issuer ?? baseURLOrigin;
|
|
87
87
|
const aud = payload.aud;
|
|
88
88
|
const defaultAud = options?.jwt?.audience ?? baseURLOrigin;
|
|
89
|
+
if (!(iss ?? defaultIss) || !(aud ?? defaultAud)) ctx.context.logger.warn("[better-auth] The JWT plugin signed a JWT without an issuer or audience because no base URL was resolved for this call. Set `baseURL`, or `jwt.issuer` and `jwt.audience` in the JWT plugin options.");
|
|
89
90
|
if (options?.jwt?.sign) {
|
|
90
91
|
const jwtPayload = {
|
|
91
92
|
...payload,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Session, User } from "../../types/models.mjs";
|
|
2
2
|
import { InferOptionSchema } from "../../types/plugins.mjs";
|
|
3
|
+
import "../../types/index.mjs";
|
|
3
4
|
import { schema } from "./schema.mjs";
|
|
4
5
|
import { Awaitable, GenericEndpointContext } from "@better-auth/core";
|
|
5
6
|
import { JWTPayload } from "jose";
|
|
6
|
-
|
|
7
7
|
//#region src/plugins/jwt/types.d.ts
|
|
8
|
-
interface JwtOptions {
|
|
8
|
+
export interface JwtOptions {
|
|
9
9
|
/**
|
|
10
10
|
* Use the JWT plugin's locally managed signing keys for JWT session cookie
|
|
11
11
|
* cache values.
|
|
@@ -214,7 +214,7 @@ interface JwtOptions {
|
|
|
214
214
|
*
|
|
215
215
|
* @see https://github.com/panva/jose/issues/210
|
|
216
216
|
*/
|
|
217
|
-
type JWKOptions = {
|
|
217
|
+
export type JWKOptions = {
|
|
218
218
|
alg: "EdDSA";
|
|
219
219
|
crv?: "Ed25519" | undefined;
|
|
220
220
|
} | {
|
|
@@ -230,8 +230,8 @@ type JWKOptions = {
|
|
|
230
230
|
alg: "RS256";
|
|
231
231
|
modulusLength?: number | undefined;
|
|
232
232
|
};
|
|
233
|
-
type JWSAlgorithms = JWKOptions["alg"];
|
|
234
|
-
interface Jwk {
|
|
233
|
+
export type JWSAlgorithms = JWKOptions["alg"];
|
|
234
|
+
export interface Jwk {
|
|
235
235
|
id: string;
|
|
236
236
|
publicKey: string;
|
|
237
237
|
privateKey: string;
|
|
@@ -247,10 +247,9 @@ interface Jwk {
|
|
|
247
247
|
* read the `alg` before constructing the JWT payload
|
|
248
248
|
* (required for OIDC hash claims like at_hash).
|
|
249
249
|
*/
|
|
250
|
-
interface ResolvedSigningKey {
|
|
250
|
+
export interface ResolvedSigningKey {
|
|
251
251
|
alg: string;
|
|
252
252
|
kid: string;
|
|
253
253
|
privateKey: CryptoKey | Uint8Array;
|
|
254
254
|
}
|
|
255
|
-
//#endregion
|
|
256
|
-
export { JWKOptions, JWSAlgorithms, Jwk, JwtOptions, ResolvedSigningKey };
|
|
255
|
+
//#endregion
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Jwk, JwtOptions } from "./types.mjs";
|
|
2
2
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
3
|
-
import * as _$jose from "jose";
|
|
4
|
-
|
|
5
3
|
//#region src/plugins/jwt/utils.d.ts
|
|
6
4
|
/**
|
|
7
5
|
* Converts an expirationTime to ISO seconds expiration time (the format of JWT exp)
|
|
@@ -12,10 +10,10 @@ import * as _$jose from "jose";
|
|
|
12
10
|
* @param iat - the iat time to consolidate on
|
|
13
11
|
* @returns
|
|
14
12
|
*/
|
|
15
|
-
declare function toExpJWT(expirationTime: number | Date | string, iat: number): number;
|
|
16
|
-
declare function generateExportedKeyPair(options?: JwtOptions | undefined): Promise<{
|
|
17
|
-
publicWebKey:
|
|
18
|
-
privateWebKey:
|
|
13
|
+
export declare function toExpJWT(expirationTime: number | Date | string, iat: number): number;
|
|
14
|
+
export declare function generateExportedKeyPair(options?: JwtOptions | undefined): Promise<{
|
|
15
|
+
publicWebKey: import("jose").JWK;
|
|
16
|
+
privateWebKey: import("jose").JWK;
|
|
19
17
|
alg: "EdDSA" | "ES256" | "ES512" | "PS256" | "RS256";
|
|
20
18
|
cfg: {
|
|
21
19
|
crv?: "Ed25519" | undefined;
|
|
@@ -36,6 +34,5 @@ declare function generateExportedKeyPair(options?: JwtOptions | undefined): Prom
|
|
|
36
34
|
* @param options
|
|
37
35
|
* @returns
|
|
38
36
|
*/
|
|
39
|
-
declare function createJwk(ctx: GenericEndpointContext, options?: JwtOptions | undefined): Promise<Jwk>;
|
|
40
|
-
//#endregion
|
|
41
|
-
export { createJwk, generateExportedKeyPair, toExpJWT };
|
|
37
|
+
export declare function createJwk(ctx: GenericEndpointContext, options?: JwtOptions | undefined): Promise<Jwk>;
|
|
38
|
+
//#endregion
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { JwtOptions } from "./types.mjs";
|
|
2
2
|
import { JWTPayload } from "jose";
|
|
3
|
-
|
|
4
3
|
//#region src/plugins/jwt/verify.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Verify a JWT token using the JWKS public keys
|
|
7
6
|
* Returns the payload if valid, null otherwise
|
|
8
7
|
*/
|
|
9
|
-
declare function verifyJWT<T extends JWTPayload = JWTPayload>(token: string, options?: JwtOptions): Promise<(T & Required<Pick<JWTPayload, "sub" | "aud">>) | null>;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { verifyJWT };
|
|
8
|
+
export declare function verifyJWT<T extends JWTPayload = JWTPayload>(token: string, options?: JwtOptions): Promise<(T & Required<Pick<JWTPayload, "sub" | "aud">>) | null>;
|
|
9
|
+
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getJwksAdapter } from "./adapter.mjs";
|
|
1
|
+
import { getDefaultKeyAlg, getJwksAdapter } from "./adapter.mjs";
|
|
2
2
|
import { getCurrentAuthEndpointContext } from "@better-auth/core/context";
|
|
3
3
|
import { base64 } from "@better-auth/utils/base64";
|
|
4
4
|
import { importJWK, jwtVerify } from "jose";
|
|
@@ -28,11 +28,17 @@ async function verifyJWT(token, options) {
|
|
|
28
28
|
ctx.context.logger.debug(`No JWKS key found for kid: ${kid}`);
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
|
-
const
|
|
31
|
+
const publicKey = JSON.parse(key.publicKey);
|
|
32
|
+
const alg = key.alg ?? getDefaultKeyAlg(options);
|
|
33
|
+
const cryptoKey = await importJWK(publicKey, alg);
|
|
32
34
|
const baseURLOrigin = typeof ctx.context.options.baseURL === "string" ? ctx.context.options.baseURL : void 0;
|
|
35
|
+
const issuer = options?.jwt?.issuer ?? baseURLOrigin;
|
|
36
|
+
const audience = options?.jwt?.audience ?? baseURLOrigin;
|
|
37
|
+
if (!issuer || !audience) ctx.context.logger.warn("[better-auth] The JWT plugin is verifying a JWT without checking its issuer or audience because no base URL was resolved for this call. Set `baseURL`, or `jwt.issuer` and `jwt.audience` in the JWT plugin options.");
|
|
33
38
|
const { payload } = await jwtVerify(token, cryptoKey, {
|
|
34
|
-
issuer
|
|
35
|
-
audience
|
|
39
|
+
issuer,
|
|
40
|
+
audience,
|
|
41
|
+
algorithms: [alg]
|
|
36
42
|
});
|
|
37
43
|
if (!payload.sub || !payload.aud) return null;
|
|
38
44
|
return payload;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Configuration for the client-side last login method plugin
|
|
4
4
|
*/
|
|
5
|
-
interface LastLoginMethodClientConfig {
|
|
5
|
+
export interface LastLoginMethodClientConfig {
|
|
6
6
|
/**
|
|
7
7
|
* Name of the cookie to read the last login method from
|
|
8
8
|
* @default "better-auth.last_used_login_method"
|
|
@@ -22,7 +22,7 @@ interface LastLoginMethodClientConfig {
|
|
|
22
22
|
/**
|
|
23
23
|
* Client-side plugin to retrieve the last used login method
|
|
24
24
|
*/
|
|
25
|
-
declare const lastLoginMethodClient: (config?: LastLoginMethodClientConfig) => {
|
|
25
|
+
export declare const lastLoginMethodClient: (config?: LastLoginMethodClientConfig) => {
|
|
26
26
|
id: "last-login-method-client";
|
|
27
27
|
version: string;
|
|
28
28
|
getActions(): {
|
|
@@ -44,5 +44,4 @@ declare const lastLoginMethodClient: (config?: LastLoginMethodClientConfig) => {
|
|
|
44
44
|
isLastUsedLoginMethod: (method: string) => boolean;
|
|
45
45
|
};
|
|
46
46
|
};
|
|
47
|
-
//#endregion
|
|
48
|
-
export { LastLoginMethodClientConfig, lastLoginMethodClient };
|
|
47
|
+
//#endregion
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import * as _$_better_auth_core0 from "@better-auth/core";
|
|
2
1
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
3
|
-
import * as _$better_call0 from "better-call";
|
|
4
|
-
|
|
5
2
|
//#region src/plugins/last-login-method/index.d.ts
|
|
6
3
|
declare module "@better-auth/core" {
|
|
7
4
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -13,7 +10,7 @@ declare module "@better-auth/core" {
|
|
|
13
10
|
/**
|
|
14
11
|
* Configuration for tracking different authentication methods
|
|
15
12
|
*/
|
|
16
|
-
interface LastLoginMethodOptions {
|
|
13
|
+
export interface LastLoginMethodOptions {
|
|
17
14
|
/**
|
|
18
15
|
* Name of the cookie to store the last login method
|
|
19
16
|
* @default "better-auth.last_used_login_method"
|
|
@@ -57,10 +54,10 @@ interface LastLoginMethodOptions {
|
|
|
57
54
|
/**
|
|
58
55
|
* Plugin to track the last used login method
|
|
59
56
|
*/
|
|
60
|
-
declare const lastLoginMethod: <O extends LastLoginMethodOptions>(userConfig?: O | undefined) => {
|
|
57
|
+
export declare const lastLoginMethod: <O extends LastLoginMethodOptions>(userConfig?: O | undefined) => {
|
|
61
58
|
id: "last-login-method";
|
|
62
59
|
version: string;
|
|
63
|
-
init(ctx:
|
|
60
|
+
init(ctx: import("@better-auth/core").AuthContext): {
|
|
64
61
|
options: {
|
|
65
62
|
databaseHooks: {
|
|
66
63
|
user: {
|
|
@@ -107,7 +104,7 @@ declare const lastLoginMethod: <O extends LastLoginMethodOptions>(userConfig?: O
|
|
|
107
104
|
hooks: {
|
|
108
105
|
after: {
|
|
109
106
|
matcher(): true;
|
|
110
|
-
handler:
|
|
107
|
+
handler: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>>;
|
|
111
108
|
}[];
|
|
112
109
|
};
|
|
113
110
|
schema: O["storeInDatabase"] extends true ? {
|
|
@@ -123,5 +120,4 @@ declare const lastLoginMethod: <O extends LastLoginMethodOptions>(userConfig?: O
|
|
|
123
120
|
} : undefined;
|
|
124
121
|
options: NoInfer<O>;
|
|
125
122
|
};
|
|
126
|
-
//#endregion
|
|
127
|
-
export { LastLoginMethodOptions, lastLoginMethod };
|
|
123
|
+
//#endregion
|
|
@@ -30,7 +30,7 @@ const lastLoginMethod = (userConfig) => {
|
|
|
30
30
|
const config = {
|
|
31
31
|
...userConfig,
|
|
32
32
|
cookieName: userConfig?.cookieName ?? "better-auth.last_used_login_method",
|
|
33
|
-
maxAge: userConfig?.maxAge ??
|
|
33
|
+
maxAge: userConfig?.maxAge ?? 2592e3
|
|
34
34
|
};
|
|
35
35
|
return {
|
|
36
36
|
id: "last-login-method",
|