【问题标题】:Getting refresh_token with lepture/authlib使用lepture/authlib 获取refresh_token
【发布时间】:2018-08-01 03:27:30
【问题描述】:

我正在使用 Authlib,并尝试从 Hydra 服务器获取 refresh_token。我有以下代码:

from authlib.client import OAuth2Session

client_id = "my-client"
client_secret = "client secret"
token_url = "https://myhydraserver/token"
scope = 'openid email profile offline'
session = OAuth2Session(client_id, client_secret, scope=scope)

token = session.fetch_access_token(token_url)
print(token)

打印出来

{'access_token': 'the-token', 'expires_in': 3599, 'scope': '', 'token_type': 'bearer', 'expires_at': 1519224804}

从文档中,我看到有一个函数可以从 refresh_token 获取访问令牌,但首先找不到获取 refresh_token 的方法。我将如何获得 refresh_token? Hydra 的配置:

  --grant-types authorization_code,refresh_token,client_credentials,implicit 
  --response-types token,code,id_token 

应该分发refresh_tokens。

【问题讨论】:

    标签: python oauth-2.0 openid-connect authlib


    【解决方案1】:

    client_credentials 不会发出刷新令牌。您需要使用 authorization_code 流程来获取刷新令牌。

    https://docs.authlib.org/en/latest/client/oauth2.html#oauth2session-for-authorization-code

    【讨论】:

    • 我实际上尝试了链接中提到的 Authorization_code 流程,但我仍然只收到一个访问令牌(即没有刷新令牌)。也许我需要在服务器端设置一些东西?
    猜你喜欢
    • 2018-12-20
    • 2020-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-25
    • 1970-01-01
    • 2018-08-16
    相关资源
    最近更新 更多