本文介绍了通过授权代码从Lepture / Authlib获取刷新令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试开发一个简单的工具,该工具使用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:
github/authlib/example-oauth2-server/commit/4f2f48cc3e74b631d9c4365
请参阅文档: docs.authlib/en/latest/flask/oauth2.html#server
更多推荐
通过授权代码从Lepture / Authlib获取刷新令牌
发布评论