Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Using omniauth-saml with multiple IDPs

What I'm trying to have in the end is the ability to login normally with devise OR choose to login with SAML. So I read that if I integrate omniauth and saml, then omniauth and devise, I could achieve that.

My problem is, that I have different IDPs that I would like to choose from. So I don't have one :idp_sso_target_url, but many. So my question is how can I dynamically change the value of the target_url. Currently the omniauth-saml gem defines this value in the config/initializers directory..

Thank you,

like image 812
user1069624 Avatar asked Aug 18 '13 09:08

user1069624


1 Answers

You can store settings for every provider in db, and then configure omniauth in the setup phase at request-time. For example:

SETUP_PROC = lambda do |env| 
  request = Rack::Request.new(env)
  user = User.find_by_subdomain(request.subdomain)
  env['omniauth.strategy'].options[:consumer_key] = user.consumer_key
  env['omniauth.strategy'].options[:consumer_secret] = user.consumer_secret
end

use OmniAuth::Builder.new do
  provider :twitter, :setup => SETUP_PROC
end

See https://github.com/intridea/omniauth/wiki/Setup-Phase for more information.

like image 196
Kostya Avatar answered Sep 23 '22 21:09

Kostya