I am using Google's GTMOAuth for iOS/Mac SDK in order to be able to connect with APIS such as YouTube API and Instagram API. It all works fine, however when the user authenticates, I can only get access token. This is all well and good, but after a while the access tokens expire and the user has to re-login which is awful.
My problem is that when the user authenticates, I ONLY GET back an access token and nothing else...
Thanks for you're help :)
You can also use the GTMOAuth2Authentication´s
authorizeRequest:completionHandler:
methodIf your application saves the authorization to the keychain (by setting the controller's keychainItemName), it can be retrieved the next time the application launches:
and then you can refresh the access token like this:
The token will be then refreshed and you can keep making queries.
May be this one help you..!
I am using Google oauth 2.0, for google drive authentication.
In the Google finished with authentication method save the accesstoken and refresh token values in NSUSerDefaults like this.
After that when ever you want to use the acces token for performing api call first make a call using existing accesstoken value from the NSUSERDefaults, after that in the url response check the status code. If you are getting status code '401' means your access token is expired, and not valid. Then you have to request for refresh token using saved refresh token value in NSUserDefaults like this.
This is your first api call to check accesstoken valid or not.
This is for request new accesstoken from refresh token.
In response check for status code again and if status code is 200.Then update the value in userdafaults.
This is my first answer on stack overflow. Sorry for any mistakes.
UPDATE BELOW - Written by Supertecnoboff
Also keep this in mind. For some API's such as Google, you need to add "approval_prompt=force" and "access_type=offline" if you want it to give you a refresh token. In order to add these parameters, you have to edit the GTMOAuth2SignIn.m file and replace the "paramsDict" with this NSMutableDictionary: