I am trying to implement a 'Sign In with Apple'. I can sign in easily with accounts that I've made with the password credentials, but I am unable to get access to the users email and name in the ASAuthorizationAppleIDCredential, how can I get access to these fields and an auto generated password so that users can signup without the hassle?
@objc private func appleSignInPressed() {
let provider = ASAuthorizationAppleIDProvider()
let request = provider.createRequest()
request.requestedScopes = [.email, .fullName]
let requests = [request, ASAuthorizationPasswordProvider().createRequest()]
let controller = ASAuthorizationController(authorizationRequests: requests)
controller.delegate = self
controller.presentationContextProvider = self
controller.performRequests()
}
extension WelcomeViewController: ASAuthorizationControllerDelegate {
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
switch authorization.credential {
case let passwordCredential as ASPasswordCredential:
let username = passwordCredential.user
let password = passwordCredential.password
viewModel.didTouchLoginButton(with: username, and: password, feeds: [], referralLink: nil)
case let credentials as ASAuthorizationAppleIDCredential:
let fullName = credentials.fullName?.givenName
let email = credentials.email
SignupManager.shared.email = email
SignupManager.shared.username = fullName
print("HERE HERE: \(credentials.fullName)")
print("HERE HERE: \(credentials.email)")
startSignUpFlow()
default:
startSignUpFlow()
}
}
}
prints:
HERE HERE: Optional()
HERE HERE: nil
After clicking Sign In with Apple -> Apple ID