Skip to content

Commit

Permalink
Better option mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed Oct 21, 2024
1 parent 4fdda03 commit 7e76f60
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def self.model
url: { allow_blank: true, allow_nil: true, schemes: %w[http https] },
if: -> { model.post_logout_redirect_uri_changed? }


OpenIDConnect::Provider::MAPPABLE_ATTRIBUTES.each do |attr|
attribute :"mapping_#{attr}"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def initialize(configuration)
end

def call! # rubocop:disable Metrics/AbcSize
options = mapped_options(configuration.deep_stringify_keys)
options = configuration.deep_stringify_keys

{
"slug" => options["name"],
Expand All @@ -57,7 +57,12 @@ def call! # rubocop:disable Metrics/AbcSize
"token_endpoint" => extract_url(options, "token_endpoint"),
"userinfo_endpoint" => extract_url(options, "userinfo_endpoint"),
"end_session_endpoint" => extract_url(options, "end_session_endpoint"),
"jwks_uri" => extract_url(options, "jwks_uri")
"jwks_uri" => extract_url(options, "jwks_uri"),
"mapping_login" => options.dig("attribute_map", "login"),
"mapping_mail" => options.dig("attribute_map", "email"),
"mapping_firstname" => options.dig("attribute_map", "first_name"),
"mapping_lastname" => options.dig("attribute_map", "last_name"),
"mapping_admin" => options.dig("attribute_map", "admin")
}.compact
end

Expand Down Expand Up @@ -102,21 +107,5 @@ def base_url(options)
scheme: options["scheme"] || "https"
).to_s
end

def mapped_options(options)
extract_mapping(options)

options.compact
end

def extract_mapping(options)
return unless options["attribute_map"]

options["mapping_login"] = options["attribute_map"]["login"]
options["mapping_mail"] = options["attribute_map"]["email"]
options["mapping_firstname"] = options["attribute_map"]["first_name"]
options["mapping_lastname"] = options["attribute_map"]["last_name"]
options["mapping_admin"] = options["attribute_map"]["admin"]
end
end
end

0 comments on commit 7e76f60

Please sign in to comment.