Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User is not created in AWS Amplify User Pool using federated sign in

[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:

User Management

AWS Cognito -> User Pools -> Federated Identities:

Federated Identities

Any ideas what I may be doing wrong?

like image 488
Ecil Avatar asked Oct 15 '25 08:10

Ecil


1 Answers

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.

like image 196
Ecil Avatar answered Oct 16 '25 22:10

Ecil