Skip to content

Commit

Permalink
fix some rubocop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Knerio committed Nov 22, 2024
1 parent 74f0db1 commit 8135ec8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions code0-identities.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency "httparty", "~> 0.22"
spec.add_dependency "ruby-saml", '~> 1.17.0'
spec.add_dependency "ruby-saml", "~> 1.17.0"

spec.add_development_dependency "webmock", "~> 3.23.1"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rubocop", "~> 1.21"
spec.add_development_dependency "rubocop-rake", "~> 0.6"
spec.add_development_dependency "rubocop-rspec", "~> 2.29" # Uncomment to register a new dependency of your gem
spec.add_development_dependency "webmock", "~> 3.23.1"
spec.metadata["rubygems_mfa_required"] = "true"
end
2 changes: 1 addition & 1 deletion lib/code0/identities.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require "httparty"
require 'onelogin/ruby-saml'
require "onelogin/ruby-saml"

require_relative "identities/version"
require_relative "identities/identity_provider"
Expand Down
18 changes: 8 additions & 10 deletions lib/code0/identities/provider/saml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,23 @@ def authorization_url
end

def load_identity(**params)
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse], { **config[:response_settings], settings: create_settings })
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])
)
find_attribute(attributes, config[:attribute_statements][:lastname]))
end

private

def find_attribute(attributes, attribute_statements)
attribute_statements.each do |statement|
unless attributes[statement].nil?
return attributes[statement]
end
return attributes[statement] unless attributes[statement].nil?
end
nil
end
Expand All @@ -59,10 +57,9 @@ def create_settings

def config
config = config_loader
if config_loader.is_a?(Proc)
config = config_loader.call
end
config = config_loader.call if config_loader.is_a?(Proc)

# rubocop:disable Layout/LineLength
config[:provider_name] ||= :saml
config[:response_settings] ||= {}
config[:settings] ||= {}
Expand All @@ -71,10 +68,11 @@ def config
config[:attribute_statements][:email] ||= %w[email mail http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress http://schemas.microsoft.com/ws/2008/06/identity/claims/emailaddress]
config[:attribute_statements][:firstname] ||= %w[first_name firstname firstName http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname http://schemas.microsoft.com/ws/2008/06/identity/claims/givenname]
config[:attribute_statements][:lastname] ||= %w[last_name lastname lastName http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname http://schemas.microsoft.com/ws/2008/06/identity/claims/surname]
# rubocop:enable Layout/LineLength

config
end
end
end
end
end
end

0 comments on commit 8135ec8

Please sign in to comment.