You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I made successful authentication, now user can able to login in my app. But the problem is once user loggs into the app no need to login again that is my requirement, so for this purpose i went through the document which is provided then i understood that using refreshToken i can get accessToken. But in the document refreshToken details are not mentioned.
Here is the code i used to get refreshToken----->
let auth = GTMAppAuthFetcherAuthorization.init(fromKeychainForName: keyChainForAccount)
if auth?.authState.refreshToken == nil {
// some perform segue methods i will call here
}
else{
auth?.authorizeRequest(nil, delegate: self, didFinish: #selector(LaunchViewController.auth(_:finishedRefreshWithFetcher:error:)))
}
func auth(_ auth: GTMAppAuthFetcherAuthorization, finishedRefreshWithFetcher fetcher: GTMSessionFetcher, error: NSError) {
//we come here if and only if we already have an account
if error._userInfo != nil {
self.displayDebugAlert("Error At line 482 with (error.userInfo)")
} else {
loadAuth(auth)
}
}
func loadAuth(_ auth: GTMAppAuthFetcherAuthorization) {
#if DEBUG
NSLog("fetch auth from google completed")
#endif
loadAccoutWithUserName(auth.userEmail!, password: nil, hostname: "imap.gmail.com", oauth2Token:"(String(describing: auth.authState.lastTokenResponse!.accessToken!))") . ////This line will takes me to the mailcore2 For fetching emails
}
How can i get accessToken Using refreshToken in GTMAppAuth Authorisation..........thanks in advance.
The text was updated successfully, but these errors were encountered:
You don't. You don't get use the refreshToken yourself, that's handled for you.
If your app is needing to re-auth every time, then probably you have not set the delegates of GTMAppAuthFetcherAuthorization.authState. The important one to implement is OIDAuthStateChangeDelegate -> in didChangeState:, make sure you save the state to the keychain again. Otherwise, what's happening is that the refresh token is being used automatically, but you are not saving it to disk, so the updated access token is never used.
I just found a bug in my code that caused the accessToken not to get refreshed using the refreshToken: I was manually using the token and not using GTMAppAuth to authorize my URLRequest. The codepath that refreshes the token is in the GTMAppAuth authorizeRequest: method. So, the fix was in the place where I want to use the token, to first call authorizeRequest: on a dummy NSMutableURLRequest that matches the scope of the initial OIDAuthorizationRequest's scope, which in my case is "https://mail.google.com/" because i'm sending mail via gmail.
Hi,
I made successful authentication, now user can able to login in my app. But the problem is once user loggs into the app no need to login again that is my requirement, so for this purpose i went through the document which is provided then i understood that using refreshToken i can get accessToken. But in the document refreshToken details are not mentioned.
Here is the code i used to get refreshToken----->
let auth = GTMAppAuthFetcherAuthorization.init(fromKeychainForName: keyChainForAccount)
if auth?.authState.refreshToken == nil {
// some perform segue methods i will call here
}
else{
auth?.authorizeRequest(nil, delegate: self, didFinish: #selector(LaunchViewController.auth(_:finishedRefreshWithFetcher:error:)))
}
func auth(_ auth: GTMAppAuthFetcherAuthorization, finishedRefreshWithFetcher fetcher: GTMSessionFetcher, error: NSError) {
//we come here if and only if we already have an account
if error._userInfo != nil {
self.displayDebugAlert("Error At line 482 with (error.userInfo)")
} else {
loadAuth(auth)
}
}
func loadAuth(_ auth: GTMAppAuthFetcherAuthorization) {
#if DEBUG
NSLog("fetch auth from google completed")
#endif
loadAccoutWithUserName(auth.userEmail!, password: nil, hostname: "imap.gmail.com", oauth2Token:"(String(describing: auth.authState.lastTokenResponse!.accessToken!))") . ////This line will takes me to the mailcore2 For fetching emails
}
How can i get accessToken Using refreshToken in GTMAppAuth Authorisation..........thanks in advance.
The text was updated successfully, but these errors were encountered: