Class: Code0::Identities::Provider::Saml

Inherits:
Object
  • Object
show all
Defined in:
lib/code0/identities/provider/saml.rb,
sig/code0/identities/provider/saml.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_loader) ⇒ Saml

Returns a new instance of Saml.



9
10
11
# File 'lib/code0/identities/provider/saml.rb', line 9

def initialize(config_loader)
  @config_loader = config_loader
end

Instance Attribute Details

#config_loaderObject (readonly)

Returns the value of attribute config_loader.



7
8
9
# File 'lib/code0/identities/provider/saml.rb', line 7

def config_loader
  @config_loader
end

Instance Method Details

#authorization_urlString

Returns:

  • (String)


23
24
25
26
27
28
# File 'lib/code0/identities/provider/saml.rb', line 23

def authorization_url
  request = OneLogin::RubySaml::Authrequest.new
  request.create(create_settings)

  request.instance_variable_get :@login_url
end

#load_identity(**params) ⇒ Identity

Parameters:

  • (Hash[Symbol, any])

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/code0/identities/provider/saml.rb', line 30

def load_identity(**params)
  response = OneLogin::RubySaml::Response.new(params[:SAMLResponse],
                                              { **config[:response_settings], settings: create_settings })
  attributes = response.attributes

  Identity.new(config[:provider_name],
               response.name_id,
               find_attribute(attributes, config[:attribute_statements][:username]),
               find_attribute(attributes, config[:attribute_statements][:email]),
               find_attribute(attributes, config[:attribute_statements][:firstname]),
               find_attribute(attributes, config[:attribute_statements][:lastname]))
end

#validate_config!void

This method returns an undefined value.



13
14
15
16
17
18
19
20
21
# File 'lib/code0/identities/provider/saml.rb', line 13

def validate_config!
  required_keys = config[:metadata_url].nil? ? %i[settings] : %i[metadata_url]

  missing_keys = required_keys - config.keys
  invalid_keys = config.keys - %i[provider_name metadata_url settings response_settings attribute_statements]

  raise MissingConfigurationError, "Missing: #{missing_keys.inspect}" if missing_keys.any?
  raise InvalidConfigurationError, "Invalid: #{invalid_keys.inspect}" if invalid_keys.any?
end