[iOS15, SwiftUI, AWS Amplify]
I'm using a
SignInWithAppleButton(
.signIn,
onRequest: configure,
onCompletion: handle
)
.signInWithAppleButtonStyle(.white)
.frame(height: 44.0)
.clipShape(Capsule(style: .continuous)
)
to call a handle function, that calls this signIn function:
func signIn(with identityToken: String) {
guard
let plugin = try? Amplify.Auth.getPlugin(for: AWSCognitoAuthPlugin().key),
let authPlugin = plugin as? AWSCognitoAuthPlugin,
case .awsMobileClient(let client) = authPlugin.getEscapeHatch()
else {
return
}
client.federatedSignIn(
providerName: "signInWithApple",
token: identityToken) { state, error in
if let unwrappedError = error {
print("Error in federatedSignIn: \(unwrappedError)")
return
}
guard let unwrappedState = state else {
print("userState unexpectedly nil")
return
}
print("Successful federated sign in:", unwrappedState)
}
}
}
The console prints Successful federated sign in: signedIn, but when I check the User Pool in AWS Amplify Admin UI or AWS Cognito, it is empty.
AWS Admin UI:

AWS Cognito -> User Pools -> Federated Identities:

Any ideas what I may be doing wrong?
Debugging HTTP traffic, I found out there was an error message that is not returned by client.federatedSignIn(). The error indicated the identity token did not match the provider, so I decided to try with several different options for the provider name, and the one that works is: appleid.apple.com.
client.federatedSignIn(
providerName: "appleid.apple.com",
token: identityToken)
or
import AWSMobileClientXCF
...
client.federatedSignIn(
providerName: IdentityProvider.apple.rawValue,
token: identityToken)
Doing further research I also found out a user is not created in the User Pools when using federated sign in. This only happens if using credentials sign in, or social sign in using Hosted UI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With