Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GoogleAPI oauth2 refresh token expires in 1 hour

I am using Google APIs in my application and the oauth2 refresh token expires after 1 hour. I am using this refresh token to execute a task which runs daily. I create the refresh token using the OAuth2 playground. Is there a way to extend the expiration time of a refresh token? (1 month)

like image 888
Madhuka Wickramapala Avatar asked Oct 01 '18 06:10

Madhuka Wickramapala


2 Answers

I think that you have your terms confused here.

As per Oauth2 access tokens expire after one hour. Access tokens are used to request access of an api and return the data that you need. There is no way to extend the lifetime of an access token beyond one hour. You need to use a refresh token to request a new access token.

Refresh tokens are extremely long lived and do not normally expire. Refresh tokens are used to request a new access token. Refresh tokens for the most part do not expire if one is not used in six months though google will automatically expire it. Also if the user removes your access then the refresh token will also automatically expire.

If you are creating your refresh token using the Outh2 playground which is intended only for testing purposes it will also expire.

If you are using the oauth2 playground to create your refresh token then you should not be doing this you should be creating your own application to request the tokens.

like image 179
DaImTo Avatar answered Oct 02 '22 19:10

DaImTo


As already explained the refresh tokens created using the OAuth 2.0 Playground are automatically revoked after a few hours because the playground is mainly for testing purposes. However you can configure the OAuth playground to use your own app credentials (use the 'wheely' icon top right). If you use your own app credentials the refresh token will not be revoked.

That said it looks like you want to run a background service that accesses Google APIs. For this you may want to use a Service Account if you are not accessing a specific user's data.

like image 22
Nicolas Garnier Avatar answered Oct 02 '22 18:10

Nicolas Garnier