gogoogle-apigoogle-api-go-client

How to get notified when the go google api refreshes the access and refresh tokens?


My application successfully gets the AccessToken and the RefreshToken from the user throught the oauth2 flow. Then I store them in my database so I can access them later on and execute requests on behalf of the user. This works totally fine so far. But when my AccessToken expires, the Go google api library will automatically refresh the AccessToken as well as the RefreshToken using that RefreshToken. This works fine as well, but to be able to use the new set of Tokens for future sessions, I have to store them in my database again. So how can I make the Go google api tell me whenever it changes the access token?

In the example for their node.js library there is a simle callback I can register to archieve this. But somehow the Go library is not documented that well.

Googles official documentation: https://developers.google.com/identity/protocols/oauth2/web-server?hl=de#offline


Solution

  • After deeper reseach of the golang/oauth2 code, i found there is no such functionallity. However i opened a pull request on said repo enabling it. https://github.com/golang/oauth2/pull/683