4
votes

I am facing issue in using ruby-saml in my Rails application. I am new to Ruby world.

From here I got to know I could use ruby-saml tool kit for SAML SP.

Now, when I tried to refer to OneLogin in my controller (like below) I am getting the error "uninitialized constant Onelogin::Saml".

OneLogin::RubySaml::Authrequest.new

When I tried include below lines in my controller I am getting different errors.

require 'onelogin/saml'
or
require 'onelogin/ruby-saml'

Getting the errors like,

cannot load such file -- onelogin/saml
or
cannot load such file -- onelogin/ruby-saml

I installed the gem ruby-saml and I included the same in my rails application's GemFile as well and ran bundle install as well.

[root@localhost SP]# bundle show ruby-saml  
/usr/local/rvm/gems/ruby-2.1.1/gems/ruby-saml-0.8.1  
[root@localhost SP]# 

My controller:

#require 'onelogin/saml'

require 'onelogin/ruby-saml'

class SamlController < ApplicationController
  skip_before_filter :verify_authenticity_token, :only => [:consume]  

  def index
    #settings = Account.get_saml_settings
    settings = :get_saml_settings
    request = Onelogin::Saml::Authrequest.new
    redirect_to(request.create(settings))
  end

  def consume
    response = Onelogin::Saml::Response.new(params[:SAMLResponse])
    response.settings = Account.get_saml_settings

    logger.info "NAMEID: #{response.name_id}"

    if response.is_valid?
      session[:userid] = response.name_id
      redirect_to :action => :complete
    else
      redirect_to :action => :fail
    end
  end

  def complete
  end

  def fail
  end

def get_saml_settings
end

end

I am not sure what I am missing. Thoughts?

1

1 Answers

3
votes

I think the declaration should be like this: OneLogin::RubySaml according to the source code.