Home >Backend Development >Golang >How to be notified when go google api refreshes access and refresh token?

How to be notified when go google api refreshes access and refresh token?

WBOY
WBOYforward
2024-02-10 21:57:07772browse

当 go google api 刷新访问和刷新令牌时如何收到通知?

php editor Youzi often encounters refresh access and refresh tokens when using go google api. But how do you get notified in time? In fact, we can do this by setting the callback URL. When the refresh operation completes, Google will send a POST request to this URL to notify us of the status of the refresh. In this way, we can obtain relevant information about access and token refresh in time to facilitate our subsequent processing and operations.

Question content

My application successfully obtains AccessToken and RefreshToken from the user through the oauth2 process. I then store them in the database so that I can access them later and perform requests on behalf of the user. So far this is working fine. But when my AccessToken expires, the Go google api library automatically refreshes the AccessToken along with the RefreshToken using that RefreshToken. This works great too, but to be able to use the new set of tokens in future sessions I have to store them in my database again. So how can I make the Go google api tell me when the access token is changed?

In the example of their node.js library, there is a simple callback that I can register to achieve this. But somehow the documentation for Go libraries is not that good.

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

Solution

In-depth study of golang/ After oauth2 code, I found that there is no such function. However, I opened a pull request on the above repository to enable it. https://www.php.cn/link/8fbf752a03d27d94c949ca816b453196

The above is the detailed content of How to be notified when go google api refreshes access and refresh token?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete