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