在本地主机上运行 Vapor 应用程序,并尝试使用 iPhone 模拟器使用 Passkey 进行身份验证时,
authorizationController(controller:didCompleteWithError:)
委托方法会触发此错误:
["NSLocalizedFailureReason": Application with identifier <APP_BUNDLE_ID> is not associated with domain localhost:8080]
Vapor项目的设置是:
https://localhost:8080
/.well-known/apple-app-site-association
文件正在通过(Vapor/RouteLoggingMiddleware.swift:14)
到达。{
"applinks": {
"details": [
{
"appIDs": ["<APP_BUNDLE_ID>"],
"components": []
}
]
},
"webcredentials": {
"apps": ["<APP_BUNDLE_ID>"]
}
}
与服务器的通信正常,因为我可以看到从 iPhone 模拟器请求中收到了用户的
username
。请求发回 userID
和 Challenge
以使用 Passkey 进行身份验证。
iOS项目上的设置是:
webcredentials:localhost:8080?mode=developer
创建密码认证的代码:
func authenticate(with email: String) async throws {
let publicKeyProvider = ASAuthorizationPlatformPublicKeyCredentialProvider(
relyingPartyIdentifier: "localhost:8080"
)
// The authentication request to receive the `userID` and `Challenge`.
// This part is sucessful.
let authenticationData = AuthenticationData(email: email)
let urlRequest = try urlRequest(with: authenticationData, atEndpoint: .authentication)
let data = try await serverCall(for: PublicAuthKeyData.self, on: urlRequest)
let registrationRequest = publicKeyProvider.createCredentialRegistrationRequest(
challenge: data.challenge.decodeBase64(),
name: email,
userID: data.userID.decodeBase64()
)
let authController = ASAuthorizationController(
authorizationRequests: [registrationRequest]
)
authController.delegate = self
authController.presentationContextProvider = self
authController.performRequests()
}
从那里,
authorizationController(controller:didCompleteWithError:)
触发错误Domain=com.apple.AuthenticationServices.AuthorizationError Code=1004