Skip to content
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

GitHub oAuth - Flask - AWS Beanstalk #413

Closed
QAInsights opened this issue Feb 12, 2023 · 2 comments
Closed

GitHub oAuth - Flask - AWS Beanstalk #413

QAInsights opened this issue Feb 12, 2023 · 2 comments

Comments

@QAInsights
Copy link

I implemented GitHub oAuth for my app. Upon clicking Login using GitHub link, it is not logging in. From the logs, I can see the below error:

WARNING:flask_dance.consumer.oauth2:OAuth 2 authorization error: redirect_uri_mismatch description: The redirect_uri MUST match the registered callback URL for this application. uri: https://docs.github.com/apps/managing-oauth-apps/troubleshooting-authorization-request-errors/#redirect-uri-mismatch

My auth callback URL: https://perfgpt.qainsights.com/login/github/authorized

I went through this issue, but it is not solving my case.

Any insights please?

@singingwolfboy
Copy link
Owner

My auth callback URL: https://perfgpt.qainsights.com/login/github/authorized

The error message says that given URL does not match the registered callback URL. You need to edit your OAuth app on GitHub and make sure that this URL is in the "Authorization callback URL" field.

@QAInsights
Copy link
Author

Thanks @singingwolfboy I was able to fix it. Below is the code I used. Auth call URL is configured correctly.

class ReverseProxied(object):
    def __init__(self, app):
        self.app = app

    def __call__(self, environ, start_response):
        # if one of x_forwarded or preferred_url is https, prefer it.
        forwarded_scheme = environ.get("HTTP_X_FORWARDED_PROTO", None)
        preferred_scheme = application.config.get("PREFERRED_URL_SCHEME", None)
        if "https" in [forwarded_scheme, preferred_scheme]:
            environ["wsgi.url_scheme"] = "https"
        return self.app(environ, start_response)
application.config.update(dict(
    PREFERRED_URL_SCHEME='https'
))
application.wsgi_app = ReverseProxied(application.wsgi_app)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants