chrodriguez / redmine_omniauth_saml

Plugins that adds SAML authentication support for "Redmine"
GNU General Public License v2.0
38 stars 57 forks source link

No route matches [POST] "/" #13

Closed gosforth closed 8 years ago

gosforth commented 8 years ago

Hi,

I have config:

Redmine::OmniAuthSAML::Base.configure do |config|
  config.saml = {
    :assertion_consumer_service_url => "https://host.domain.com/login", # The redmine application hostname
    :issuer                         => "https://host.domain.com/",                 # The issuer name
    :idp_sso_target_url             => "https://auth.dom.com/simplesaml/saml2/idp/SSOService.php", # SSO login endpoint
    :idp_cert_fingerprint           => "bd:56:ce:72:94:72:af:f5:8d:18:a5:a4:75:9a:99:a1:66:9b:c2:13", # SSO ssl certificate fingerprint
    :name_identifier_format         => "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",
    :signout_url                    => "https://auth.dom.com/simplesaml/saml2/idp/SingleLogoutService.php",
    :idp_slo_target_url             => "http://sso.example.com/saml2/idp/SingleLogoutService.php",
    :name_identifier_value          => "uid", # Which redmine field is used as name_identifier_value for SAML logout
    :attribute_mapping              => {
    # How will we map attributes from SSO to redmine attributes
      :login      => 'extra.raw_info.username',
      :uid      => 'extra.raw_info.username',
      :firstname  => 'extra.raw_info.first_name',
      :lastname   => 'extra.raw_info.last_name',
      :mail       => 'extra.raw_info.email'
    }
  }

  config.on_login do |omniauth_hash, user|
    # Implement any hook you want here
  end
end

I can successfuly authenticate yet after redirecting to Redmine from IDP I have error:

Page not found

The page you were trying to access doesn't exist or has been removed.

Back

And in the log:

Started GET "/" for 62.111.45.33 at 2016-09-21 10:16:46 +0200
Processing by WelcomeController#index as HTML
  Current user: anonymous
Redirected to http://host.domain.com/login?back_url=http%3A%2F%2Fhost.domain.com%2F
Filter chain halted as :check_if_login_required rendered or redirected
Completed 302 Found in 3ms (ActiveRecord: 0.2ms)
Started GET "/login?back_url=http%3A%2F%2Fhost.domain.com%2F" for 62.111.45.33 at 2016-09-21 10:16:46 +0200
Processing by AccountController#login as HTML
  Parameters: {"back_url"=>"http://host.domain.com/"}
  Current user: anonymous
  Rendered plugins/redmine_omniauth_saml/app/views/redmine_omniauth_saml/_view_account_login_top.html.erb (1.8ms)
  Rendered account/login.html.erb within layouts/base (3.8ms)
Completed 200 OK in 14ms (Views: 9.7ms | ActiveRecord: 0.6ms)
Started GET "/auth/saml?origin=http%3A%2F%2Fhost.domain.com%2F" for 62.111.45.33 at 2016-09-21 10:16:53 +0200
Started POST "/" for 62.111.45.33 at 2016-09-21 10:16:54 +0200

ActionController::RoutingError (No route matches [POST] "/"):
  actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.6) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.6) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'

What is the reason?

gosforth commented 8 years ago

Maybe problem is that there are no routes for "Started GET "/auth/saml?origin=..."

This routing commands: https://github.com/chrodriguez/redmine_omniauth_saml/blob/master/config/routes.rb

...should be added to config/routes.rb manualy? I d not see these lines in config/routes.rb file. If so how where these lines should be inserted?

chrodriguez commented 8 years ago

That specific route is the one highlighted in the following link:

https://github.com/chrodriguez/redmine_omniauth_saml/blob/master/config/routes.rb#L4

Are you sure the plugin is installed properly? Which redmine version are you using?

gosforth commented 8 years ago

Redmine 3.3.0 I think plugin is istalled correctly. This routes would be added automaticaly to routes.rb during install? Anyway if I add this:

RedmineApp::Application.routes.draw do
  match '/auth/failure'             => 'account#login_with_saml_failure',   via: [:get, :post]
  match '/auth/:provider/callback'  => 'account#login_with_saml_callback',  via: [:get, :post]
  match '/auth/:provider'           => 'account#login_with_saml_redirect',  as: :sign_in, via: [:get, :post]
end

then I have error that sign_in is duplicated. ...maybe I should check option "Replace Redmine login page" to make it works?

BWT: how to reinstall this plugin?

gosforth commented 8 years ago

Will you please help? If this is routing problem so how to add those commands to routes.rb? Any example how finally route.rb should look like? Installation process do NOT modify this file during plugin installation.

chrodriguez commented 8 years ago

I didn't test the plugin with this version of redmine (3.3). The latest version I've tested it and worked was 3.1

I'll try this new version when I've more time

gosforth commented 8 years ago

Rodriguez, could you please show me your example of routes.rb?

How to put these all comands there?

RedmineApp::Application.routes.draw do
  match '/auth/failure'             => 'account#login_with_saml_failure',   via: [:get, :post]
  match '/auth/:provider/callback'  => 'account#login_with_saml_callback',  via: [:get, :post]
  match '/auth/:provider'           => 'account#login_with_saml_redirect',  as: :sign_in, via: [:get, :post]
end
chrodriguez commented 8 years ago

You can learn how routing works reading: http://guides.rubyonrails.org/routing.html

Those commands are loaded onto RedmineApp::Application routes, as the code shows

gosforth commented 8 years ago

Looks like syntax has changed in latest version of Redmine. This is similar problem: http://www.redmine.org/boards/3/topics/50786?r=50978

Thanks for the link but I do not understand much from that... First of all I do not get what is this

RedmineApp::Application.routes.draw do

I do not find it in Ruby commands

gosforth commented 8 years ago

Christian,

this content:

RedmineApp::Application.routes.draw do
  match '/auth/failure'             => 'account#login_with_saml_failure',   via: [:get, :post]
  match '/auth/:provider/callback'  => 'account#login_with_saml_callback',  via: [:get, :post]
  match '/auth/:provider'           => 'account#login_with_saml_redirect',  as: :sign_in, via: [:get, :post]
end

Should be added to config/routes.rb? Could you PLEASE show your example? If the IDP redirects then what url it calls?

chrodriguez commented 8 years ago

@gosforth this plugin is intended to not modify anything. Just install it and use it, so no routes need to be added. The lines you are asking for, are adding those routes to redmine seamlessly... As I mentioned in a previous comment, I haven't test this plugin with 3,3,0, so when a I can, I'll check if something changed. For now, you can test with a previous version of redmine (3.1.0 is working perfect)

gosforth commented 8 years ago

How to check if the routes are added to Redmine. They should be in {redmineApp}/config/routes.rb? If so, they are not added. So, that's why I kindly ask you to give example. I appreciate your help and effort to test it in the future but I have project I have to complete now.

gosforth commented 8 years ago

Saml assertion (response from SSO) should come to wich url? "https://host/auth/saml/callback"? It should be POST or Get?

chrodriguez commented 8 years ago

@gosforth I've installed redmine 3.3 and have no problems with routes. If you want to know which routes redmine's got configured, you can run:

rake routes

SAML routes are the following in my fresh installation:

redmine-3.3 (3.3-stable)*$ be rake routes  | grep saml
                          auth_failure GET|POST           /auth/failure(.:format)                                                           account#login_with_saml_failure
                                       GET|POST           /auth/:provider/callback(.:format)                                                account#login_with_saml_callback
                               sign_in GET|POST           /auth/:provider(.:format)  

As you can see, redmine expects this routes to be GET or POST. I think the plugin is not installed correctly.

gosforth commented 8 years ago

Thank you. Meanwhile I checked out that your example config sample-saml-initializers.rb is wrong (anyway I see you updated it finally). You had: ":assertion_consumer_service_url => "http://redmine.example.com/auth/saml/callback" and the correct value should be: :assertion_consumer_service_url => "http://redmine.example.com/auth/saml/callback"

right?

And one thing more: I have it running on Linux. I start app with command: ruby bin/rails server webrick -e production -p3010& Your plugin is working (well, I still have problem with response request but that's another story) but after several hours when clicking on "login with SAML' it redirects to 'https://host.com/auth/saml?origin=https://host.com/'..... probably some service stops working. Any idea what it can be? There is some OMNIAUTH service running in the background that stops to work? Restarting Redmine app makes it works again.

chrodriguez commented 8 years ago

@gosforth as mentioned in Redmine Installation wiki step 9 you shall not use WebBrick in production. Try using unicorn instead As your original problem is solved, I close this issue