I am using Flask-Dance for facebook login.
Here is blueprint file
from flask import redirect, url_for
from flask_dance.contrib.facebook import make_facebook_blueprint, facebook
facebook_bp = make_facebook_blueprint(
redirect_url='http://api.domain.com/auth/social/facebook/authorized'
)
@facebook_bp.route('')
def index():
if not facebook.authorized:
return redirect(url_for("facebook.login"))
resp = facebook.get("/me")
return resp.text
And below is main app file
from api.auth.facebook import facebook_bp
...
app.register_blueprint(facebook_bp, url_prefix='/auth/social')
When I request to https://api.domain.com/auth/social
it redirects me to facebook, which says that redirect_url is blocked.
The facebook url that flask-dance opens is something linke this facebook.com/...&redirect_uri=http://api/auth/social/facebook/authorized&...
I have even tried to add redirect_url
in blueprint configs, but the same thing there.
The app is deployed with docker compose nginx and gunicorn.
2
Answers
kindly check that
in my case turns out redirect_to is always none ! if I did it as the following:
You said that the
redirect_uri
query parameter doesn’t match the domain that your Flask app is running on. That indicates that Flask (not Flask-Dance, but Flask itself) is getting incorrect information (or possibly no information) about the server it’s running on. This information is necessary for handling OAuth securely.Read through the Flask-Dance documentation about proxies and HTTPS, as well as the Flask documentation about proxies. Once Flask is able to correctly determine where it’s running, Flask-Dance should generate the
redirect_uri
correctly.