@@ -15,28 +15,46 @@ def self.inherited(subclass)
1515 option :name_identifier_format , nil
1616 option :idp_sso_target_url_runtime_params , { }
1717 option :request_attributes , [
18- { :name => 'email' , :name_format => 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic' , :friendly_name => 'Email address' } ,
19- { :name => 'name' , :name_format => 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic' , :friendly_name => 'Full name' } ,
20- { :name => 'first_name' , :name_format => 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic' , :friendly_name => 'Given name' } ,
21- { :name => 'last_name' , :name_format => 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic' , :friendly_name => 'Family name' }
18+ { :name => 'email' , :name_format => 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic' , :friendly_name => 'Email address' } ,
19+ { :name => 'name' , :name_format => 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic' , :friendly_name => 'Full name' } ,
20+ { :name => 'first_name' , :name_format => 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic' , :friendly_name => 'Given name' } ,
21+ { :name => 'last_name' , :name_format => 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic' , :friendly_name => 'Family name' }
2222 ]
2323 option :attribute_service_name , 'Required attributes'
2424 option :attribute_statements , {
25- name : [ "name" ] ,
26- email : [ "email" , "mail" ] ,
27- first_name : [ "first_name" , "firstname" , "firstName" ] ,
28- last_name : [ "last_name" , "lastname" , "lastName" ]
25+ name : [ "name" ] ,
26+ email : [ "email" , "mail" ] ,
27+ first_name : [ "first_name" , "firstname" , "firstName" ] ,
28+ last_name : [ "last_name" , "lastname" , "lastName" ]
2929 }
3030 option :slo_default_relay_state
3131 option :uid_attribute
32+ option :auth_request_include_request_attributes , false
33+ option :sptype , false
3234 option :idp_slo_session_destroy , proc { |_env , session | session . clear }
3335
3436 def request_phase
3537 authn_request = OneLogin ::RubySaml ::Authrequest . new
3638
37- with_settings do |settings |
38- redirect ( authn_request . create ( settings , additional_params_for_authn_request ) )
39+ options [ :assertion_consumer_service_url ] ||= callback_url
40+ if options [ :sptype ] != false
41+ options . extensions [ :sptype ] = options [ :sptype ]
42+ end
43+ if options [ :auth_request_include_request_attributes ] == true
44+ options . extensions [ :requested_attributes ] = with_requested_attributes
45+ end
46+ settings = OneLogin ::RubySaml ::Settings . new ( options )
47+
48+ redirect ( authn_request . create ( settings , additional_params_for_authn_request ) )
49+ end
50+
51+ def with_requested_attributes
52+ raise OmniAuth ::Strategies ::SAML ::ValidationError . new ( 'Cannot convert option request_attributes to samlp:Extensions/eidas:RequestedAttributes' ) unless options [ :request_attributes ] . respond_to? :each
53+ attrs = [ ]
54+ options [ :request_attributes ] . each do |orig_attr |
55+ attrs . push ( OneLogin ::RubySaml ::RequestedAttribute . new ( { :Name => orig_attr [ :name ] , :FriendlyName => orig_attr [ :friendly_name ] , :NameFormat => orig_attr [ :name_format ] , :isRequired => orig_attr [ :required ] || false } ) )
3956 end
57+ attrs
4058 end
4159
4260 def callback_phase
@@ -61,7 +79,7 @@ def response_fingerprint
6179 response = request . params [ "SAMLResponse" ]
6280 response = ( response =~ /^</ ) ? response : Base64 . decode64 ( response )
6381 document = XMLSecurity ::SignedDocument ::new ( response )
64- cert_element = REXML ::XPath . first ( document , "//ds:X509Certificate" , { "ds" => 'http://www.w3.org/2000/09/xmldsig#' } )
82+ cert_element = REXML ::XPath . first ( document , "//ds:X509Certificate" , { "ds" => 'http://www.w3.org/2000/09/xmldsig#' } )
6583 base64_cert = cert_element . text
6684 cert_text = Base64 . decode64 ( base64_cert )
6785 cert = OpenSSL ::X509 ::Certificate . new ( cert_text )
@@ -108,7 +126,7 @@ def other_phase
108126 Hash [ found_attributes ]
109127 end
110128
111- extra { { :raw_info => @attributes , :session_index => @session_index , :response_object => @response_object } }
129+ extra { { :raw_info => @attributes , :session_index => @session_index , :response_object => @response_object } }
112130
113131 def find_attribute_by ( keys )
114132 keys . each do |key |
@@ -180,7 +198,7 @@ def handle_logout_request(raw_request, settings)
180198 logout_request = OneLogin ::RubySaml ::SloLogoutrequest . new ( raw_request )
181199
182200 if logout_request . is_valid? &&
183- logout_request . name_id == session [ "saml_uid" ]
201+ logout_request . name_id == session [ "saml_uid" ]
184202
185203 # Actually log out this session
186204 options [ :idp_slo_session_destroy ] . call @env , session
@@ -231,7 +249,7 @@ def validate_fingerprint(settings)
231249
232250 def options_for_response_object
233251 # filter options to select only extra parameters
234- opts = options . select { |k , _ | RUBYSAML_RESPONSE_OPTIONS . include? ( k . to_sym ) }
252+ opts = options . select { |k , _ | RUBYSAML_RESPONSE_OPTIONS . include? ( k . to_sym ) }
235253
236254 # symbolize keys without activeSupport/symbolize_keys (ruby-saml use symbols)
237255 opts . inject ( { } ) do |new_hash , ( key , value ) |
@@ -247,7 +265,7 @@ def other_phase_for_metadata
247265
248266 add_request_attributes_to ( settings ) if options . request_attributes . length > 0
249267
250- Rack ::Response . new ( response . generate ( settings ) , 200 , { "Content-Type" => "application/xml" } ) . finish
268+ Rack ::Response . new ( response . generate ( settings ) , 200 , { "Content-Type" => "application/xml" } ) . finish
251269 end
252270 end
253271
@@ -269,7 +287,7 @@ def other_phase_for_spslo
269287 redirect ( generate_logout_request ( settings ) )
270288 end
271289 else
272- Rack ::Response . new ( "Not Implemented" , 501 , { "Content-Type" => "text/html" } ) . finish
290+ Rack ::Response . new ( "Not Implemented" , 501 , { "Content-Type" => "text/html" } ) . finish
273291 end
274292 end
275293
0 commit comments