New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Google Oauth Error 400: redirect_uri_mismatch #344
Comments
If Google doesn't support adding non-SSL URLs there's nothing you can do on the Flask side. But I doubt that's the case. Goolge should accept Please note that though we maintain a solution to help you leverage Oauth2 in your Flask app, we're not a generic helpdesk. There's a million of solutions that show up on search engines: https://stackoverflow.com/questions/10456174/oauth-how-to-test-with-local-urls |
thank you, but I'm running it on my server and it has SSL. Error 400: redirect_uri_mismatch so I need to do that via HTTPS but I don't know how to do that and google does not allow me to add HTTP://revisto.com. thanks again |
Then it sounds like your reverse proxy isn't set up correctly, so the Flask app running your website doesn't think it has TLS and is generating plain http URLs instead of https ones. I'd suggest reviewing https://flask.palletsprojects.com/en/1.1.x/deploying/wsgi-standalone/. |
i found what causes the problem. when flask_dance wants to redirect, the URL is like this: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=<CLIEND_ID>&redirect_uri=http%3A%2F%2Frevisto.com%2Flogin%2Fgoogle%2Fauthorized&scope=profile+email&state=&access_type=offline here the value of redirect_uri parameter is "http". How can I change it to https? |
That's this one: https://github.com/singingwolfboy/flask-dance/blob/main/flask_dance/contrib/google.py#L58. But if it's generating a URL with |
final solution: if anyone has the same problem, just add this simple line to your flask code:
|
This is an extremely bad idea. Setting that variable this way means that even if a connection were to come in over HTTP, you're telling flask it's HTTPS. This can lead to tokens being leaked. If you configure Flask and any reverse proxy correctly, this isn't necessary and things will work as intended, with https URLs being correctly generated. |
Hi again.
i'm trying to use Google OAuth on my server, my website is HTTPS but the request that it sends to redirect is from HTTP and there is no way to add non-SSL redirect URIs to google console.
btw i use Nginx.
I would appreciate any help or solution.
The text was updated successfully, but these errors were encountered: