2017-02-03 15:36:11 -06:00
|
|
|
require 'omniauth/key_store'
|
2011-05-17 10:53:32 -04:00
|
|
|
|
|
|
|
module OmniAuth
|
2011-09-22 12:56:36 -05:00
|
|
|
# The AuthHash is a normalized schema returned by all OmniAuth
|
|
|
|
# strategies. It maps as much user information as the provider
|
|
|
|
# is able to provide into the InfoHash (stored as the `'info'`
|
|
|
|
# key).
|
2017-02-03 15:36:11 -06:00
|
|
|
class AuthHash < OmniAuth::KeyStore
|
2014-01-16 05:00:46 +01:00
|
|
|
def self.subkey_class
|
|
|
|
Hashie::Mash
|
|
|
|
end
|
2011-10-15 03:15:45 -05:00
|
|
|
|
2011-05-17 10:53:32 -04:00
|
|
|
# Tells you if this is considered to be a valid
|
|
|
|
# OmniAuth AuthHash. The requirements for that
|
|
|
|
# are that it has a provider name, a uid, and a
|
2011-09-22 12:56:36 -05:00
|
|
|
# valid info hash. See InfoHash#valid? for
|
2011-05-17 10:53:32 -04:00
|
|
|
# more details there.
|
|
|
|
def valid?
|
2011-09-27 12:36:05 -05:00
|
|
|
uid? && provider? && info? && info.valid?
|
2011-05-17 10:53:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def regular_writer(key, value)
|
2018-12-14 11:29:36 -05:00
|
|
|
value = InfoHash.new(value) if key.to_s == 'info' && value.is_a?(::Hash) && !value.is_a?(InfoHash)
|
2011-05-17 10:53:32 -04:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2017-02-03 15:36:11 -06:00
|
|
|
class InfoHash < OmniAuth::KeyStore
|
2014-01-16 05:00:46 +01:00
|
|
|
def self.subkey_class
|
|
|
|
Hashie::Mash
|
|
|
|
end
|
2011-10-15 03:15:45 -05:00
|
|
|
|
2011-09-27 12:36:05 -05:00
|
|
|
def name
|
|
|
|
return self[:name] if self[:name]
|
|
|
|
return "#{first_name} #{last_name}".strip if first_name? || last_name?
|
|
|
|
return nickname if nickname?
|
|
|
|
return email if email?
|
2018-12-14 11:29:36 -05:00
|
|
|
|
2011-09-27 12:36:05 -05:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2014-01-16 05:00:46 +01:00
|
|
|
def name?
|
2015-12-19 12:14:29 +09:00
|
|
|
!!name
|
2011-05-17 10:53:32 -04:00
|
|
|
end
|
2016-08-08 10:55:19 -07:00
|
|
|
alias valid? name?
|
2011-09-27 12:36:05 -05:00
|
|
|
|
|
|
|
def to_hash
|
|
|
|
hash = super
|
|
|
|
hash['name'] ||= name
|
|
|
|
hash
|
|
|
|
end
|
2011-05-17 10:53:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|