【发布时间】:2017-09-25 21:54:52
【问题描述】:
编辑:底部附近的附加信息和简明问题;)
我正在使用 SAML2.0 在我正在制作的一个小应用程序和一个身份提供者之间设置集成。
一般来说,我一直遵循设计页面上的说明,然后是 Omniauth-SAML 文档。
目前的问题似乎是没有生成回调路径。这是下面的相关代码位;随时索取更多信息。
app/models/user.rb
class User < ActiveRecord::Base
devise :omniauthable, omniauth_providers: [:saml]
def from_omniauth(auth_hash)
puts auth_hash
new # Stub for now I guess?
end
end
app/controllers/omniauth_callbacks_controller.rb
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def saml
@user = User.from_omniauth request.env['omniauth.auth']
if @user.persisted?
sign_in_and_redirect @user, event: :authentication
set_flash_message(:notice, :success, kind: 'SAML') if is_navicational_format?
else
session['devise.saml_data'] = request.env['omniauth.auth']
redirect_to permission_denied # this isn't going to work lol
end
end
def failure
redirect_to root_path
end
end
来自 config/initializers/devise.rb 的截断和清理的块
config.omniauth :saml,
idp_cert_fingerprint: 'aa:bb:cc...', # an actual fingerprint here
idp_sso_target_url: 'https://sso.bla.thing.com/fss/idp/startSSO.ping?PartnerSpId=SAML_UID',
issuer: 'myidpname', # Not actually sure what this should be
idp_entity_id: 'thingfssdp',
assertion_consumer_service_url: 'https://myapp.com/auth/saml/callback',
name_identifier_format: 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress'
根据文档here 和here,添加超过上述内容(即,将附加要求放入 config/initializers/omniauth.rb)是不正确的。
我的控制器将before_action :authenticate_user! 作为第一行。
config/routes.rb 在顶部有以下行:
Rails.application.routes.draw do
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
但可能需要注意的是,我还没有手动添加任何回调处理逻辑
尝试访问我的应用会产生 ERR_TOO_MANY_REDIRECTS;相当多的 302 显然都指向自身。执行 GET /auth/saml/callback 会产生以下有用的错误(不知道 /users/ 是如何或为什么会出现在前面的;我是否需要请求更改 ACS URL 或者这是我可以控制的?):
任何见解或帮助将不胜感激。
编辑:似乎问题在于 user_saml_omniauth_authorize_path 被设置为 /users/auth/saml ——而不是直接设置为 IDP 登录页面。我对这条路线没有明确的控制器,但显然需要为其他控制器登录意味着我需要为这个控制器登录。最终结果是,正如一些人所建议的,我们得到了一个无限重定向循环。
【问题讨论】:
-
使用 sso gem。
-
不客气。
标签: ruby-on-rails devise ruby-on-rails-5 omniauth saml-2.0