Python authlib flask - how to do password grant flow correctly?

。_饼干妹妹 提交于 2021-01-25 06:01:29

问题


I have "password grant flow" login with the authlib flask integration working nicely:

@app.route('/login', methods=('GET', 'POST'))
def login():
    if request.method == 'GET':
        return render_template('login.html')
    else:
        try:
            token = oauth.myOauth2.fetch_access_token(username=request.form.get('username'),
                                                      password=request.form.get('password'))
        except OAuthError as e:
            if e.description:
                flash(e.description)
                return render_template('login.html')
            raise

However, in a previous question I was advised not to use fetch_access_token like this as it's not documented for the flask integration, and to use authorize_access_token instead. This fails with an error werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. KeyError: 'code'

So what is the correct way to do "password grant flow" with the flask integration?
Any advice is welcome.


回答1:


For the record, @lepture confirmed in the comments above that this use of fetch_access_token is ok.
Entering this answer here to be able to mark the question as answered.



来源:https://stackoverflow.com/questions/64528856/python-authlib-flask-how-to-do-password-grant-flow-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!