Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I test refreshing my google access token using a refresh token

I am a fair way through implementing an actionscript OAuth library which I am initially testing with Google's Drive Api.

I know how you are supposed to refresh an access token using your refresh token but my question is how do I test it?

How do I make my access_token expire so that I test my code that catches the error, attempts a refresh and then re-loads the initial request? If I can only do this once a week (or however often they expire) it's going to take a while to get it right!

Thanks

like image 915
Roaders Avatar asked Dec 23 '13 14:12

Roaders


People also ask

How do I know if my refresh token is working?

If you're looking to test your code, you don't actually need to invalidate or expire the access token. Simply make a (say) Drive call with a null access token and you will receive the same 401 response that you would have got with an expired access token. Ok, thanks.

How do I use Google refresh token?

To use the refresh token, make a POST request to the service's token endpoint with grant_type=refresh_token , and include the refresh token as well as the client credentials if required.

How do I update my access token with refresh token?

Using a Refresh 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 .

How do I verify my Google access token?

After you receive the ID token by HTTPS POST, you must verify the integrity of the token. To verify that the token is valid, ensure that the following criteria are satisfied: The ID token is properly signed by Google. Use Google's public keys (available in JWK or PEM format) to verify the token's signature.


4 Answers

Well, judging by the lack of responses to this question I am assuming that there is no way to do this.

This page: https://developers.google.com/youtube/v3/guides/authentication#installed-apps

describes how to revoke an access or refresh token by using this url:

https://accounts.google.com/o/oauth2/revoke?token={token}

but then says:

The specified token can be an access token or a refresh token. If the token is an access token and it has a corresponding refresh token, the refresh token is also revoked.

So if you just want to revoke an access token you aren't able to.

I think the only solution is to wait for the access token to expire (seems to take an hour) then go about testing your app.

I'll be very happy if anyone tells me a faster way to make the token expire.

like image 148
Roaders Avatar answered Oct 25 '22 17:10

Roaders


I handle this testing by simply making note of an expired access_token. Then when I need to test how my app deals with an expired token I simply give the app that expired token to work with. This way, for example, I can test that requests with an expired token will fail as expected.

like image 39
Mike O Avatar answered Oct 25 '22 17:10

Mike O


The easiest way of doing it is using the OAuth Playground 2.0

https://developers.google.com/oauthplayground/

In step 2 especially, you can try refreshing your access token with a refresh token.

Additionally, in the setting (the gear icon), you can set up your own OAuth Credentials to test it out for your own API project.

like image 35
Emily Avatar answered Oct 25 '22 16:10

Emily


If you're looking to test your code, you don't actually need to invalidate or expire the access token. Simply make a (say) Drive call with a null access token and you will receive the same 401 response that you would have got with an expired access token.

like image 25
pinoyyid Avatar answered Oct 25 '22 15:10

pinoyyid