【问题标题】:How to save and load refresh token in Google Python APIs如何在 Google Python API 中保存和加载刷新令牌
【发布时间】:2012-07-16 13:18:53
【问题描述】:

我对@9​​87654321@ 这个答案很满意,因为有了它,我现在很好地理解了访问令牌和刷新令牌之间的区别。我还看了一眼 OAuth2WebSercer 文档https://developers.google.com/accounts/docs/OAuth2WebServer 但我不知道可用于处理刷新令牌的功能/方法。对于访问令牌,我们使用:

gdata.gauth.ae_save()
gdata.gauth.ae_load()
token.get_access_token()

但是刷新令牌呢?

【问题讨论】:

    标签: python access-token


    【解决方案1】:

    如果您逐步进入源:
    [ae_save source]
    [token_to_blob source]

    当您调用 ae_save 时,您会看到在令牌本身上调用了 token_to_blob

    特别是:

    elif isinstance(token, OAuth2Token):
      return _join_token_parts(
          '2o', token.client_id, token.client_secret, token.scope,
          token.user_agent, token.auth_uri, token.token_uri,
          token.access_token, token.refresh_token)
    

    所以不仅保存了访问令牌,还保存了令牌对象的许多其他属性。

    【讨论】:

    • 如何使用刷新令牌?使用 refresh token.refresh_token 会报错。
    • 不应该这样。 type(token) 是什么?即使您没有刷新令牌,该值也将是None。在通过ae_save 序列化令牌之前,请确保您确实拥有refresh_token。除非您指定 approval_prompt=force,否则后续 OAuth2 请求不会为您提供新的刷新令牌。
    猜你喜欢
    • 1970-01-01
    • 2016-01-26
    • 2012-12-19
    • 1970-01-01
    • 2020-09-13
    • 1970-01-01
    • 2018-11-19
    • 2021-07-11
    • 2016-08-03
    相关资源
    最近更新 更多