skip to Main Content

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?

2

Answers


  1. Per the documentation:

    >>> import requests_oauthlib
    >>> from requests_oauthlib import OAuth2Session
    >>> from requests_oauthlib.compliance_fixes import facebook_compliance_fix
    >>> facebook = OAuth2Session(client_id='test', redirect_uri='https://test.me')
    >>> facebook = facebook_compliance_fix(facebook)
    >>> authorization_url, state = facebook.authorization_url('https://www.facebook.com/dialog/oauth')
    >>> authorization_url
    'https://www.facebook.com/dialog/oauth?response_type=code&client_id=test&redirect_uri=https%3A%2F%2Ftest.me&state=bfipsir5GsKc1CbdPZCgBT0jIn2eq6'
    
    Login or Signup to reply.
  2. 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?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search