A generic SAML strategy for OmniAuth available under the MIT License
https://github.com/omniauth/omniauth-saml
- OmniAuth 1.3+
- Ruby 1.9.x or Ruby 2.1.x+
We tag and release gems according to the Semantic Versioning principle.
Use the SAML strategy as a middleware in your application:
require 'omniauth'
use OmniAuth::Strategies::SAML,
:assertion_consumer_service_url => "consumer_service_url",
:issuer => "issuer",
:idp_sso_target_url => "idp_sso_target_url",
:idp_sso_target_url_runtime_params => {:original_request_param => :mapped_idp_param},
:idp_cert => "-----BEGIN CERTIFICATE-----\n...-----END CERTIFICATE-----",
:idp_cert_fingerprint => "E7:91:B2:E1:...",
:idp_cert_fingerprint_validator => lambda { |fingerprint| fingerprint },
:name_identifier_format => "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
or in your Rails application:
in Gemfile
:
gem 'omniauth-saml'
and in config/initializers/omniauth.rb
:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :saml,
:assertion_consumer_service_url => "consumer_service_url",
:issuer => "rails-application",
:idp_sso_target_url => "idp_sso_target_url",
:idp_sso_target_url_runtime_params => {:original_request_param => :mapped_idp_param},
:idp_cert => "-----BEGIN CERTIFICATE-----\n...-----END CERTIFICATE-----",
:idp_cert_fingerprint => "E7:91:B2:E1:...",
:idp_cert_fingerprint_validator => lambda { |fingerprint| fingerprint },
:name_identifier_format => "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
end
For IdP-initiated SSO, users should directly access the IdP SSO target URL. Set the href
of your application's login link to the value of idp_sso_target_url
. For SP-initiated SSO, link to /auth/saml
.
The service provider metadata used to ease configuration of the SAML SP in the IdP can be retrieved from http://example.com/auth/saml/metadata
. Send this URL to the administrator of the IdP.
-
:assertion_consumer_service_url
- The URL at which the SAML assertion should be received. If not provided, defaults to the OmniAuth callback URL (typicallyhttp://example.com/auth/saml/callback
). Optional. -
:issuer
- The name of your application. Some identity providers might need this to establish the identity of the service provider requesting the login. Required. -
:idp_sso_target_url
- The URL to which the authentication request should be sent. This would be on the identity provider. Required. -
:idp_sso_target_url_runtime_params
- A dynamic mapping of request params that exist during the request phase of OmniAuth that should to be sent to the IdP after a specific mapping. So for example, a paramoriginal_request_param
with valueoriginal_param_value
, could be sent to the IdP on the login request asmapped_idp_param
with valueoriginal_param_value
. Optional. -
:idp_cert
- The identity provider's certificate in PEM format. Takes precedence over the fingerprint option below. This option or:idp_cert_fingerprint
or:idp_cert_fingerprint_validator
must be present. -
:idp_cert_fingerprint
- The SHA1 fingerprint of the certificate, e.g. "90:CC:16:F0:8D:...". This is provided from the identity provider when setting up the relationship. This option or:idp_cert
or:idp_cert_fingerprint_validator
MUST be present. -
:idp_cert_fingerprint_validator
- A lambda that MUST accept one parameter (the fingerprint), verify if it is valid and return it if successful. This option or:idp_cert
or:idp_cert_fingerprint
MUST be present. -
:name_identifier_format
- Used during SP-initiated SSO. Describes the format of the username required by this application. If you need the email address, use "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress". See http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf section 8.3 for other options. Note that the identity provider might not support all options. If not specified, the IdP is free to choose the name identifier format used in the response. Optional. -
:request_attributes
- Used to build the metadata file to inform the IdP to send certain attributes along with the SAMLResponse messages. Defaults to requestingname
,first_name
,last_name
andemail
attributes. See theOneLogin::RubySaml::AttributeService
class in the Ruby SAML gem for the available options for each attribute. Set to{}
to disable this from metadata. -
:attribute_service_name
- Name for the attribute service. Defaults toRequired attributes
. -
:attribute_statements
- Used to map Attribute Names in a SAMLResponse to entries in the OmniAuth info hash. For example, if your SAMLResponse contains an Attribute called 'EmailAddress', specify{:email => ['EmailAddress']}
to map the Attribute to the corresponding key in the info hash. URI-named Attributes are also supported, e.g.{:email => ['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress']}
. Note: All attributes can also be found in an array underauth_hash[:extra][:raw_info]
, so this setting should only be used to map attributes that are part of the OmniAuth info hash schema. -
See the
OneLogin::RubySaml::Settings
class in the Ruby SAML gem for additional supported options.
Straightforward integration with Devise, the widely-used authentication solution for Rails.
In config/initializers/devise.rb
:
Devise.setup do |config|
config.omniauth :saml,
idp_cert_fingerprint: 'fingerprint',
idp_sso_target_url: 'target_url'
end
Then follow Devise's general OmniAuth tutorial, replacing references to facebook
with saml
.
Authored by Rajiv Aaron Manglani, Raecoo Cao, Todd W Saxton, Ryan Wilcox, Steven Anderson, Nikos Dimitrakopoulos, Rudolf Vriend and Bruno Pedro.