Google-signin: How To Get Refresh Token on Both IOS and Android

Created on 18 Jun 2018  路  6Comments  路  Source: react-native-google-signin/google-signin

Is it possible to get Refresh Token on this package?? Apparently it is not included on the documentation so I'm assuming it is not configured to get refresh token.

And also is it also possible to get expiration date for access token on Android?? I've read that it is only available on IOS.

Environment

  • react-native : 0.55.0
  • react-native-google-signin : 0.12.0
  • react : 16.3.0-alpha.0
Question

Most helpful comment

Thanks for the quick reply! I sent the serverAuthCode in a request and I only got a new accessToken.

I tried some other things and I've just remembered that I can only get a refreshToken on the first request.

I got the refreshToken when I send the serverAuthCode immediately on the first authentication.


For people reading this in the future,
This happened to me while I'm testing around, I had to delete my permissions and re-authenticate.
See : https://stackoverflow.com/questions/10827920/not-receiving-google-oauth-refresh-token
Exchange your serverAuthCode for refreshToken as of Step 5 in:
https://developers.google.com/identity/protocols/OAuth2InstalledApp#exchange-authorization-code
Try it out with code, client_id, client_secret, and grant_type.

All 6 comments

I might be able to answer this question if you can provide some context about what you're trying to achieve. Are you looking for a refresh token because you're trying to do some offline API access, server-side perhaps?

I also have this problem. I am using google contact api v3 to get contact list(name, photo).
To get contact photo, I need access_Token, but it is expired soon.
How can I get refresh_token to access Google api when I need?

https://www.google.com/m8/feeds/photos/media/*%40gmail.com/1a1ce810cd9d161/1B2M2Y8AsgTpgAmY7PhCfg
I get this url from google contact api.

I'm also facing the same problem, I'm wondering why I do not receive a refreshToken. Just like the post above, I'm looking for the refresh token in order to refresh to access token when it has been checked to be expired.

Thanks for the quick reply! I sent the serverAuthCode in a request and I only got a new accessToken.

I tried some other things and I've just remembered that I can only get a refreshToken on the first request.

I got the refreshToken when I send the serverAuthCode immediately on the first authentication.


For people reading this in the future,
This happened to me while I'm testing around, I had to delete my permissions and re-authenticate.
See : https://stackoverflow.com/questions/10827920/not-receiving-google-oauth-refresh-token
Exchange your serverAuthCode for refreshToken as of Step 5 in:
https://developers.google.com/identity/protocols/OAuth2InstalledApp#exchange-authorization-code
Try it out with code, client_id, client_secret, and grant_type.

Just for clearity, the access token you will receive from GoogleSignin.getTokens(); will only last for about an hour, to get a new access_token we need to send serverAuthCode to https://oauth2.googleapis.com/token with fields : client_id, client_secret, code(this is serverAuthCode), grant_type(its value should be authorization_code), redirect_uri(can set it from developers console). Remember to only use the serverAuthCode that you get on your first attempt when you just allowed your app for the permissions FIRST TIME otherwise you will get grant_error every time. After getting the refresh_token, we need to get the new access_token using refresh token that we just got, so now just replace the value of grant_type from authorization_code to refresh_token and also replace the value of code field to refresh_token , fill its value and send a post request to the same url, you will get a fresh access_tokenthat will be valid for 1 hour.

Was this page helpful?
0 / 5 - 0 ratings