我在 Rails 应用程序中使用 ruby-saml 时遇到问题。我是 Ruby 世界的新手。
从这里我知道我可以为 SAML SP 使用ruby-saml工具包。
现在,当我尝试在我的控制器中引用 OneLogin(如下所示)时,我收到错误“未初始化的常量 Onelogin::Saml”。
OneLogin::RubySaml::Authrequest.new
当我尝试在我的控制器中包含以下行时,我得到了不同的错误。
require 'onelogin/saml'
or
require 'onelogin/ruby-saml'
得到像这样的错误,
cannot load such file -- onelogin/saml
or
cannot load such file -- onelogin/ruby-saml
我安装了 gem ruby-saml,并将它包含在我的 rails 应用程序的 GemFile 中,并运行了 bundle install 。
[root@localhost SP]# bundle show ruby-saml
/usr/local/rvm/gems/ruby-2.1.1/gems/ruby-saml-0.8.1
[root@localhost SP]#
我的控制器:
#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
我不确定我错过了什么。想法?