[英]Devise Omniauth-Saml: [“omniauth.auth”] is nil
我正在開發Rails 4應用程序。 Auth針對MS ADFS。
我正在使用..
我的帶有omniauth-saml的POC(未設計)可以正常工作,但實際上...
當ADFS發送回調(發布) request.env["omniauth.auth"]
為零
這是我的config / initializers / devise.rb(僅omniauth部分)
config.omniauth :saml,
issuer: "https://xxx.xxx.xxx",
idp_sso_target_url: "https://yyy.yyy.yyy/adfs/ls",
assertion_consumer_service_url: "https://xxx.xxx.xxx/auth/saml/callback",
name_identifier_format: "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress",
idp_cert: "xxxxxxxxxx"
我的omniauth控制器
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
#skip_before_action :protect_from_forgery
#protect_from_forgery with: :null_session
#protect_from_forgery except: :sign_in
skip_before_filter :verify_authenticity_token
def saml
auth = request.env["omniauth.auth"]
#auth.uid # Gets the UID value of the user that has just signed in
# Create a session, redirect etc
Rails.logger.debug "========================================"
Rails.logger.debug "AUTH " + auth.inspect
Rails.logger.debug "========================================"
redirect_to root_path, notice: "GOOD "
end
end
我的路線(設計部分)
devise_for :users,
:controllers => {
:omniauth_callbacks => "users/omniauth_callbacks"
},
skip: :registrations
devise_scope :user do
post "/auth/:provider/callback", to: "users/omniauth_callbacks#saml"
end
耙道...
user_omniauth_authorize GET|POST /users/auth/:provider(.:format) users/omniauth_callbacks#passthru {:provider=>/saml/}
user_omniauth_callback GET|POST /users/auth/:action/callback(.:format) users/omniauth_callbacks#(?-mix:saml)
POST /auth/:provider/callback(.:format) users/omniauth_callbacks#saml
身份驗證提供程序將回調發送到https://xxx.xxx.xxx/auth/saml/callback,但是omniauth正在監聽https://xxx.xxx.xxx/users/auth/:action/callback 。 我使用devise_scope
將網址映射到控制器。 這可能是問題嗎?
看到這個...
user_omniauth_callback GET|POST /users/auth/:action/callback(.:format) users/omniauth_callbacks#(?-mix:saml)
在我的devise_for
使用“路徑”解決了(並deleting devise _scope
)
devise_for :users,
:path => '',
:controllers => {
:omniauth_callbacks => 'users/omniauth_callbacks'
},
skip: :registrations
有了這個,路線從...
user_omniauth_authorize GET|POST /users/auth/:provider(.:format) users/omniauth_callbacks#passthru {:provider=>/saml/}
user_omniauth_callback GET|POST /users/auth/:action/callback(.:format) users/omniauth_callbacks#(?-mix:saml)
POST /auth/:provider/callback(.:format)
至 ...
user_omniauth_authorize GET|POST /auth/:provider(.:format) users/omniauth_callbacks#passthru {:provider=>/saml/}
user_omniauth_callback GET|POST /auth/:action/callback(.:format) users/omniauth_callbacks#(?-mix:saml)
現在, user_omniauth_callback
等於我的Auth提供者調用的url。
結論:在Devise + Omniauth中,映射URL不起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.