title: Shibboleth authentication in Rails
body: <p>I am having a struggle getting this to work so I've created a hell-world Rails app to try and get this to work. </p>
  
  <p>Here's the repo with the code that is not working: <a href="https://github.com/pitosalas/shibtry" rel="noreferrer">https://github.com/pitosalas/shibtry</a></p>
  
  <p>Here's what I've done starting from an empty Rails application:</p>
  
  <ol>
  <li><p>I've added two gems to gem files:</p>
  
  <pre><code>gem 'omniauth-shibboleth'
  gem 'rack-saml'
  </code></pre></li>
  <li><p>I got the shibboleth meta data from my university's web site and converted it using shib_conv.rb into the corresponding YAML: ./config.yml</p></li>
  <li><p>I've updated routes adding <code>get '/auth/:provider/callback', to: 'sessions#create'</code></p></li>
  <li><p>I've put a breakpoint at <code>SessionController#create</code></p></li>
  <li><p>I've added initializers: omniauth.rb:</p>
  
  <pre><code>Rails.application.config.middleware.use OmniAuth::Builder do
    provider :shibboleth, {
      :shib_session_id_field     =&gt; "Shib-Session-ID",
      :shib_application_id_field =&gt; "Shib-Application-ID",
      :debug                     =&gt; true,
      :extra_fields =&gt; [
        :"unscoped-affiliation",
        :entitlement
      ]
    }
  end
  </code></pre></li>
  <li><p>I've added rack_sam.rb initializer:</p>
  
  <pre><code>Rails.application.config.middleware.insert_after Rack::ETag, Rack::Saml,
    { :metadata =&gt; "#{Rails.root}/config/metadata.yml"}
  </code></pre></li>
  <li><p>Now, run the server and go to <code>http://0.0.0.0:3000/auth/shibboleth</code> and I get an error: </p>
  
  <pre><code>undefined method `[]' for nil:NilClass'
  </code></pre>
  
  <p>which is traced back to this line in rack-saml/misc/onelogin_setting.rb line 13 which is:</p>
  
  <pre><code>settings.idp_sso_target_url = @metadata['saml2_http_redirect']
  </code></pre>
  
  <p>in other words, looking for the metadata hash for that key. It happens that in my metadata.yml file that key is present, but by the time I get to this onelogin_setting.rb line 13, <code>@metadata</code> is nil (it should contain the contents of the file) and consequently that key doesn't exist.</p></li>
  </ol>
  
  <p>And that's where, for now, the trail dries up.</p>