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

redirect_uri_mismatch #2654

Open
ivomarino opened this issue Mar 17, 2018 · 13 comments
Open

redirect_uri_mismatch #2654

ivomarino opened this issue Mar 17, 2018 · 13 comments

Comments

@ivomarino
Copy link

hi all, we're running Samson as a Docker container behind HAProxy which also does SSL termination, the service is available as, let's say, http://deploy.dev.foo.com -- the following environment settings have been set:

        DATABASE_URL: "sqlite3://db/development.sqlite"
        DEFAULT_URL: "https://deploy.dev.foo.com"
        SECRET_TOKEN: "whatever"
        AUTH_GITHUB: "true"
        GITHUB_TOKEN: "whatever"
        GITHUB_ORGANIZATION: "foo"
        GITHUB_ADMIN_TEAM: "foo"
        GITHUB_CLIENT_ID: "whatever"
        GITHUB_SECRET: "whatever"
        # RAILS_ENV: "production"
        # RACK_ENV: "production"
        RAILS_ENV: "development"
        RACK_ENV: "development"
        FORCE_SSL: 1

after trying to log-in via GitHub we always get this error message: redirect_uri_mismatch | The redirect_uri MUST match the registered callback URL for this application. | https://developer.github.com/apps/managing-oauth-apps/troubleshooting-authorization-request-errors/#redirect-uri-mismatch:

screen shot 2018-03-17 at 14 57 19

OAuth authentication has been set this way:

screen shot 2018-03-17 at 15 11 34

any suggestions? Thanks.

@grosser
Copy link
Contributor

grosser commented Mar 17, 2018

make sure haproxy passes on http_x_forwarded_proto so samson knows that it is actually running in https

did you try setting the authorization callback url to http ?
otherwise try to hack oauth to tell you what the actual url was ... might be a good PR for oauth anyway ... I think I ran into this error too :/

@ivomarino
Copy link
Author

the chain is haproxy -> nginx reverse proxy -> Samson, I have to check if header infos are forwarded.

@ivomarino
Copy link
Author

I can’t actually use HTTP cause HAProxy actually forces HTTPS (redirect), I can try to turn that off anyway if you think the issue is HTTPS.

@grosser
Copy link
Contributor

grosser commented Mar 17, 2018 via email

@ivomarino
Copy link
Author

@grosser just tested, running everything on HTTP only works, as soon as I use https://deploy.dev.foo.com I can't login.

@ivomarino
Copy link
Author

I've checked the vars using Apache2 and PHP:

HTTP_X_REAL_IP => 192.168.120.1 
HTTP_X_FORWARDED_FOR => xxx.xxx.xxx.xxx, 192.168.120.1 
HTTP_X_FORWARDED_PROTO => https 
HTTP_X_FORWARDED_SSL => off 
HTTP_X_FORWARDED_PORT => 80 

this is basically just another container running on the same node where samson runs so what applies to this also applies to samson. Does Samson use HTTP_X_FORWARDED_PROTO or similar? I'm accessing this stuff via https://debug.dev.foo.com.

@grosser
Copy link
Contributor

grosser commented Mar 19, 2018

hmm I think the error comes from githubs side via oauth
see omniauth-oauth2-1.4.0/lib/omniauth/strategies/oauth2.rb:66

does it work when only setting the callback url to http ?

I think the issue comes from samson sending out a request like "hey call me back on http://" and then github say "nope!"

callback_url comes from omniauth-1.6.1/lib/omniauth/strategy.rb:410
so might be fixable by setting OmniAuth.config.full_host = "https://debug.dev.foo.com" in samsons config/initializers/omniauth.rb

let me know if that works ... might also be good to inspect the request env, it should be visible on that error page you saw ... check for HTTP_X_FORWARDED_PROTO

@ivomarino
Copy link
Author

@grosser I check thats, thanks. Is there anyway for printing HTTP_X_FORWARDED_PROTO form puma, etc?

@grosser
Copy link
Contributor

grosser commented Mar 19, 2018 via email

@ivomarino
Copy link
Author

ivomarino commented Mar 19, 2018

seems to work now, had to set auth URL to https://deploy.dev.foo.com/auth/github/callback and mount modified app/config/initializers/omniauth.rb:/app/config/initializers/omniauth.rb into the container we're I've set OmniAuth.config.full_host = "https://deploy.dev.foo.com".

@grosser
Copy link
Contributor

grosser commented Mar 19, 2018 via email

@ivomarino
Copy link
Author

@grosser seems so, I will double check that by printing X-vars then. Thanks for help;) regarding memcached, is it required? thanks

@grosser
Copy link
Contributor

grosser commented Mar 19, 2018 via email

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