Search code examples
flaskauthlib

Authlib - passing authorize url as json


I'm building a SPA using Flask as an api and Vue js as front end. I'm using Authlib for user authentication and planning to use Facebook OAuth. I've already tried the example with Facebook and it's working. But I want to build this in a RESTful way. What I'm trying to do is change this part from app.py from the example:

@app.route('/login')
def login():
    redirect_uri = url_for('auth', _external=True)
    return oauth.google.authorize_redirect(redirect_uri)

to a json.

Is there a method in the library to get the url of Facebook dialog so that I can pass that as json and do the redirection in Vue?


Solution

  • Do you mean that you want to return a url value in the JSON response?

    resp = oauth.google.authorize_redirect(redirect_uri)
    url = resp.location
    return jsonify(url=url)
    

    Like the above code?