您可以生成通過添加下面的匹配到的routes.rb *元數據路徑:
devise_scope :user do
match "https://stackoverflow.com/users/auth/:action/metadata",
constraints: { action: /saml/ },
to: "omniauth_callbacks",
as: :user_omniauth_metadata,
via: [:get, :post]
end
以如下的路線得到的(沒有 「(.format)」):
user_omniauth_metadata GET|POST /users/auth/:action/metadata omniauth_callbacks#(?-mix:saml)
這是在除了標準omniauth路線:
user_omniauth_authorize GET|POST /users/auth/:provider omniauth_callbacks#passthru {:provider=>/saml/}
user_omniauth_callback GET|POST /users/auth/:action/callback omniauth_callbacks#(?-mix:saml)
從結果:
devise_for :users, controllers: { omniauth_callbacks: "omniauth_callbacks" }
注:我用的色器件這樣做:用戶範圍,但範圍之外它看起來更像是:
match("/auth/:action/metadata",
constraints: { action: /saml/ },
to: "omniauth_callbacks",
as: :omniauth_metadata,
via: [:get, :post]
)
您還需要定義一個回調「other_phase」; 例如添加類似以下到您的SAML策略
module OmniAuth
module Strategies
class Saml
include OmniAuth::Strategy
def other_phase
if on_path?("#{request_path}/metadata")
# omniauth does not set the strategy on the "other_phase"
@env['omniauth.strategy'] ||= self
setup_phase
response = OneLogin::RubySaml::Metadata.new
settings = OneLogin::RubySaml::Settings.new # set whatever params you want on this guy
Rack::Response.new(response.generate(settings), 200,
{ "Content-Type" => "application/xml" }).finish
else
call_app!
end
end
end
end
end
我想知道這個問題的答案爲好。 – Aaron