1
0
Fork 0
mirror of https://github.com/omniauth/omniauth.git synced 2022-11-09 12:31:49 -05:00
omniauth--omniauth/lib/omniauth/auth_hash.rb
Michael Herold 00481a9edc Silence Hashie::Mash logger on Hashie 3.5.0+
We introduced a new logger for Mash due to the huge number of issues
that we get where people try to set keys on their Mash. This change
silences the info messages that get logged when a Mash has a conflict
with a method name.

I had to do this in a kind of hacky way. Since OmniAuth supports Hashie
versions `>= 1.2, < 4`, I can't just hook into the method that we'll be
adding in 3.5.2. As such, I apply an override for the logging method if
the disable method isn't present.

I'm also only overriding the method in versions that have the logging
capability.
2017-02-05 15:35:08 -06:00

54 lines
1.3 KiB
Ruby

require 'omniauth/key_store'
module OmniAuth
# 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).
class AuthHash < OmniAuth::KeyStore
def self.subkey_class
Hashie::Mash
end
# 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
# valid info hash. See InfoHash#valid? for
# more details there.
def valid?
uid? && provider? && info? && info.valid?
end
def regular_writer(key, value)
if key.to_s == 'info' && !value.is_a?(InfoHash)
value = InfoHash.new(value)
end
super
end
class InfoHash < OmniAuth::KeyStore
def self.subkey_class
Hashie::Mash
end
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?
nil
end
def name?
!!name
end
alias valid? name?
def to_hash
hash = super
hash['name'] ||= name
hash
end
end
end
end