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

Omniauth OAuth redirect_uri_mismatch when https is used #723

Closed
gitviola opened this issue Feb 3, 2017 · 9 comments
Closed

Omniauth OAuth redirect_uri_mismatch when https is used #723

gitviola opened this issue Feb 3, 2017 · 9 comments
Assignees
Labels

Comments

@gitviola
Copy link

gitviola commented Feb 3, 2017

Infos:

  • Used Zammad version: 1.2.0
  • Operating system: Ubuntu 16.04

Expected behavior:

  • use https in callback url for github oauth

Actual behavior:

  • uses http in callback url for github oauth

Steps to reproduce the behavior:

  • set http type to https
  • logout
  • authorise with github on login page

Known workaround

redirect http to https in nginx and use the http version of the url as callback url in the github oauth app setting

(related to #647)

@madd86
Copy link

madd86 commented Feb 3, 2017

It worked for me.

Remember that the callback url is actually set on github and not on Zammad.

Here:

screenshot_3

@thorsteneckel
Copy link
Contributor

Thanks @madd86 !

@gitviola
Copy link
Author

@madd86 that's what I did. The other thing is just the workaround so that it works

@thorsteneckel
Copy link
Contributor

thorsteneckel commented Feb 15, 2017

Hi @schurig - ups. Hit the button to early 😁

I analyzed the behavior and can reproduce the issue you are having. Sadly it's out of the Zammad scope (done by Ominauth) so we can't provide a direct fix. Nevertheless we will analyze it further to find the best solution to get it to work.

How to reproduce:

  • Have a https Zammad instance running with a reverse proxy e.g. NGINX
  • Register a Github OAuth2 application in Github/Zammad
  • Try to login in Zammad, get redirected to the Github page
  • Notice that the redirect_url GET parameter is actually the Zammad url with http instead of https

Current state:
The redirect_url comes from here:
https://github.com/intridea/omniauth-github/blob/master/lib/omniauth/strategies/github.rb#L5
https://github.com/intridea/omniauth-oauth2/blob/master/lib/omniauth/strategies/oauth2.rb#L47
https://github.com/omniauth/omniauth/blob/8098855f6b52f5f1aecbd700e7068f204adddfdd/lib/omniauth/strategy.rb#L435
https://github.com/omniauth/omniauth/blob/8098855f6b52f5f1aecbd700e7068f204adddfdd/lib/omniauth/strategy.rb#L428
https://github.com/omniauth/omniauth/blob/8098855f6b52f5f1aecbd700e7068f204adddfdd/lib/omniauth/strategy.rb#L503

Seems some of those RACK ENVs are not set properly. Should be checked if we can influence this via the NGINX conf or if we have to do it somehow in the Rails context.

@thorsteneckel thorsteneckel reopened this Feb 15, 2017
@thorsteneckel thorsteneckel self-assigned this Feb 15, 2017
@thorsteneckel thorsteneckel added bug and removed bug labels Feb 17, 2017
@thorsteneckel
Copy link
Contributor

Hi @schurig - I think I got it! Are you running with an NGINX installation? If so please update your configuration and add these two lines:

        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-Port 443;

Like in the screenshot:
bildschirmfoto 2017-02-17 um 16 56 54

Restart your NGINX and Zammad and let me know. Apache should be these lines:

RequestHeader set Host zammad.example.com
RequestHeader set X-Forwarded-Proto https
RequestHeader set X-Forwarded-Port 443

For the record: I dumped the rack.envs via an initializer overwriting the Omniauth ssl detection in a new rails initializer config/initializers/debug_ssl.rb:

Rails.application.config.to_prepare do              # to_prepare ensures that the monkey patching happens before the first request
  OmniAuth::Strategy.class_eval do                  # reopen the class
    protected

    def ssl?                                        # redefine the ssl? method
      # DEBUG/CUSTOMIZATION
      File.write('/tmp/omniauth.log', request.env.inspect)
      # DEBUG/CUSTOMIZATION

      request.env['HTTPS'] == 'on' ||
        request.env['HTTP_X_FORWARDED_SSL'] == 'on' ||
        request.env['HTTP_X_FORWARDED_SCHEME'] == 'https' ||
        (request.env['HTTP_X_FORWARDED_PROTO'] && request.env['HTTP_X_FORWARDED_PROTO'].split(',')[0] == 'https') ||
        request.env['rack.url_scheme'] == 'https'
    end
  end
end

And none of the checked vars were set.

@thorsteneckel thorsteneckel changed the title Github OAuth redirect_uri_mismatch when https is used Omniauth OAuth redirect_uri_mismatch when https is used Feb 17, 2017
@gitviola
Copy link
Author

This was the problem! Thanks!! 😍 ❤️

@thorsteneckel
Copy link
Contributor

Thanks for the feedback! Commit is on its way. 🚀 up to the next issue.

@salmagomaa
Copy link

Try this answer it worked with me
https://stackoverflow.com/a/41466634/1770571

@MrGeneration
Copy link
Member

@salmagomaa this does not solve the problem and was a Bug within Zammad.
Please try not to recycle posts - the issue has been resolved already.

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

No branches or pull requests

5 participants