Skip to content

Commit

Permalink
Properly fetch user attributes from the retrieved info
Browse files Browse the repository at this point in the history
  • Loading branch information
fblupi committed Jul 4, 2024
1 parent ae738db commit b2f5404
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/omniauth/strategies/ub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@
module OmniAuth
module Strategies
class Ub < OmniAuth::Strategies::OAuth2
REGEXP_SANITIZER = /[<>?%&^*#@()\[\]=+:;"{}\\|]/

option :name, "ub"
option :token_options, %w(client_id client_secret)

uid do
token_info["uid"]
raw_info.dig("employeenumber", 0)
end

info do
{
name: token_info["cn"],
nickname: token_info["dni"],
email: token_info["mail"]
name: raw_info.dig("cn", 0).gsub(REGEXP_SANITIZER, ""),
nickname: Decidim::UserBaseEntity.nicknamize(raw_info.dig("uidnet", 0)),
email: raw_info.dig("mail", 0)
}
end

def callback_url
full_host + callback_path
end

def token_info
@token_info ||= begin
def raw_info
@raw_info ||= begin
connection = Faraday.new(url: options.client_options[:site], ssl: { verify: true }) do |conn|
conn.headers["Authorization"] = "#{access_token.response.parsed.token_type} #{access_token.token}"
end
Expand Down

0 comments on commit b2f5404

Please sign in to comment.