better-auth 1.6.23 → 1.6.25
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 +1 -6
- package/dist/api/dispatch.d.mts +0 -1
- package/dist/api/index.d.mts +476 -478
- package/dist/api/middlewares/authorization.d.mts +12 -8
- 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 +3 -5
- package/dist/api/routes/account.d.mts +10 -13
- package/dist/api/routes/account.mjs +35 -7
- package/dist/api/routes/callback.d.mts +1 -3
- package/dist/api/routes/callback.mjs +4 -0
- package/dist/api/routes/email-verification.d.mts +4 -8
- package/dist/api/routes/email-verification.mjs +15 -2
- package/dist/api/routes/error.d.mts +1 -3
- package/dist/api/routes/index.d.mts +2 -1
- package/dist/api/routes/ok.d.mts +1 -3
- package/dist/api/routes/password.d.mts +7 -9
- package/dist/api/routes/password.mjs +14 -1
- package/dist/api/routes/session.d.mts +22 -24
- package/dist/api/routes/session.mjs +5 -1
- package/dist/api/routes/sign-in.d.mts +3 -5
- package/dist/api/routes/sign-in.mjs +84 -2
- package/dist/api/routes/sign-out.d.mts +1 -3
- package/dist/api/routes/sign-up.d.mts +3 -4
- package/dist/api/routes/sign-up.mjs +3 -2
- package/dist/api/routes/update-session.d.mts +3 -4
- package/dist/api/routes/update-user.d.mts +13 -14
- package/dist/api/routes/update-user.mjs +26 -1
- package/dist/auth/full.d.mts +1 -1
- package/dist/auth/minimal.d.mts +1 -1
- package/dist/client/config.d.mts +12 -14
- package/dist/client/config.mjs +2 -2
- package/dist/client/equality.d.mts +0 -1
- package/dist/client/index.d.mts +6 -5
- package/dist/client/lynx/index.d.mts +4 -5
- package/dist/client/lynx/lynx-store.d.mts +1 -2
- package/dist/client/parser.d.mts +7 -3
- package/dist/client/path-to-object.d.mts +3 -4
- package/dist/client/plugins/index.d.mts +1 -1
- package/dist/client/plugins/infer-plugin.d.mts +0 -1
- package/dist/client/query.d.mts +0 -1
- package/dist/client/query.mjs +38 -20
- package/dist/client/react/index.d.mts +4 -5
- package/dist/client/react/react-store.d.mts +1 -2
- package/dist/client/session-refresh.d.mts +0 -1
- package/dist/client/solid/index.d.mts +6 -6
- package/dist/client/solid/index.mjs +4 -2
- package/dist/client/svelte/index.d.mts +5 -6
- package/dist/client/types.d.mts +2 -2
- package/dist/client/vanilla.d.mts +2 -3
- package/dist/client/vue/index.d.mts +5 -6
- package/dist/context/create-context.mjs +3 -3
- package/dist/context/helpers.mjs +2 -2
- package/dist/cookies/cookie-utils.d.mts +1 -1
- package/dist/cookies/index.d.mts +6 -7
- package/dist/cookies/index.mjs +4 -0
- package/dist/cookies/session-store.d.mts +1 -0
- package/dist/cookies/session-store.mjs +6 -1
- package/dist/crypto/index.d.mts +2 -9
- package/dist/crypto/jwt.d.mts +0 -1
- package/dist/crypto/password.d.mts +1 -5
- package/dist/db/adapter-base.d.mts +0 -1
- package/dist/db/adapter-kysely.d.mts +0 -1
- package/dist/db/field-converter.d.mts +0 -1
- package/dist/db/field.d.mts +9 -10
- package/dist/db/get-migration.d.mts +0 -1
- package/dist/db/get-migration.mjs +8 -4
- package/dist/db/get-schema.d.mts +0 -1
- package/dist/db/internal-adapter.d.mts +0 -1
- package/dist/db/internal-adapter.mjs +61 -1
- package/dist/db/revoke-unproven-account-access.d.mts +0 -1
- package/dist/db/schema.d.mts +2 -2
- package/dist/db/to-zod.d.mts +3 -7
- package/dist/db/with-hooks.d.mts +0 -1
- package/dist/index.d.mts +4 -3
- package/dist/integrations/next-js.d.mts +4 -7
- package/dist/integrations/node.d.mts +2 -3
- package/dist/integrations/svelte-kit.d.mts +2 -9
- package/dist/integrations/tanstack-start-solid.d.mts +2 -5
- package/dist/integrations/tanstack-start.d.mts +2 -5
- package/dist/oauth2/link-account.d.mts +1 -1
- package/dist/oauth2/state.d.mts +0 -1
- package/dist/oauth2/utils.d.mts +0 -1
- package/dist/package.mjs +1 -1
- package/dist/plugins/access/access.d.mts +0 -1
- package/dist/plugins/access/types.d.mts +4 -5
- package/dist/plugins/additional-fields/client.d.mts +0 -1
- package/dist/plugins/admin/access/statement.d.mts +1 -0
- package/dist/plugins/admin/admin.d.mts +120 -125
- package/dist/plugins/admin/client.d.mts +30 -30
- package/dist/plugins/admin/client.mjs +1 -1
- package/dist/plugins/admin/error-codes.d.mts +23 -25
- package/dist/plugins/admin/index.d.mts +1 -1
- package/dist/plugins/admin/routes.mjs +9 -0
- package/dist/plugins/admin/schema.d.mts +1 -1
- package/dist/plugins/admin/types.d.mts +3 -2
- package/dist/plugins/anonymous/client.d.mts +9 -11
- package/dist/plugins/anonymous/client.mjs +1 -1
- package/dist/plugins/anonymous/error-codes.d.mts +8 -10
- package/dist/plugins/anonymous/index.d.mts +14 -18
- package/dist/plugins/anonymous/types.d.mts +1 -1
- package/dist/plugins/bearer/index.d.mts +4 -7
- package/dist/plugins/captcha/index.d.mts +5 -8
- package/dist/plugins/captcha/types.d.mts +0 -1
- package/dist/plugins/custom-session/client.d.mts +0 -1
- package/dist/plugins/custom-session/index.d.mts +7 -12
- package/dist/plugins/device-authorization/client.d.mts +0 -1
- package/dist/plugins/device-authorization/index.d.mts +19 -22
- package/dist/plugins/email-otp/client.d.mts +4 -6
- package/dist/plugins/email-otp/client.mjs +1 -1
- package/dist/plugins/email-otp/error-codes.d.mts +3 -5
- package/dist/plugins/email-otp/index.d.mts +67 -73
- package/dist/plugins/email-otp/routes.mjs +2 -0
- package/dist/plugins/email-otp/types.d.mts +0 -1
- package/dist/plugins/generic-oauth/client.d.mts +10 -11
- package/dist/plugins/generic-oauth/client.mjs +1 -1
- package/dist/plugins/generic-oauth/error-codes.d.mts +8 -10
- package/dist/plugins/generic-oauth/index.d.mts +40 -44
- package/dist/plugins/generic-oauth/providers/auth0.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/gumroad.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/hubspot.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/index.d.mts +2 -1
- package/dist/plugins/generic-oauth/providers/keycloak.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/line.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/okta.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/patreon.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/slack.d.mts +0 -1
- package/dist/plugins/generic-oauth/providers/yandex.d.mts +0 -1
- package/dist/plugins/generic-oauth/routes.mjs +14 -0
- package/dist/plugins/generic-oauth/types.d.mts +1 -2
- package/dist/plugins/haveibeenpwned/index.d.mts +3 -6
- package/dist/plugins/index.d.mts +4 -1
- package/dist/plugins/jwt/client.d.mts +2 -4
- package/dist/plugins/jwt/index.d.mts +8 -11
- package/dist/plugins/jwt/sign.d.mts +2 -2
- package/dist/plugins/jwt/types.d.mts +1 -1
- package/dist/plugins/jwt/utils.d.mts +2 -4
- package/dist/plugins/jwt/verify.d.mts +0 -1
- package/dist/plugins/last-login-method/client.mjs +13 -0
- package/dist/plugins/last-login-method/index.d.mts +11 -5
- package/dist/plugins/last-login-method/index.mjs +8 -0
- package/dist/plugins/magic-link/client.d.mts +0 -1
- package/dist/plugins/magic-link/index.d.mts +4 -5
- package/dist/plugins/magic-link/index.mjs +32 -1
- package/dist/plugins/mcp/authorize.mjs +12 -0
- package/dist/plugins/mcp/client/adapters.d.mts +0 -1
- package/dist/plugins/mcp/client/index.d.mts +2 -0
- package/dist/plugins/mcp/client/index.mjs +36 -11
- package/dist/plugins/mcp/index.d.mts +10 -11
- package/dist/plugins/multi-session/client.d.mts +2 -4
- package/dist/plugins/multi-session/client.mjs +1 -1
- package/dist/plugins/multi-session/error-codes.d.mts +1 -3
- package/dist/plugins/multi-session/index.d.mts +7 -11
- package/dist/plugins/multi-session/index.mjs +45 -0
- package/dist/plugins/oauth-popup/client.d.mts +6 -12
- package/dist/plugins/oauth-popup/client.mjs +5 -3
- package/dist/plugins/oauth-popup/error-codes.d.mts +4 -6
- package/dist/plugins/oauth-popup/index.d.mts +8 -12
- package/dist/plugins/oauth-popup/index.mjs +1 -1
- package/dist/plugins/oauth-popup/types.d.mts +1 -2
- package/dist/plugins/oauth-proxy/index.d.mts +6 -9
- package/dist/plugins/oauth-proxy/index.mjs +2 -2
- package/dist/plugins/oidc-provider/authorize.mjs +9 -0
- package/dist/plugins/oidc-provider/client.d.mts +1 -2
- package/dist/plugins/oidc-provider/index.d.mts +15 -17
- package/dist/plugins/oidc-provider/index.mjs +26 -2
- package/dist/plugins/oidc-provider/schema.d.mts +0 -1
- package/dist/plugins/oidc-provider/schema.mjs +37 -0
- package/dist/plugins/oidc-provider/types.d.mts +1 -1
- package/dist/plugins/one-tap/client.d.mts +3 -6
- package/dist/plugins/one-tap/client.mjs +3 -0
- package/dist/plugins/one-tap/index.d.mts +1 -3
- package/dist/plugins/one-tap/index.mjs +6 -1
- package/dist/plugins/one-time-token/client.d.mts +1 -2
- package/dist/plugins/one-time-token/index.d.mts +5 -6
- package/dist/plugins/one-time-token/index.mjs +30 -0
- package/dist/plugins/open-api/generator.d.mts +0 -1
- package/dist/plugins/open-api/generator.mjs +81 -5
- package/dist/plugins/open-api/index.d.mts +3 -5
- package/dist/plugins/organization/access/statement.d.mts +1 -0
- package/dist/plugins/organization/adapter.d.mts +56 -82
- package/dist/plugins/organization/adapter.mjs +17 -3
- package/dist/plugins/organization/client.d.mts +106 -105
- package/dist/plugins/organization/client.mjs +7 -4
- package/dist/plugins/organization/error-codes.d.mts +59 -61
- package/dist/plugins/organization/has-permission.d.mts +0 -1
- 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 +7 -7
- package/dist/plugins/organization/organization.mjs +434 -1
- package/dist/plugins/organization/permission.d.mts +2 -2
- package/dist/plugins/organization/routes/crud-access-control.d.mts +17 -17
- package/dist/plugins/organization/routes/crud-invites.d.mts +53 -54
- package/dist/plugins/organization/routes/crud-invites.mjs +1 -1
- package/dist/plugins/organization/routes/crud-members.d.mts +44 -46
- package/dist/plugins/organization/routes/crud-members.mjs +4 -1
- package/dist/plugins/organization/routes/crud-org.d.mts +47 -48
- package/dist/plugins/organization/routes/crud-org.mjs +2 -2
- package/dist/plugins/organization/routes/crud-team.d.mts +50 -51
- package/dist/plugins/organization/schema.d.mts +4 -4
- package/dist/plugins/organization/schema.mjs +1 -1
- package/dist/plugins/organization/types.d.mts +16 -16
- package/dist/plugins/phone-number/client.d.mts +13 -15
- package/dist/plugins/phone-number/client.mjs +1 -1
- package/dist/plugins/phone-number/error-codes.d.mts +12 -14
- package/dist/plugins/phone-number/index.d.mts +41 -47
- package/dist/plugins/phone-number/routes.mjs +15 -0
- package/dist/plugins/phone-number/types.d.mts +1 -1
- package/dist/plugins/siwe/client.d.mts +0 -1
- package/dist/plugins/siwe/index.d.mts +4 -5
- package/dist/plugins/test-utils/index.d.mts +2 -4
- package/dist/plugins/test-utils/types.d.mts +1 -0
- package/dist/plugins/two-factor/backup-codes/index.d.mts +4 -6
- package/dist/plugins/two-factor/backup-codes/index.mjs +52 -1
- package/dist/plugins/two-factor/client.d.mts +12 -15
- package/dist/plugins/two-factor/client.mjs +1 -1
- package/dist/plugins/two-factor/error-code.d.mts +10 -12
- package/dist/plugins/two-factor/index.d.mts +27 -31
- package/dist/plugins/two-factor/index.mjs +30 -0
- package/dist/plugins/two-factor/otp/index.d.mts +2 -4
- package/dist/plugins/two-factor/otp/index.mjs +42 -1
- package/dist/plugins/two-factor/totp/index.d.mts +4 -6
- package/dist/plugins/two-factor/totp/index.mjs +47 -0
- package/dist/plugins/two-factor/types.d.mts +1 -1
- package/dist/plugins/username/client.d.mts +9 -11
- package/dist/plugins/username/client.mjs +1 -1
- package/dist/plugins/username/error-codes.d.mts +8 -10
- package/dist/plugins/username/index.d.mts +17 -22
- package/dist/plugins/username/schema.d.mts +3 -5
- package/dist/state.d.mts +0 -1
- package/dist/state.mjs +4 -0
- package/dist/test-utils/test-instance.d.mts +5 -3
- package/dist/test-utils/test-instance.mjs +4 -1
- package/dist/types/adapter.d.mts +1 -1
- package/dist/types/api.d.mts +1 -2
- package/dist/types/auth.d.mts +0 -1
- package/dist/types/helper.d.mts +5 -5
- package/dist/types/index.d.mts +2 -2
- package/dist/types/models.d.mts +0 -1
- package/dist/types/plugins.d.mts +2 -3
- package/dist/utils/index.d.mts +2 -1
- package/dist/utils/request.mjs +23 -0
- package/dist/utils/url.d.mts +0 -1
- package/package.json +11 -11
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GenericEndpointContext } from "@better-auth/core";
|
|
2
2
|
import { User } from "@better-auth/core/db";
|
|
3
3
|
import { OAuth2Tokens, OAuth2UserInfo } from "@better-auth/core/oauth2";
|
|
4
|
-
|
|
5
4
|
//#region src/plugins/generic-oauth/types.d.ts
|
|
6
5
|
interface GenericOAuthOptions {
|
|
7
6
|
/**
|
|
@@ -70,7 +69,7 @@ interface GenericOAuthConfig {
|
|
|
70
69
|
responseType?: string | undefined;
|
|
71
70
|
/**
|
|
72
71
|
* The response mode to use for the authorization code request.
|
|
73
|
-
|
|
72
|
+
*/
|
|
74
73
|
responseMode?: ("query" | "form_post") | undefined;
|
|
75
74
|
/**
|
|
76
75
|
* Prompt parameter for the authorization request.
|
|
@@ -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> {
|
|
@@ -30,7 +27,7 @@ interface HaveIBeenPwnedOptions {
|
|
|
30
27
|
declare const haveIBeenPwned: (options?: HaveIBeenPwnedOptions | undefined) => {
|
|
31
28
|
id: "have-i-been-pwned";
|
|
32
29
|
version: string;
|
|
33
|
-
init(ctx:
|
|
30
|
+
init(ctx: import("@better-auth/core").AuthContext): {
|
|
34
31
|
context: {
|
|
35
32
|
password: {
|
|
36
33
|
hash(password: string): Promise<string>;
|
|
@@ -42,13 +39,13 @@ declare const haveIBeenPwned: (options?: HaveIBeenPwnedOptions | undefined) => {
|
|
|
42
39
|
minPasswordLength: number;
|
|
43
40
|
maxPasswordLength: number;
|
|
44
41
|
};
|
|
45
|
-
checkPassword: (userId: string, ctx:
|
|
42
|
+
checkPassword: (userId: string, ctx: import("@better-auth/core").GenericEndpointContext<import("@better-auth/core").BetterAuthOptions>) => Promise<boolean>;
|
|
46
43
|
};
|
|
47
44
|
};
|
|
48
45
|
};
|
|
49
46
|
options: HaveIBeenPwnedOptions | undefined;
|
|
50
47
|
$ERROR_CODES: {
|
|
51
|
-
PASSWORD_COMPROMISED:
|
|
48
|
+
PASSWORD_COMPROMISED: import("@better-auth/core/utils/error-codes").RawError<"PASSWORD_COMPROMISED">;
|
|
52
49
|
};
|
|
53
50
|
};
|
|
54
51
|
//#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";
|
|
@@ -67,4 +69,5 @@ import { USERNAME_ERROR_CODES } from "./username/error-codes.mjs";
|
|
|
67
69
|
import { UsernameOptions, username } from "./username/index.mjs";
|
|
68
70
|
import { hasPermission } from "./organization/has-permission.mjs";
|
|
69
71
|
import { DefaultOrganizationPlugin, DynamicAccessControlEndpoints, OrganizationCreator, OrganizationEndpoints, OrganizationPlugin, TeamEndpoints, organization, parseRoles } from "./organization/organization.mjs";
|
|
70
|
-
|
|
72
|
+
import "./organization/index.mjs";
|
|
73
|
+
export { AccessControl, type AdminOptions, type AnonymousOptions, type AnonymousSession, ArrayElement, type Auth0Options, type AuthorizationQuery, AuthorizeResponse, type BackupCodeOptions, type BaseCaptchaOptions, BaseOAuthProviderOptions, BearerOptions, type CaptchaFoxOptions, type CaptchaOptions, type Client, type CloudflareTurnstileOptions, type CodeVerificationValue, CustomSessionPluginOptions, DefaultOrganizationPlugin, DeviceAuthorizationOptions, DynamicAccessControlEndpoints, MULTI_SESSION_ERROR_CODES as ERROR_CODES, type EmailOTPOptions, ExactRoleStatements, type FieldSchema, type GenericOAuthConfig, type GenericOAuthOptions, 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 OAuthAccessToken, type OAuthPopupData, type OAuthPopupMessage, OAuthProxyOptions, type OIDCMetadata, type OIDCOptions, 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, 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 TestCookie, type TestHelpers, type TestUtilsOptions, type TimeString, type TokenBody, TwoFactorOptions, TwoFactorProvider, TwoFactorTable, USERNAME_ERROR_CODES, type UserWithAnonymous, type UserWithPhoneNumber, type UserWithRole, UserWithTwoFactor, UsernameOptions, 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, getClient, getJwtToken, getMCPProtectedResourceMetadata, getMCPProviderMetadata, getMetadata, getOrgAdapter, gumroad, hasPermission, haveIBeenPwned, hubspot, type invitationSchema, type invitationStatus, jwt, keycloak, lastLoginMethod, line, magicLink, mcp, type memberSchema, microsoftEntraId, type ms, multiSession, oAuthDiscoveryMetadata, oAuthProtectedResourceMetadata, oAuthProxy, oauthPopup, oidcProvider, okta, oneTap, oneTimeToken, openAPI, organization, type organizationRoleSchema, type organizationSchema, type otp2fa, parseRoles, patreon, phoneNumber, role, type roleSchema, type sec, signJWT, siwe, slack, type teamMemberSchema, type teamSchema, testUtils, toExpJWT, type totp2fa, twoFactor, twoFactorClient, username, type verifyBackupCode, verifyJWT, withMcpAuth, yandex };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { JWKOptions, JWSAlgorithms, Jwk, JwtOptions } from "./types.mjs";
|
|
2
2
|
import { jwt } from "./index.mjs";
|
|
3
3
|
import { JSONWebKeySet } from "jose";
|
|
4
|
-
import * as _better_fetch_fetch0 from "@better-fetch/fetch";
|
|
5
|
-
|
|
6
4
|
//#region src/plugins/jwt/client.d.ts
|
|
7
5
|
interface JwtClientOptions {
|
|
8
6
|
jwks?: {
|
|
@@ -22,7 +20,7 @@ declare const jwtClient: (options?: JwtClientOptions) => {
|
|
|
22
20
|
pathMethods: {
|
|
23
21
|
[x: string]: "GET";
|
|
24
22
|
};
|
|
25
|
-
getActions: ($fetch:
|
|
23
|
+
getActions: ($fetch: import("@better-fetch/fetch").BetterFetch) => {
|
|
26
24
|
jwks: (fetchOptions?: any) => Promise<{
|
|
27
25
|
data: null;
|
|
28
26
|
error: {
|
|
@@ -37,4 +35,4 @@ declare const jwtClient: (options?: JwtClientOptions) => {
|
|
|
37
35
|
};
|
|
38
36
|
};
|
|
39
37
|
//#endregion
|
|
40
|
-
export { jwtClient };
|
|
38
|
+
export { type JWKOptions, type JWSAlgorithms, type Jwk, type JwtOptions, jwtClient };
|
|
@@ -2,11 +2,8 @@ import { JWKOptions, JWSAlgorithms, Jwk, JwtOptions } from "./types.mjs";
|
|
|
2
2
|
import { getJwtToken, 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> {
|
|
@@ -20,7 +17,7 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
20
17
|
version: string;
|
|
21
18
|
options: NoInfer<O>;
|
|
22
19
|
endpoints: {
|
|
23
|
-
getJwks:
|
|
20
|
+
getJwks: import("better-call").StrictEndpoint<string, {
|
|
24
21
|
method: "GET";
|
|
25
22
|
metadata: {
|
|
26
23
|
openapi: {
|
|
@@ -97,10 +94,10 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
97
94
|
};
|
|
98
95
|
};
|
|
99
96
|
}, JSONWebKeySet>;
|
|
100
|
-
getToken:
|
|
97
|
+
getToken: import("better-call").StrictEndpoint<"/token", {
|
|
101
98
|
method: "GET";
|
|
102
99
|
requireHeaders: true;
|
|
103
|
-
use: ((inputContext:
|
|
100
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
104
101
|
session: {
|
|
105
102
|
session: Record<string, any> & {
|
|
106
103
|
id: string;
|
|
@@ -149,7 +146,7 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
149
146
|
}, {
|
|
150
147
|
token: string;
|
|
151
148
|
}>;
|
|
152
|
-
signJWT:
|
|
149
|
+
signJWT: import("better-call").StrictEndpoint<string, {
|
|
153
150
|
method: "POST";
|
|
154
151
|
metadata: {
|
|
155
152
|
$Infer: {
|
|
@@ -166,7 +163,7 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
166
163
|
}, {
|
|
167
164
|
token: string;
|
|
168
165
|
}>;
|
|
169
|
-
verifyJWT:
|
|
166
|
+
verifyJWT: import("better-call").StrictEndpoint<string, {
|
|
170
167
|
method: "POST";
|
|
171
168
|
metadata: {
|
|
172
169
|
$Infer: {
|
|
@@ -193,8 +190,8 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
193
190
|
};
|
|
194
191
|
hooks: {
|
|
195
192
|
after: {
|
|
196
|
-
matcher(context:
|
|
197
|
-
handler: (inputContext:
|
|
193
|
+
matcher(context: import("@better-auth/core").HookEndpointContext): boolean;
|
|
194
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
198
195
|
}[];
|
|
199
196
|
};
|
|
200
197
|
schema: {
|
|
@@ -221,4 +218,4 @@ declare const jwt: <O extends JwtOptions>(options?: O) => {
|
|
|
221
218
|
};
|
|
222
219
|
};
|
|
223
220
|
//#endregion
|
|
224
|
-
export { JWKOptions, JWSAlgorithms, Jwk, JwtOptions, createJwk, generateExportedKeyPair, getJwtToken, jwt, signJWT, toExpJWT, verifyJWT };
|
|
221
|
+
export { type JWKOptions, type JWSAlgorithms, type Jwk, type JwtOptions, createJwk, generateExportedKeyPair, getJwtToken, jwt, signJWT, toExpJWT, verifyJWT };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { JwtOptions } 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
|
declare function signJWT(ctx: GenericEndpointContext, config: {
|
|
@@ -1,9 +1,9 @@
|
|
|
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
8
|
interface JwtOptions {
|
|
9
9
|
jwks?: {
|
|
@@ -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)
|
|
@@ -14,8 +12,8 @@ import * as jose from "jose";
|
|
|
14
12
|
*/
|
|
15
13
|
declare function toExpJWT(expirationTime: number | Date | string, iat: number): number;
|
|
16
14
|
declare function generateExportedKeyPair(options?: JwtOptions | undefined): Promise<{
|
|
17
|
-
publicWebKey: jose.JWK;
|
|
18
|
-
privateWebKey: jose.JWK;
|
|
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;
|
|
@@ -15,15 +15,28 @@ const lastLoginMethodClient = (config = {}) => {
|
|
|
15
15
|
version: PACKAGE_VERSION,
|
|
16
16
|
getActions() {
|
|
17
17
|
return {
|
|
18
|
+
/**
|
|
19
|
+
* Get the last used login method from cookies
|
|
20
|
+
* @returns The last used login method or null if not found
|
|
21
|
+
*/
|
|
18
22
|
getLastUsedLoginMethod: () => {
|
|
19
23
|
return getCookieValue(cookieName);
|
|
20
24
|
},
|
|
25
|
+
/**
|
|
26
|
+
* Clear the last used login method cookie
|
|
27
|
+
* This sets the cookie with an expiration date in the past
|
|
28
|
+
*/
|
|
21
29
|
clearLastUsedLoginMethod: () => {
|
|
22
30
|
if (typeof document !== "undefined") {
|
|
23
31
|
const domainPart = config.domain ? ` domain=${config.domain};` : "";
|
|
24
32
|
document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;${domainPart}`;
|
|
25
33
|
}
|
|
26
34
|
},
|
|
35
|
+
/**
|
|
36
|
+
* Check if a specific login method was the last used
|
|
37
|
+
* @param method The method to check
|
|
38
|
+
* @returns True if the method was the last used, false otherwise
|
|
39
|
+
*/
|
|
27
40
|
isLastUsedLoginMethod: (method) => {
|
|
28
41
|
return getCookieValue(cookieName) === method;
|
|
29
42
|
}
|
|
@@ -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> {
|
|
@@ -35,6 +32,15 @@ interface LastLoginMethodOptions {
|
|
|
35
32
|
* @default false
|
|
36
33
|
*/
|
|
37
34
|
storeInDatabase?: boolean | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* A hook to run before the last login method is stored in the cookie.
|
|
37
|
+
* Useful if you are required to follow GDPR or other regulations to ensure that you're allowed to store the last login method in the cookie.
|
|
38
|
+
*
|
|
39
|
+
* @param ctx - The context from the hook
|
|
40
|
+
* @param lastUsedLoginMethod - The last login method
|
|
41
|
+
* @returns `true` to store the cookie, `false` to skip storing it (authentication continues either way)
|
|
42
|
+
*/
|
|
43
|
+
beforeStoreCookie?: ((ctx: GenericEndpointContext, lastUsedLoginMethod: string) => Promise<boolean> | boolean) | undefined;
|
|
38
44
|
/**
|
|
39
45
|
* Custom schema for the plugin
|
|
40
46
|
* @default undefined
|
|
@@ -51,7 +57,7 @@ interface LastLoginMethodOptions {
|
|
|
51
57
|
declare const lastLoginMethod: <O extends LastLoginMethodOptions>(userConfig?: O | undefined) => {
|
|
52
58
|
id: "last-login-method";
|
|
53
59
|
version: string;
|
|
54
|
-
init(ctx:
|
|
60
|
+
init(ctx: import("@better-auth/core").AuthContext): {
|
|
55
61
|
options: {
|
|
56
62
|
databaseHooks: {
|
|
57
63
|
user: {
|
|
@@ -98,7 +104,7 @@ declare const lastLoginMethod: <O extends LastLoginMethodOptions>(userConfig?: O
|
|
|
98
104
|
hooks: {
|
|
99
105
|
after: {
|
|
100
106
|
matcher(): true;
|
|
101
|
-
handler: (inputContext:
|
|
107
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
102
108
|
}[];
|
|
103
109
|
};
|
|
104
110
|
schema: O["storeInDatabase"] extends true ? {
|
|
@@ -71,6 +71,14 @@ const lastLoginMethod = (userConfig) => {
|
|
|
71
71
|
maxAge: config.maxAge,
|
|
72
72
|
httpOnly: false
|
|
73
73
|
};
|
|
74
|
+
let isPermitted = true;
|
|
75
|
+
if (config.beforeStoreCookie) try {
|
|
76
|
+
isPermitted = await config.beforeStoreCookie(ctx, lastUsedLoginMethod);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (ctx.context.logger) ctx.context.logger.error?.("[LastLoginMethod] Error in beforeStoreCookie hook", error);
|
|
79
|
+
isPermitted = false;
|
|
80
|
+
}
|
|
81
|
+
if (!isPermitted) return;
|
|
74
82
|
ctx.setCookie(config.cookieName, lastUsedLoginMethod, cookieAttributes);
|
|
75
83
|
}
|
|
76
84
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Awaitable, GenericEndpointContext } from "@better-auth/core";
|
|
2
|
-
import * as better_call0 from "better-call";
|
|
3
2
|
import * as z from "zod";
|
|
4
|
-
|
|
5
3
|
//#region src/plugins/magic-link/index.d.ts
|
|
6
4
|
declare module "@better-auth/core" {
|
|
7
5
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -90,9 +88,10 @@ declare const magicLink: (options: MagicLinkOptions) => {
|
|
|
90
88
|
*
|
|
91
89
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/sign-in#api-method-sign-in-magic-link)
|
|
92
90
|
*/
|
|
93
|
-
signInMagicLink:
|
|
91
|
+
signInMagicLink: import("better-call").StrictEndpoint<"/sign-in/magic-link", {
|
|
94
92
|
method: "POST";
|
|
95
93
|
requireHeaders: true;
|
|
94
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>)[];
|
|
96
95
|
body: z.ZodObject<{
|
|
97
96
|
email: z.ZodEmail;
|
|
98
97
|
name: z.ZodOptional<z.ZodString>;
|
|
@@ -142,7 +141,7 @@ declare const magicLink: (options: MagicLinkOptions) => {
|
|
|
142
141
|
*
|
|
143
142
|
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/magic-link#api-method-magic-link-verify)
|
|
144
143
|
*/
|
|
145
|
-
magicLinkVerify:
|
|
144
|
+
magicLinkVerify: import("better-call").StrictEndpoint<"/magic-link/verify", {
|
|
146
145
|
method: "GET";
|
|
147
146
|
query: z.ZodObject<{
|
|
148
147
|
token: z.ZodString;
|
|
@@ -150,7 +149,7 @@ declare const magicLink: (options: MagicLinkOptions) => {
|
|
|
150
149
|
errorCallbackURL: z.ZodOptional<z.ZodString>;
|
|
151
150
|
newUserCallbackURL: z.ZodOptional<z.ZodString>;
|
|
152
151
|
}, z.core.$strip>;
|
|
153
|
-
use: ((inputContext:
|
|
152
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>)[];
|
|
154
153
|
requireHeaders: true;
|
|
155
154
|
metadata: {
|
|
156
155
|
openapi: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { originCheck } from "../../api/middlewares/origin-check.mjs";
|
|
1
|
+
import { formCsrfMiddleware, originCheck } from "../../api/middlewares/origin-check.mjs";
|
|
2
2
|
import { parseSessionOutput, parseUserOutput } from "../../db/schema.mjs";
|
|
3
3
|
import { generateRandomString } from "../../crypto/random.mjs";
|
|
4
4
|
import { setSessionCookie } from "../../cookies/index.mjs";
|
|
@@ -38,9 +38,25 @@ const magicLink = (options) => {
|
|
|
38
38
|
id: "magic-link",
|
|
39
39
|
version: PACKAGE_VERSION,
|
|
40
40
|
endpoints: {
|
|
41
|
+
/**
|
|
42
|
+
* ### Endpoint
|
|
43
|
+
*
|
|
44
|
+
* POST `/sign-in/magic-link`
|
|
45
|
+
*
|
|
46
|
+
* ### API Methods
|
|
47
|
+
*
|
|
48
|
+
* **server:**
|
|
49
|
+
* `auth.api.signInMagicLink`
|
|
50
|
+
*
|
|
51
|
+
* **client:**
|
|
52
|
+
* `authClient.signIn.magicLink`
|
|
53
|
+
*
|
|
54
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/sign-in#api-method-sign-in-magic-link)
|
|
55
|
+
*/
|
|
41
56
|
signInMagicLink: createAuthEndpoint("/sign-in/magic-link", {
|
|
42
57
|
method: "POST",
|
|
43
58
|
requireHeaders: true,
|
|
59
|
+
use: [formCsrfMiddleware],
|
|
44
60
|
body: signInMagicLinkBodySchema,
|
|
45
61
|
metadata: { openapi: {
|
|
46
62
|
operationId: "signInWithMagicLink",
|
|
@@ -81,6 +97,21 @@ const magicLink = (options) => {
|
|
|
81
97
|
}, ctx);
|
|
82
98
|
return ctx.json({ status: true });
|
|
83
99
|
}),
|
|
100
|
+
/**
|
|
101
|
+
* ### Endpoint
|
|
102
|
+
*
|
|
103
|
+
* GET `/magic-link/verify`
|
|
104
|
+
*
|
|
105
|
+
* ### API Methods
|
|
106
|
+
*
|
|
107
|
+
* **server:**
|
|
108
|
+
* `auth.api.magicLinkVerify`
|
|
109
|
+
*
|
|
110
|
+
* **client:**
|
|
111
|
+
* `authClient.magicLink.verify`
|
|
112
|
+
*
|
|
113
|
+
* @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/magic-link#api-method-magic-link-verify)
|
|
114
|
+
*/
|
|
84
115
|
magicLinkVerify: createAuthEndpoint("/magic-link/verify", {
|
|
85
116
|
method: "GET",
|
|
86
117
|
query: magicLinkVerifyQuerySchema,
|
|
@@ -94,6 +94,18 @@ async function authorizeMCPOAuth(ctx, options) {
|
|
|
94
94
|
scope: requestScope,
|
|
95
95
|
userId: session.user.id,
|
|
96
96
|
authTime: new Date(session.session.createdAt).getTime(),
|
|
97
|
+
/**
|
|
98
|
+
* If the prompt is set to `consent`, then we need
|
|
99
|
+
* to require the user to consent to the scopes.
|
|
100
|
+
*
|
|
101
|
+
* This means the code now needs to be treated as a
|
|
102
|
+
* consent request.
|
|
103
|
+
*
|
|
104
|
+
* once the user consents, the code will be updated
|
|
105
|
+
* with the actual code. This is to prevent the
|
|
106
|
+
* client from using the code before the user
|
|
107
|
+
* consents.
|
|
108
|
+
*/
|
|
97
109
|
requireConsent: query.prompt === "consent",
|
|
98
110
|
state: query.prompt === "consent" ? query.state : null,
|
|
99
111
|
codeChallenge: query.code_challenge,
|
|
@@ -24,7 +24,9 @@ interface NodeLikeRequest {
|
|
|
24
24
|
}
|
|
25
25
|
interface NodeLikeResponse {
|
|
26
26
|
set?: (name: string, value: string) => void;
|
|
27
|
+
get?: (name: string) => string | undefined;
|
|
27
28
|
setHeader?: (name: string, value: string) => void;
|
|
29
|
+
getHeader?: (name: string) => string | number | string[] | undefined;
|
|
28
30
|
status?: (code: number) => {
|
|
29
31
|
json: (body: unknown) => void;
|
|
30
32
|
};
|
|
@@ -17,7 +17,19 @@ function buildCorsHeaders(authURL, allowedOrigin) {
|
|
|
17
17
|
function makeWWWAuthenticate(authURL, resource) {
|
|
18
18
|
return `Bearer resource_metadata="${resource ? `${resource}/.well-known/oauth-protected-resource` : `${authURL}/.well-known/oauth-protected-resource`}"`;
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function addExposeHeader(headers, headerName) {
|
|
21
|
+
const exposedHeaders = headers["Access-Control-Expose-Headers"];
|
|
22
|
+
if (!exposedHeaders) return {
|
|
23
|
+
...headers,
|
|
24
|
+
"Access-Control-Expose-Headers": headerName
|
|
25
|
+
};
|
|
26
|
+
const alreadyExposed = exposedHeaders.split(",").some((header) => header.trim().toLowerCase() === headerName.toLowerCase());
|
|
27
|
+
return {
|
|
28
|
+
...headers,
|
|
29
|
+
"Access-Control-Expose-Headers": alreadyExposed ? exposedHeaders : `${exposedHeaders}, ${headerName}`
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function make401Response(authURL, resource, corsHeaders) {
|
|
21
33
|
const wwwAuth = makeWWWAuthenticate(authURL, resource);
|
|
22
34
|
return Response.json({
|
|
23
35
|
jsonrpc: "2.0",
|
|
@@ -29,10 +41,13 @@ function make401Response(authURL, resource) {
|
|
|
29
41
|
id: null
|
|
30
42
|
}, {
|
|
31
43
|
status: 401,
|
|
32
|
-
headers: {
|
|
44
|
+
headers: {
|
|
45
|
+
...addExposeHeader(corsHeaders, "WWW-Authenticate"),
|
|
46
|
+
"WWW-Authenticate": wwwAuth
|
|
47
|
+
}
|
|
33
48
|
});
|
|
34
49
|
}
|
|
35
|
-
function send401Node(res, wwwAuth, message) {
|
|
50
|
+
function send401Node(res, wwwAuth, message, corsHeaders) {
|
|
36
51
|
const body = JSON.stringify({
|
|
37
52
|
jsonrpc: "2.0",
|
|
38
53
|
error: {
|
|
@@ -41,13 +56,21 @@ function send401Node(res, wwwAuth, message) {
|
|
|
41
56
|
},
|
|
42
57
|
id: null
|
|
43
58
|
});
|
|
59
|
+
const existingExposedHeaders = res.get?.("Access-Control-Expose-Headers") ?? res.getHeader?.("Access-Control-Expose-Headers") ?? res.getHeader?.("access-control-expose-headers");
|
|
60
|
+
const headers = {
|
|
61
|
+
...addExposeHeader({
|
|
62
|
+
...corsHeaders,
|
|
63
|
+
...existingExposedHeaders ? { "Access-Control-Expose-Headers": Array.isArray(existingExposedHeaders) ? existingExposedHeaders.join(", ") : String(existingExposedHeaders) } : {}
|
|
64
|
+
}, "WWW-Authenticate"),
|
|
65
|
+
"WWW-Authenticate": wwwAuth
|
|
66
|
+
};
|
|
44
67
|
if (typeof res.set === "function") {
|
|
45
|
-
res.set(
|
|
68
|
+
for (const [name, value] of Object.entries(headers)) res.set(name, value);
|
|
46
69
|
res.status?.(401).json(JSON.parse(body));
|
|
47
70
|
} else if (typeof res.writeHead === "function") {
|
|
48
71
|
res.writeHead(401, {
|
|
49
72
|
"Content-Type": "application/json",
|
|
50
|
-
|
|
73
|
+
...headers
|
|
51
74
|
});
|
|
52
75
|
res.end?.(body);
|
|
53
76
|
}
|
|
@@ -78,9 +101,10 @@ function createMcpAuthClient(options) {
|
|
|
78
101
|
headers: corsHeaders
|
|
79
102
|
});
|
|
80
103
|
const authHeader = req.headers.get("Authorization");
|
|
81
|
-
if (!authHeader || !authHeader.startsWith("Bearer ")) return make401Response(authURL, options.resource);
|
|
82
|
-
const
|
|
83
|
-
|
|
104
|
+
if (!authHeader || !authHeader.startsWith("Bearer ")) return make401Response(authURL, options.resource, corsHeaders);
|
|
105
|
+
const token = authHeader.slice(7);
|
|
106
|
+
const session = await verifyToken(token);
|
|
107
|
+
if (!session) return make401Response(authURL, options.resource, corsHeaders);
|
|
84
108
|
return fn(req, session);
|
|
85
109
|
};
|
|
86
110
|
};
|
|
@@ -128,12 +152,13 @@ function createMcpAuthClient(options) {
|
|
|
128
152
|
return async (req, res, next) => {
|
|
129
153
|
const authHeader = req.headers?.authorization ?? req.headers?.get?.("Authorization") ?? req.get?.("Authorization");
|
|
130
154
|
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
131
|
-
send401Node(res, makeWWWAuthenticate(authURL, options.resource), "Unauthorized: Authentication required");
|
|
155
|
+
send401Node(res, makeWWWAuthenticate(authURL, options.resource), "Unauthorized: Authentication required", corsHeaders);
|
|
132
156
|
return;
|
|
133
157
|
}
|
|
134
|
-
const
|
|
158
|
+
const token = authHeader.slice(7);
|
|
159
|
+
const session = await verifyToken(token);
|
|
135
160
|
if (!session) {
|
|
136
|
-
send401Node(res, makeWWWAuthenticate(authURL, options.resource), "Invalid or expired token");
|
|
161
|
+
send401Node(res, makeWWWAuthenticate(authURL, options.resource), "Invalid or expired token", corsHeaders);
|
|
137
162
|
return;
|
|
138
163
|
}
|
|
139
164
|
req.mcpSession = session;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { OAuthAccessToken, OIDCMetadata, OIDCOptions } from "../oidc-provider/types.mjs";
|
|
2
|
+
import "../oidc-provider/index.mjs";
|
|
2
3
|
import { BetterAuthOptions, GenericEndpointContext } from "@better-auth/core";
|
|
3
|
-
import * as better_call0 from "better-call";
|
|
4
4
|
import * as z from "zod";
|
|
5
|
-
|
|
6
5
|
//#region src/plugins/mcp/index.d.ts
|
|
7
6
|
declare module "@better-auth/core" {
|
|
8
7
|
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
@@ -31,18 +30,18 @@ declare const mcp: (options: MCPOptions) => {
|
|
|
31
30
|
hooks: {
|
|
32
31
|
after: {
|
|
33
32
|
matcher(): true;
|
|
34
|
-
handler: (inputContext:
|
|
33
|
+
handler: (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>;
|
|
35
34
|
}[];
|
|
36
35
|
};
|
|
37
36
|
endpoints: {
|
|
38
|
-
oAuthConsent:
|
|
37
|
+
oAuthConsent: import("better-call").StrictEndpoint<"/oauth2/consent", {
|
|
39
38
|
method: "POST";
|
|
40
39
|
operationId: string;
|
|
41
40
|
body: z.ZodObject<{
|
|
42
41
|
accept: z.ZodBoolean;
|
|
43
42
|
consent_code: z.ZodOptional<z.ZodNullable<z.ZodOptional<z.ZodString>>>;
|
|
44
43
|
}, z.core.$strip>;
|
|
45
|
-
use: ((inputContext:
|
|
44
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
46
45
|
session: {
|
|
47
46
|
session: Record<string, any> & {
|
|
48
47
|
id: string;
|
|
@@ -114,13 +113,13 @@ declare const mcp: (options: MCPOptions) => {
|
|
|
114
113
|
}, {
|
|
115
114
|
redirectURI: string;
|
|
116
115
|
}>;
|
|
117
|
-
getMcpOAuthConfig:
|
|
116
|
+
getMcpOAuthConfig: import("better-call").StrictEndpoint<"/.well-known/oauth-authorization-server", {
|
|
118
117
|
method: "GET";
|
|
119
118
|
metadata: {
|
|
120
119
|
readonly scope: "server";
|
|
121
120
|
};
|
|
122
121
|
}, OIDCMetadata | null>;
|
|
123
|
-
getMCPProtectedResource:
|
|
122
|
+
getMCPProtectedResource: import("better-call").StrictEndpoint<"/.well-known/oauth-protected-resource", {
|
|
124
123
|
method: "GET";
|
|
125
124
|
metadata: {
|
|
126
125
|
readonly scope: "server";
|
|
@@ -133,7 +132,7 @@ declare const mcp: (options: MCPOptions) => {
|
|
|
133
132
|
bearer_methods_supported: string[];
|
|
134
133
|
resource_signing_alg_values_supported: string[];
|
|
135
134
|
}>;
|
|
136
|
-
mcpOAuthAuthorize:
|
|
135
|
+
mcpOAuthAuthorize: import("better-call").StrictEndpoint<"/mcp/authorize", {
|
|
137
136
|
method: "GET";
|
|
138
137
|
query: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
139
138
|
metadata: {
|
|
@@ -156,7 +155,7 @@ declare const mcp: (options: MCPOptions) => {
|
|
|
156
155
|
};
|
|
157
156
|
};
|
|
158
157
|
}, void>;
|
|
159
|
-
mcpOAuthToken:
|
|
158
|
+
mcpOAuthToken: import("better-call").StrictEndpoint<"/mcp/token", {
|
|
160
159
|
method: "POST";
|
|
161
160
|
body: z.ZodRecord<z.ZodAny, z.ZodAny>;
|
|
162
161
|
metadata: {
|
|
@@ -177,7 +176,7 @@ declare const mcp: (options: MCPOptions) => {
|
|
|
177
176
|
scope: string;
|
|
178
177
|
id_token: string | undefined;
|
|
179
178
|
}>;
|
|
180
|
-
registerMcpClient:
|
|
179
|
+
registerMcpClient: import("better-call").StrictEndpoint<"/mcp/register", {
|
|
181
180
|
method: "POST";
|
|
182
181
|
body: z.ZodObject<{
|
|
183
182
|
redirect_uris: z.ZodArray<z.ZodString>;
|
|
@@ -295,7 +294,7 @@ declare const mcp: (options: MCPOptions) => {
|
|
|
295
294
|
};
|
|
296
295
|
};
|
|
297
296
|
}, Response>;
|
|
298
|
-
getMcpSession:
|
|
297
|
+
getMcpSession: import("better-call").StrictEndpoint<"/mcp/get-session", {
|
|
299
298
|
method: "GET";
|
|
300
299
|
requireHeaders: true;
|
|
301
300
|
}, OAuthAccessToken | null>;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { MULTI_SESSION_ERROR_CODES } from "./error-codes.mjs";
|
|
2
2
|
import { MultiSessionConfig, multiSession } from "./index.mjs";
|
|
3
|
-
import * as _better_auth_core_utils_error_codes0 from "@better-auth/core/utils/error-codes";
|
|
4
|
-
|
|
5
3
|
//#region src/plugins/multi-session/client.d.ts
|
|
6
4
|
declare const multiSessionClient: () => {
|
|
7
5
|
id: "multi-session";
|
|
@@ -12,8 +10,8 @@ declare const multiSessionClient: () => {
|
|
|
12
10
|
signal: "$sessionSignal";
|
|
13
11
|
}[];
|
|
14
12
|
$ERROR_CODES: {
|
|
15
|
-
INVALID_SESSION_TOKEN:
|
|
13
|
+
INVALID_SESSION_TOKEN: import("@better-auth/core/utils/error-codes").RawError<"INVALID_SESSION_TOKEN">;
|
|
16
14
|
};
|
|
17
15
|
};
|
|
18
16
|
//#endregion
|
|
19
|
-
export { multiSessionClient };
|
|
17
|
+
export { MULTI_SESSION_ERROR_CODES, type MultiSessionConfig, multiSessionClient };
|