Python Flask.Authlib.如何注销或撤销令牌?GitHub OAuth



我在我的应用程序中为oauth2使用authlib。通过oauth(GitHub)登录后,我想退出。我该怎么做呢?我需要撤销令牌吗?或者我需要清空我的烧酒会话?

oauth = OAuth(app)
oauth.register(
name='github',
access_token_url='https://github.com/login/oauth/access_token',
authorize_url='https://github.com/login/oauth/authorize',
api_base_url='https://api.github.com/',
client_kwargs={'scope': 'read:user'},
)

我的处理程序:

from app.oauth import bp
from flask import url_for, render_template, redirect, session
from app import oauth
@bp.route('/alogin')
def login():
redirect_uri = url_for('oauth.authorize', _external=True)
print(redirect_uri) 
return oauth.github.authorize_redirect(redirect_uri)
@bp.route('/complete')
def authorize():
token = oauth.github.authorize_access_token()
resp = oauth.github.get('user', token=token) 
resp.raise_for_status()
user = resp.json()
print(token)
print(user)
print(session)
#profile = resp.json()
# do something with the token and profile
return redirect(url_for('auth.login'))

我明白是怎么回事了。这都是关于GitHub OAuth的细节。如果您已经通过github登录过一次,那么如果您在此帐户下登录到github本身,则所有后续登录尝试都会自动登录到该github帐户。因此,在我的情况下,没有必要注销或撤销令牌。

最新更新