Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How To Get Refresh Token on Both IOS and Android #425

Closed
deejaygeroso opened this issue Jun 18, 2018 · 6 comments
Closed

How To Get Refresh Token on Both IOS and Android #425

deejaygeroso opened this issue Jun 18, 2018 · 6 comments
Labels

Comments

@deejaygeroso
Copy link

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
@thomasw
Copy link
Contributor

thomasw commented Jul 2, 2018

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?

@anton128
Copy link

anton128 commented Aug 6, 2018

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.

@Esxiel
Copy link

Esxiel commented Aug 29, 2018

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.

@vonovak
Copy link
Member

vonovak commented Aug 29, 2018

@Esxiel
Copy link

Esxiel commented Aug 29, 2018

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.

@webdevfarhan
Copy link

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_token that will be valid for 1 hour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants