通过授权代码从Lepture / Authlib获取刷新令牌 [英] Obtaining Refresh Token from lepture/Authlib through Authorization Code
问题描述
我正在尝试开发一个简单的工具,该工具使用Authlib OAuth2服务器获取刷新令牌,但使用示例服务器此处不会发出刷新令牌。当我打印令牌时,得到以下内容:
I am trying to develop a simple tool that uses Authlib OAuth2 server to get refresh tokens but example server here does not issue a refresh token. When I print the token I get the following:
{'access_token': '....', 'scope': 'profile', 'token_type': 'Bearer', 'expires_in': 864000, 'expires_at': 1532191887}
该流程是此处所引用的授权代码;首先,我要处理同意部分:
The flow is Authorization code as referred here; first I handle the consent part:
client_id = '...'
client_secret = '.....'
scope = '...'
session = OAuth2Session(client_id, client_secret, scope=scope)
authorize_url = '.../oauth/authorize'
uri, state = session.authorization_url(authorize_url)
然后我尝试获取令牌:
urlset = '.../?code=...&state=...'
access_token_url = '.../oauth/token'
token = session.fetch_access_token(access_token_url,authorization_response=urlset)
推荐答案
添加 OAUTH2_REFRESH_TOKEN_GENERATOR = True
的配置,并在提交中添加:
Add a config of OAUTH2_REFRESH_TOKEN_GENERATOR=True
, added in commit:
< a href = https://github.com/authlib/example-oauth2-server/commit/4f2f48cc3e74b631d9c4c3bdf8558da3de7365a2 rel = nofollow noreferrer> https://github.com/authlib/example-oauth2-server/commit/4f2f48cc3e74b631d9c4365
请参阅文档: https://docs.authlib.org/en/latest/flask/oauth2.html#server
这篇关于通过授权代码从Lepture / Authlib获取刷新令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!