Class: OmniAuth::Strategies::Suomifi

Inherits:
SAML
  • Object
show all
Defined in:
lib/omniauth/strategies/suomifi.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, *args, &block) ⇒ Suomifi

rubocop:disable Metrics/MethodLength



494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
# File 'lib/omniauth/strategies/suomifi.rb', line 494

def initialize(app, *args, &block)
  super

  # Add the request attributes to the options.
  options[:request_attributes] = scoped_request_attributes
  options[:sp_name_qualifier] = options[:sp_entity_id] if options[:sp_name_qualifier].nil?

  # Remove the nil options from the origianl options array that will be
  # defined by the Suomi.fi options
  %i[
    certificate
    private_key
    idp_name_qualifier
    name_identifier_format
    security
  ].each do |key|
    options.delete(key) if options[key].nil?
  end

  # Add the Suomi.fi options to the local options, most of which are
  # fetched from the metadata. The options array is the one that gets
  # priority in case it overrides some of the metadata or locally defined
  # option values.
  @suomifi_thread = Thread.new do
    @options = OmniAuth::Strategy::Options.new(
      suomifi_options.merge(options)
    )
  end
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



490
491
492
# File 'lib/omniauth/strategies/suomifi.rb', line 490

def options
  @options
end

#suomifi_threadObject (readonly)

Returns the value of attribute suomifi_thread.



491
492
493
# File 'lib/omniauth/strategies/suomifi.rb', line 491

def suomifi_thread
  @suomifi_thread
end

Instance Method Details

#callback_urlObject

Override the callback URL so that it always matches the one expected by Suomi.fi. No additional query string parameters can be included in the string.



560
561
562
# File 'lib/omniauth/strategies/suomifi.rb', line 560

def callback_url
  full_host + script_name + callback_path
end

#request_phaseObject

Override the request phase to be able to pass the locale parameter to the redirect URL. Note that this needs to be the last parameter to be passed to the redirect URL.



528
529
530
531
532
533
534
535
536
537
538
539
540
# File 'lib/omniauth/strategies/suomifi.rb', line 528

def request_phase
  suomifi_thread.join if suomifi_thread.alive?
  authn_request = OneLogin::RubySaml::Authrequest.new
  locale = locale_for_authn_request

  session['saml_redirect_url'] = request.params['redirect_url']

  with_settings do |settings|
    url = authn_request.create(settings, additional_params_for_authn_request)
    url += "&locale=#{CGI.escape(locale)}" unless locale.nil?
    redirect(url)
  end
end

#response_objectObject

This method can be used externally to fetch information about the response, e.g. in case of failures.



544
545
546
547
548
549
550
551
552
553
554
555
# File 'lib/omniauth/strategies/suomifi.rb', line 544

def response_object
  return nil unless request.params['SAMLResponse']

  with_settings do |settings|
    response = OneLogin::RubySaml::Response.new(
      request.params['SAMLResponse'],
      options_for_response_object.merge(settings: settings)
    )
    response.attributes['fingerprint'] = settings.idp_cert_fingerprint
    response
  end
end