Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh Google API access token with Expo SDK?

I've followed the guide Google login / Expo and got both access token and refresh token.

But after access token expiring I can't get the new token.

When I try to get new one I get this error:

"error": "unauthorized_client", "error_description": "Unauthorized"

Here is the sample of the sent request for getting the new access token (Google docs):

    POST /oauth2/v4/token HTTP/1.1
    Host: www.googleapis.com
    Content-Type: application/x-www-form-urlencoded

    client_id=<your_client_id>&
    client_secret=<your_client_secret>&
    refresh_token=<refresh_token>&
    grant_type=refresh_token

P.S. I did not forget to replace client_id and other relevant data.

like image 832
ljmocic Avatar asked Apr 11 '18 17:04

ljmocic


People also ask

How do I refresh my access token?

To refresh the access token, select the Refresh access token API call within the Authorization folder of the Postman collection. Next, click the Send button to request a new access_token .

Can you refresh a refresh token?

To refresh your access token as well as an ID token, you send a token request with a grant_type of refresh_token . Be sure to include the openid scope when you want to refresh the ID token. If the refresh token is valid, then you get back a new access and the refresh token.

Does Google API refresh token expire?

The refresh token is set with a very long expiration time of 200 days. If the traffic to this API is 10 requests/second, then it can generate as many as 864,000 tokens in a day.


1 Answers

The same client ID that got the refresh token must be used to get another access token!

You are probably using this code on Android, for mobile devices Google doesn't give you a secret since it is not needed. You can remove the secret from the request and change the client ID to match your mobile client ID.

like image 132
eyalyoli Avatar answered Oct 23 '22 19:10

eyalyoli