title: Python authlib flask - how to do password grant flow correctly?
body: <p>I have &quot;password grant flow&quot; login with the authlib flask integration working nicely:</p>
  <pre><code>@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
  </code></pre>
  <p>However, in a <a href="https://stackoverflow.com/questions/62193044/better-examples-of-authlib-oauth-client-use-with-a-flask-app">previous question</a> I was advised not to use <code>fetch_access_token</code> like this as it's not documented for the flask integration, and to use <code>authorize_access_token</code> instead. This fails with an error <code>werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. KeyError: 'code'</code></p>
  <p>So what is the correct way to do &quot;password grant flow&quot; with the flask integration?<br />
  Any advice is welcome.</p>