dpjo15650 2015-02-23 22:45
浏览 376

如何在golang / oauth2客户端库中处理刷新令牌

There are few examples of using https://github.com/golang/oauth2 but none of them covers usage of refresh tokens. I've tried few approaches, but i'm still unsatisfied with my results.

Is there any example code, or maybe you know some project at Github using oauth2 lib to take as example?

  • 写回答

1条回答 默认 最新

  • dongzheng4556 2015-03-12 08:41
    关注

    You need not bother about refreshing tokens until the time you are storing the Expiry parameter. After getting the 'Token' object, store the following in your database:

    token.AccessToken, token.RefreshToken, token.TokenType and token.Expiry

    while fetching, construct the token object again using the above parameters:

    token := new(oauth2.Token)
    token.AccessToken = {{ From DataBase }}
    token.RefreshToken = {{ From DataBase }}
    token.Expiry = {{ From DataBase }}
    token.TokenType = {{ From DataBase }}
    

    and then get your http client:

    config.Client(ctx, token)

    this will handle refreshing the token. Excerpt (more info: Golang oauth2 client):

    Client returns an HTTP client using the provided token. The token will auto-refresh as necessary.

    Only downside is, the refreshed access token is not returned. But it works! Google has no restrictions on how many times the refresh token is used.

    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)