providers/webauthn
WebAuthnConfig
在所有 ProviderType 中共享
繼承
屬性
authenticationOptions?
optional authenticationOptions: Partial<ConfigurableAuthenticationOptions>;
傳遞給的身份驗證選項
Simplewebauthn
在身份驗證期間。
enableConditionalUI
enableConditionalUI: boolean;
啟用條件式 UI。
注意:一次只能啟用一個供應商的此選項。預設為 true
。
formFields
formFields: Record<string, CredentialInput>;
在預設的密碼金鑰登入/註冊表單中顯示的表單欄位。除了預設的 Auth.js 身份驗證頁面之外,這些欄位不會經過驗證或強制執行。
預設情況下,它會顯示電子郵件欄位。
getRelayingParty()
getRelayingParty: (options, request) => RelayingParty;
返回目前請求的依賴方功能的函式。
參數
參數 | 類型 |
---|---|
options | InternalOptions <"webauthn" > |
request | RequestInternal |
回傳
getUserInfo
getUserInfo: GetUserInfo;
返回驗證器在註冊和身份驗證期間將使用的使用者資訊的函式。
- 它接受供應商選項、請求物件,並返回使用者資訊。
- 如果請求包含現有使用者的資料(例如電子郵件地址),則函式必須返回現有使用者,且
exists
必須為true
。 - 如果請求包含足夠的資訊來建立新使用者,則函式必須返回新的使用者資訊,且
exists
必須為false
。 - 如果請求未包含足夠的資訊來建立新使用者,則函式必須返回
null
。
它不應有任何副作用(即不應修改資料庫)。
在建立密碼金鑰期間
- 密碼金鑰的使用者 ID 將是一個隨機字串。
- 密碼金鑰的使用者名稱將為 user.email
- 密碼金鑰的使用者顯示名稱將為 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>;
準備一個值,以便傳遞到導覽器。憑證。get(…) 以進行驗證器「登入」
參數
參數 | 類型 |
---|---|
options ? | GenerateAuthenticationOptionsOpts |
回傳
Promise
<PublicKeyCredentialRequestOptionsJSON
>
generateRegistrationOptions()
generateRegistrationOptions: (options) => Promise<PublicKeyCredentialCreationOptionsJSON>;
準備一個值,以便傳遞到導覽器。憑證。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
type: "webauthn";
請參閱 ProviderType
覆寫
verifyAuthenticationOptions?
optional verifyAuthenticationOptions: Partial<ConfigurableVerifyAuthenticationOptions>;
傳遞給 Simplewebauthn 的驗證選項
Simplewebauthn
在身份驗證期間。
verifyRegistrationOptions?
optional verifyRegistrationOptions: Partial<ConfigurableVerifyRegistrationOptions>;
傳遞給 Simplewebauthn 的註冊選項
Simplewebauthn
在註冊期間。
GetUserInfo()
type GetUserInfo: (options, request) => Promise<{
exists: true;
user: User;
} | {
exists: false;
user: Omit<User, "id">;
} | null>;
參數
參數 | 類型 |
---|---|
options | InternalOptions <WebAuthnProviderType > |
request | RequestInternal |
回傳值
Promise
<{ exists
: true
; user
: User
; } | { exists
: false
; user
: Omit
<User
, "id"
>; } | null
>
RelayingParty
type RelayingParty: {
id: string;
name: string;
origin: string;
};
類型宣告
id
id: string;
依賴方 ID。使用網站的網域名稱。
name
name: string;
依賴方名稱。使用網站的名稱。
origin
origin: string;
依賴方來源。使用網站的來源。
WebAuthnProviderType
type WebAuthnProviderType: "webauthn";
DEFAULT_SIMPLEWEBAUTHN_BROWSER_VERSION
const DEFAULT_SIMPLEWEBAUTHN_BROWSER_VERSION: SemverString = "v9.0.1";
DEFAULT_WEBAUTHN_TIMEOUT
const DEFAULT_WEBAUTHN_TIMEOUT: number;
default()
default(config): WebAuthnConfig
在您的頁面中加入 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 供應商。
參數
參數 | 類型 |
---|---|
config | Partial <WebAuthnConfig > |