I have this function that is from the AppAuth examples, I realised that in iOS13 I don't really need to store the return value for the OIDAuthState.authState, so I tried to clean up the code by removing the appDelegate.currentAuthorizationFlow =, but once I remove that, the callback doesn't gets called anymore. And this currentAuthorizationFlow is not used anywhere else in the code.
I have also tried assigning the result of OIDAuthState.authState to a function local variable, where the call back also will not be called.
If I assign the results of OIDAuthState.authState to a class member variable in the current class, then the call back will be called.
Why is the behaviour as such? It seems very baffling to me.
func signInGmail() {
let redirectURI = URL(string: gmail_kRedirectURI)!
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let config = GTMAppAuthFetcherAuthorization.configurationForGoogle()
let scopes = [OIDScopeOpenID, OIDScopeProfile, OIDScopeEmail, kGTLRAuthScopeGmailReadonly]
let request = OIDAuthorizationRequest.init(configuration: config, clientId: gmail_kClientID, scopes: scopes, redirectURL: redirectURI, responseType: OIDResponseTypeCode, additionalParameters: nil)
appDelegate.currentAuthorizationFlow = OIDAuthState.authState(byPresenting: request, presenting: self, callback: { (authState, error) in
//handleError
if let authState = authState {
let authorizer = GTMAppAuthFetcherAuthorization(authState: authState)
self.pickGmailLabels(authorizer: authorizer)
}
})
}