Class: Gitlab::Auth::OAuth::AuthHash

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/auth/o_auth/auth_hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_hash) ⇒ AuthHash

Returns a new instance of AuthHash.


10
11
12
# File 'lib/gitlab/auth/o_auth/auth_hash.rb', line 10

def initialize(auth_hash)
  @auth_hash = auth_hash
end

Instance Attribute Details

#auth_hashObject (readonly)

Returns the value of attribute auth_hash


9
10
11
# File 'lib/gitlab/auth/o_auth/auth_hash.rb', line 9

def auth_hash
  @auth_hash
end

Instance Method Details

#emailObject


30
31
32
# File 'lib/gitlab/auth/o_auth/auth_hash.rb', line 30

def email
  @email ||= username_and_email[:email].to_s
end

#has_attribute?(attribute) ⇒ Boolean

Returns:

  • (Boolean)

47
48
49
50
51
52
53
# File 'lib/gitlab/auth/o_auth/auth_hash.rb', line 47

def has_attribute?(attribute)
  if attribute == :location
    get_info(:address).present?
  else
    get_info(attribute).present?
  end
end

#locationObject


38
39
40
41
42
43
44
45
# File 'lib/gitlab/auth/o_auth/auth_hash.rb', line 38

def location
  location = get_info(:address)
  if location.is_a?(Hash)
    [location.locality.presence, location.country.presence].compact.join(', ')
  else
    location
  end
end

#nameObject


22
23
24
# File 'lib/gitlab/auth/o_auth/auth_hash.rb', line 22

def name
  @name ||= get_info(:name) || "#{get_info(:first_name)} #{get_info(:last_name)}"
end

#passwordObject


34
35
36
# File 'lib/gitlab/auth/o_auth/auth_hash.rb', line 34

def password
  @password ||= Gitlab::Utils.force_utf8(::User.random_password.downcase)
end

#providerObject


18
19
20
# File 'lib/gitlab/auth/o_auth/auth_hash.rb', line 18

def provider
  @provider ||= auth_hash.provider.to_s
end

#uidObject


14
15
16
# File 'lib/gitlab/auth/o_auth/auth_hash.rb', line 14

def uid
  @uid ||= Gitlab::Utils.force_utf8(auth_hash.uid.to_s)
end

#usernameObject


26
27
28
# File 'lib/gitlab/auth/o_auth/auth_hash.rb', line 26

def username
  @username ||= username_and_email[:username].to_s
end