providers/webauthn
WebAuthnConfig
在所有 ProviderType 中共享
扩展
属性
authenticationOptions?
optional authenticationOptions: Partial<ConfigurableAuthenticationOptions>;传递给
Simplewebauthn
的认证选项。
enableConditionalUI
enableConditionalUI: boolean;启用条件 UI。
注意:一次只能启用一个提供者此选项。默认为 true。
formFields
formFields: Record<string, CredentialInput>;在默认的 Passkey 登录/注册表单中显示的表单字段。这些字段不会在默认的 Auth.js 身份验证页面之外进行验证或强制执行。
默认情况下,它会显示一个电子邮件字段。
getRelayingParty()
getRelayingParty: (options, request) => RelayingParty;返回当前请求的转发方函数。
参数
| 参数 | 类型 |
|---|---|
options | InternalOptions<"webauthn"> |
request | RequestInternal |
返回值
getUserInfo
getUserInfo: GetUserInfo;返回身份验证器在注册和身份验证期间使用的用户信息的函数。
- 它接受提供者选项、请求对象并返回用户信息。
- 如果请求包含现有用户的數據(例如电子邮件地址),则该函数必须返回现有用户,并且
exists必须为true。 - 如果请求包含足够的信息来创建新用户,则该函数必须返回新用户信息,并且
exists必须为false。 - 如果请求不包含足够的信息来创建新用户,则该函数必须返回
null。
它不应该有任何副作用(即它不应该修改数据库)。
在创建 passkey 期间
- passkey 的用户 ID 将是一个随机字符串。
- passkey 的用户名将是 user.email
- passkey 的用户显示名称将是 user.name(如果存在),否则是 user.email
默认情况下,它会查找并使用“email”请求参数在数据库中查找用户。
id
id: string;在 AuthConfig.providers 中唯一标识提供者。它也是 URL 的一部分
继承自
name
name: string;在默认登录页面登录按钮上使用的提供者名称。例如,如果它是“Google”,则相应的按钮将显示:“使用 Google 登录”
继承自
registrationOptions
registrationOptions: Partial<ConfigurableRegistrationOptions>;传递给
Simplewebauthn
的注册选项。
relayingParty?
optional relayingParty: Partial<RelayingPartyArray>;转发方(RP)配置
如果未提供,则将使用请求 URL。
simpleWebAuthn
simpleWebAuthn: {
generateAuthenticationOptions: (options?) => Promise<PublicKeyCredentialRequestOptionsJSON>;
generateRegistrationOptions: (options) => Promise<PublicKeyCredentialCreationOptionsJSON>;
verifyAuthenticationResponse: (options) => Promise<VerifiedAuthenticationResponse>;
verifyRegistrationResponse: (options) => Promise<VerifiedRegistrationResponse>;
};用于注册和身份验证的 SimpleWebAuthn 实例。
generateAuthenticationOptions()
generateAuthenticationOptions: (options?) => Promise<PublicKeyCredentialRequestOptionsJSON>;准备一个要传递给 navigator.credentials.get(…) 的值,以供身份验证器“登录”
参数
| 参数 | 类型 |
|---|---|
options? | GenerateAuthenticationOptionsOpts |
返回值
Promise<PublicKeyCredentialRequestOptionsJSON>
generateRegistrationOptions()
generateRegistrationOptions: (options) => Promise<PublicKeyCredentialCreationOptionsJSON>;准备一个要传递给 navigator.credentials.create(…) 的值,以供身份验证器“注册”
选项
参数
| 参数 | 类型 |
|---|---|
options | GenerateRegistrationOptionsOpts |
返回值
Promise<PublicKeyCredentialCreationOptionsJSON>
verifyAuthenticationResponse()
verifyAuthenticationResponse: (options) => Promise<VerifiedAuthenticationResponse>;验证用户是否已合法完成登录过程
选项
参数
| 参数 | 类型 |
|---|---|
options | VerifyAuthenticationResponseOpts |
返回值
Promise<VerifiedAuthenticationResponse>
verifyRegistrationResponse()
verifyRegistrationResponse: (options) => Promise<VerifiedRegistrationResponse>;验证用户是否已合法完成注册过程
选项
参数
| 参数 | 类型 |
|---|---|
options | VerifyRegistrationResponseOpts |
返回值
Promise<VerifiedRegistrationResponse>
simpleWebAuthnBrowserVersion
simpleWebAuthnBrowserVersion: false | SemverString;在登录页面加载的 SimpleWebAuthn 浏览器脚本版本。
仅当提供者启用了条件 UI 时才会加载此脚本。如果设置为 false,则不会加载任何脚本。默认为 v9.0.0。
类型
type: "webauthn";请参阅 ProviderType
覆盖
verifyAuthenticationOptions?
optional verifyAuthenticationOptions: Partial<ConfigurableVerifyAuthenticationOptions>;传递给
Simplewebauthn
的认证选项。
的验证身份验证选项
optional verifyRegistrationOptions: Partial<ConfigurableVerifyRegistrationOptions>;传递给
的注册选项。
Simplewebauthn
type GetUserInfo: (options, request) => Promise<{
exists: true;
user: User;
} | {
exists: false;
user: Omit<User, "id">;
} | null>;的验证注册选项
| 参数 | 类型 |
|---|---|
options | GetUserInfo() |
request | RequestInternal |
参数
InternalOptions<WebAuthnProviderType>
返回值
type RelayingParty: {
id: string;
name: string;
origin: string;
};Promise<{ exists: true; user: User; } | { exists: false; user: Omit<User, "id">; } | null>
RelayingParty
id: string;id
name: string;中继方 ID。使用网站的域名。
name
origin: string;中继方名称。使用网站的名称。
origin
type WebAuthnProviderType: "webauthn";中继方来源。使用网站的来源。
const DEFAULT_SIMPLEWEBAUTHN_BROWSER_VERSION: SemverString = "v9.0.1";WebAuthnProviderType
const DEFAULT_WEBAUTHN_TIMEOUT: number;DEFAULT_SIMPLEWEBAUTHN_BROWSER_VERSION
default(config): WebAuthnConfigdefault()
在您的页面中添加 WebAuthn 登录。
import { Auth } from "@auth/core"
import WebAuthn from "@auth/core/providers/webauthn"
const request = new Request(origin)
const response = await Auth(request, {
providers: [WebAuthn],
})设置
源代码
💡
WebAuthn 提供者附带一个 默认配置。要覆盖您的用例的默认设置,请查看 自定义内置 WebAuthn 提供者。
免责声明 如果您认为在默认配置中发现了一个错误,可以 打开一个问题。
| 参数 | 类型 |
|---|---|
Auth.js 严格遵守规范,因此不承担提供者偏离规范的任何责任。您可以打开一个问题,但如果问题是非遵守规范,我们可能不会寻求解决。您可以在 Discussions 中寻求更多帮助。 | 参数 |