summaryrefslogtreecommitdiff
path: root/lib/gitlab/ldap/auth_hash.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ldap/auth_hash.rb')
-rw-r--r--lib/gitlab/ldap/auth_hash.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/gitlab/ldap/auth_hash.rb b/lib/gitlab/ldap/auth_hash.rb
new file mode 100644
index 00000000000..caca7bb3b57
--- /dev/null
+++ b/lib/gitlab/ldap/auth_hash.rb
@@ -0,0 +1,40 @@
+# Class to parse and transform the info provided by omniauth
+#
+module Gitlab
+ module LDAP
+ class AuthHash < Gitlab::OAuth::AuthHash
+ attr_accessor :config
+
+ def initialize(auth_hash, config)
+ super(auth_hash)
+ @config = config
+ end
+
+ private
+
+ def get_info(key)
+ raw_key = config.attributes[key]
+ return super unless raw_key
+
+ value =
+ case raw_key
+ when String
+ get_raw(raw_key)
+ when Array
+ raw_key.inject(nil) { |value, key| value || get_raw(key).presence }
+ else
+ nil
+ end
+
+ return super unless value
+
+ Gitlab::Utils.force_utf8(value)
+ value
+ end
+
+ def get_raw(key)
+ auth_hash.extra[:raw_info][key]
+ end
+ end
+ end
+end