1

我正在将用于 Ruby 工具包的 onelogin SAML API 集成到我当前的项目中。我配置了 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 index具有设置和请求对象的方法,但是当它重定向页面时,即redirect_to(request.create(settings)),我收到错误:

nil 类没有“创建”方法。

我认为它调用 create 方法但不返回任何值。你能请任何人检查一下,让我知道你的疑虑/建议。

4

2 回答 2

2

根据https://github.com/onelogin/ruby-saml的声明应该是:

OneLogin::RubySaml::Authrequest
and
OneLogin::RubySaml::Response

他们网站上的工具包文档似乎已经过时了。使用 gem 中提供的文档。

来自 gem 文档:

Version 0.8.x changes the namespace of the gem from OneLogin::Saml
to OneLogin::RubySaml. Please update your implementations of the gem accordingly.
于 2017-04-11T11:55:32.517 回答
1

您是否查看过这个包含 ruby​​-saml 和 rails4 工作示例的 github 存储库? https://github.com/onelogin/ruby-saml-example

同样重要的是您正在使用的 ruby​​-saml 版本,因为某些方法在旧版本上不可用。

于 2016-08-23T08:04:28.617 回答