BigW Consortium Gitlab

auth_hash.rb 788 Bytes
Newer Older
1 2 3 4 5 6 7 8
# Class to parse and transform the info provided by omniauth
#
module Gitlab
  module LDAP
    class AuthHash < Gitlab::OAuth::AuthHash
      private

      def get_info(key)
9
        attributes = ldap_config.attributes[key.to_s]
Douwe Maan committed
10
        return super unless attributes
11

Douwe Maan committed
12 13 14 15 16
        attributes = Array(attributes)

        value = nil
        attributes.each do |attribute|
          value = get_raw(attribute)
17
          value = value.first if value
Douwe Maan committed
18 19
          break if value.present?
        end
20 21 22 23 24 25 26 27 28 29
        
        return super unless value

        Gitlab::Utils.force_utf8(value)
        value
      end

      def get_raw(key)
        auth_hash.extra[:raw_info][key]
      end
30 31 32 33

      def ldap_config
        @ldap_config ||= Gitlab::LDAP::Config.new(self.provider)
      end
34 35 36
    end
  end
end