when identityToken or authorizationCode is nil??

I wrote as follows.

An error occurred on line 14 because of forced unwrapping.

Code Block
extension SignInViewController: ASAuthorizationControllerDelegate {
@available(iOS 13.0, *)
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
var name: String? = nil
if let appleIDCredential = authorization.credential as?
ASAuthorizationAppleIDCredential {
if let fname = appleIDCredential.fullName?.familyName { name = fname }
if let gname = appleIDCredential.fullName?.givenName {name = name == nil ? gname : name!+gname}
authenticateWithApple(token:
appleIDCredential.identityToken?.toString, code: appleIDCredential.authorizationCode?.toString, name: name)
}
}
func authenticateWithApple(token: String?, code: String?, name: String?) {
authenticationScenario.signOut(from: .apple)
let param = [LQAAccountAppleTokenKey:token!, LQAAccountAppleAuthorizationCode:code!]
...
}
}


I fixed it by rewriting as below, but I would like to know why nil is included in identityToken or authorizationCode.

Code Block
guard let identityToken = appleIDCredential.identityToken, let idTokenString = String(data: identityToken, encoding: .utf8) else { return }
guard let authorizationCode = appleIDCredential.authorizationCode, let authCodeString = String(data: authorizationCode, encoding: .utf8) else { return }

Quite an old question, but I'll try to answer it for others even if OP have already figured it out.

There is no code of requesting the sign-in flow posted, so I'll just assume that OP combined 2 types of request like it is described in Documentation

  let requests = [ASAuthorizationAppleIDProvider().createRequest(),
                    ASAuthorizationPasswordProvider().createRequest()]

Doing this results in no authorizationCode being returned (or actually returned as nil) in ASAuthorizationAppleIDCredential

As for why this happens? Good question I do not know the answer yet.

when identityToken or authorizationCode is nil??
 
 
Q