使用Lepture/Authlib获取refresh_token [英] Getting refresh_token with lepture/authlib

查看:203
本文介绍了使用Lepture/Authlib获取refresh_token的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using Authlib, and attempting to get a refresh_token from a Hydra server. I have the following code:

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配置有:

From the docs, I see that there's a function to get an access token from a refresh_token, but can't find a way to get a refresh_token in the first place. How would I go about getting a refresh_token? Hydra's configured with:

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

应该分发refresh_tokens.

which should hand out refresh_tokens.

推荐答案

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

client_credentials won't issue refresh token. You need to use authorization_code flow to get the refresh token.

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

这篇关于使用Lepture/Authlib获取refresh_token的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆