Looking for how to use this in your app?See Frontend Libraries →
WebAuthn認証器の管理
Amplify Authはパスキーをカメラルートンの認証情報メカニズムとして使用しています。以下のAPIにより、ユーザーはCognitoアカウントに関連付けられたパスキーを登録、追跡、削除できます。
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") }}