2

我正在使用 Authlib 库构建与 Github 的集成,并且需要刷新访问令牌。我在 Authlib 库中调用 refresh_token() ,如下所示:

my_token = {'refresh_token':'a_long_refresh_token_string',
            'access_token': "a_long_access_token",
            'expires_at': 1596745728.0,
            'expires_in': 28800.0}

oauth_session = OAuth2Session(client_id,client_secret, authorization_endpoint="https://github.com/login/oauth/authorize", token_endpoint="https://github.com/login/oauth/access_token", token=my_token, grant_type='refresh_token')

new_token = oauth_session.refresh_token(url="https://github.com/login/oauth/access_token")

# Tried this too, but generates the same error    
# new_token = oauth_session.refresh_token(url="https://github.com/login/oauth/access_token", client_id=client_id, client_secret=client_secret) 

但它始终会导致 OAuthError。这是完整的堆栈跟踪:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/user/dev/venvs/pyenv/lib64/python3.7/site-packages/authlib/oauth2/client.py", line 264, in refresh_token
    auth=auth, **session_kwargs)
  File "/root/user/dev/venvs/pyenv/lib64/python3.7/site-packages/authlib/oauth2/client.py", line 275, in _refresh_token
    token = self.parse_response_token(resp.json())
  File "/root/user/dev/venvs/pyenv/lib64/python3.7/site-packages/authlib/oauth2/client.py", line 380, in parse_response_token
    self.handle_error(error, description)
  File "/root/user/dev/venvs/pyenv/lib64/python3.7/site-packages/authlib/integrations/requests_client/oauth2_session.py", line 117, in handle_error
    raise OAuthError(error_type, error_description)
authlib.integrations.base_client.errors.OAuthError: bad_refresh_token: The refresh token passed is incorrect or expired.

在获取访问令牌和尝试刷新它之间,我没有卸载 Github 应用程序。关于我可能做错了什么的任何想法?

4

0 回答 0