Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.
Gen1 DocsLegacy

Page updated Jun 24, 2025

WebAuthn認証器の管理

Amplify Authはパスキーをカメラルートンの認証情報メカニズムとして使用しています。以下のAPIにより、ユーザーはCognitoアカウントに関連付けられたパスキーを登録、追跡、削除できます。

Amplifyでのパスキーの使用詳細を学習

WebAuthn認証器の関連付け

ユーザーがパスキーを登録するには認証されている必要があることに注意してください。これはユーザーがサインアップ中にパスキーを作成できないことも意味します。したがって、WebAuthnを使用するにはアカウントに関連付けられた少なくとも1つの他の第一要因認証メカニズムが必要です。

以下のAPIを使用してパスキーを関連付けることができます:

func associateWebAuthNCredentials() async {
do {
try await Amplify.Auth.associateWebAuthnCredential()
print("WebAuthn credential was associated")
} catch {
print("Associate WebAuthn Credential failed: \(error)")
}
}
func associateWebAuthNCredentials() -> AnyCancellable {
Amplify.Publisher.create {
try await Amplify.Auth.associateWebAuthnCredential()
}.sink {
print("Associate WebAuthn Credential failed: \($0)")
}
receiveValue: { _ in
print("WebAuthn credential was associated")
}
}

ユーザーはローカル認証器を使用してパスキーを登録するように促されます。その後、AmplifyはそのパスキーをCognitoに関連付けます。

WebAuthn認証器の一覧表示

以下のAPIを使用して登録済みのパスキーを一覧表示できます:

func listWebAuthNCredentials() async {
do {
let result = try await Amplify.Auth.listWebAuthnCredentials(
options: .init(pageSize: 5))
for credential in result.credentials {
print("Credential ID: \(credential.credentialId)")
print("Created At: \(credential.createdAt)")
print("Relying Party Id: \(credential.relyingPartyId)")
if let friendlyName = credential.friendlyName {
print("Friendly name: \(friendlyName)")
}
}
// Fetch the next page
if let nextToken = result.nextToken {
let nextResult = try await Amplify.Auth.listWebAuthnCredentials(
options: .init(
pageSize: 5,
nextToken: nextToken))
}
} catch {
print("Associate WebAuthn Credential failed: \(error)")
}
}
func listWebAuthNCredentials() -> AnyCancellable {
Amplify.Publisher.create {
try await Amplify.Auth.listWebAuthnCredentials(
options: .init(pageSize: 5))
}.sink {
print("List WebAuthn Credential failed: \($0)")
}
receiveValue: { result in
for credential in result.credentials {
print("Credential ID: \(credential.credentialId)")
print("Created At: \(credential.createdAt)")
print("Relying Party Id: \(credential.relyingPartyId)")
if let friendlyName = credential.friendlyName {
print("Friendly name: \(friendlyName)")
}
}
if let nextToken = result.nextToken {
// Fetch the next page
}
}
}

WebAuthn認証器の削除

以下のAPIでパスキーを削除できます:

func deleteWebAuthNCredentials(credentialId: String) async {
do {
try await Amplify.Auth.deleteWebAuthnCredential(credentialId: credentialId)
print("WebAuthn credential was deleted")
} catch {
print("Delete WebAuthn Credential failed: \(error)")
}
}
func deleteWebAuthNCredentials(credentialId: String) -> AnyCancellable {
Amplify.Publisher.create {
try await Amplify.Auth.deleteWebAuthnCredential(credentialId: credentialId)
}.sink {
print("Delete WebAuthn Credential failed: \($0)")
}
receiveValue: { _ in
print("WebAuthn credential was deleted")
}
}