Flask Oauth2 google.authorize()回调缺少1个位置参数

时间:2019-02-15 13:21:48

标签: python flask oauth-2.0 google-oauth

我正在尝试通过Google授权我的Flask应用,但Google不会返回我需要传递给回调函数的参数:

  

TypeError:google_authorized()缺少1个必需的位置参数:   'resp'

这是一个代码:

@auth.route('/google-login')
def google_login():
    return google.authorize(callback=url_for('auth.google_authorized', _external=True))


@google.authorized_handler
@auth.route('/oauth2callback')
def google_authorized(resp):
    if resp is None:
        return f"Access denied: reason={request.args['error_reason']} error={request.args['error_description']}"

    session['google_oauth_token'] = (resp['access_token'], '')
    userinfo = requests.get(GOOGLE_OAUTH2_USERINFO_URL, params=dict(access_token=resp['access_token'],)).json()

    user = User.query.filter_by(username=userinfo['email']).first()
    if not user:
        user = User(userinfo['email'], '')
        db.session.add(user)
        db.session.commit()

    login_user(user)
    flash(f"Logged in as id={userinfo['id']} name={userinfo['name']}")
    return redirect(url_for('auth.home'))

如何调试为什么会发生这种情况?

0 个答案:

没有答案