Need password to create account using apple SignIn

I have an API that in order to create accounts, I need name, last, email and password. So after creating the account, a user can log in with existing email and password.


When using Apple Sign we rely on this delegate

    func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
     if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
            // Create an account in your system.
            appleUserID = appleIDCredential.user
            let userFirstName = appleIDCredential.fullName?.givenName
            let userLastName = appleIDCredential.fullName?.familyName
            let userEmail = appleIDCredential.email


            //Navigate to other view controller
        }else if let passwordCredential = authorization.credential as? ASPasswordCredential {
            // Sign in using an existing iCloud Keychain credential.
            let username = passwordCredential.user
            let password = passwordCredential.password
            
            //Navigate to other view controller
        }
    }


now the first time it should go to the first if condition where you get email, first and last. However, for my case I also need to set a password in order to create an account.


In addition, for the second time, we can check a user is already Signin by calling this code

         let requests = [ASAuthorizationAppleIDProvider().createRequest(),
                            ASAuthorizationPasswordProvider().createRequest()]
            
            // Create an authorization controller with the given requests.
            let authorizationController = ASAuthorizationController(authorizationRequests: requests)
            authorizationController.delegate = self
            authorizationController.presentationContextProvider = self
            authorizationController.performRequests()


then the delegate is called and hopefully the second if part "}else if let passwordCredential = authorization.credential as? ASPasswordCredential {" at this point I should have a user and a password. but what about the email? and the what about the password the first time?


In summary, here are the Questions:


1.) How do I get a password for the first time user did apple Sign in so I can create a new account, so then the second time I want to signin, I can user email and password.

2.) How do I get the email the second time, so I can sign to my API with email and password.

3.) Caching the responses from the first time we create the account with Apple Sing in is useless if the user deletes the app, because after the second time, we only get userID, while mail, first and last are always nil. How can I get this values again for a user that deleted the app and kill my local cache?


Thanks

Hi jhoda12,


Answering your questions in order:


1. SIWA does not have passwords. The clients should instead rely on the tokens / identifiers our API returns to create a session in their own systems. It is possible to prompt the user afterwards if they would like to create a username/password in your systems, but there is no support for this out of the box and ideally the user wouldn't have to.


2. There is no way to get an email second time through the native API today. This informaiton should not be used to authenticate the user, instead you should check the credential state via ASAuthorizationPasswordProvider.


3. You can not get the values again after the initial share, only the userID & tokens will be shared after initial account creation, but no name or email.

Hey Dima,

What all exactly is returned on subsequent uses of SiwA as part of the ASAuthorizationAppleIDCredential? From another thread I concluded it was only the `user` attribute, but yesterday you made a post stating that it is now both `user` and `email`. Here you say that the JWA token will also be a part of the subsequent return payloads. I've been looking for a definitive answer on what exactly we'll get back and haven't been able to find any conclusive information. I don't have an iOS13 device to test with myself so I'm trying to get the code where I think it needs to be before it hits QA.


Thanks for your time!

Need password to create account using apple SignIn
 
 
Q