Sha256: 10f8f2407eaf133eaae170f225a5c15f5296863985c9daa788389a9cf9bef94c

Contents?: true

Size: 1.28 KB

Versions: 13

Compression:

Stored size: 1.28 KB

Contents

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)
      value = InfoHash.new(value) if key.to_s == 'info' && value.is_a?(::Hash) && !value.is_a?(InfoHash)
      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

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
omniauth-2.1.2 lib/omniauth/auth_hash.rb
omniauth-2.1.1 lib/omniauth/auth_hash.rb
omniauth-1.9.2 lib/omniauth/auth_hash.rb
omniauth-2.1.0 lib/omniauth/auth_hash.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/omniauth-2.0.4/lib/omniauth/auth_hash.rb
omniauth-2.0.4 lib/omniauth/auth_hash.rb
omniauth-2.0.3 lib/omniauth/auth_hash.rb
omniauth-2.0.2 lib/omniauth/auth_hash.rb
omniauth-2.0.1 lib/omniauth/auth_hash.rb
omniauth-2.0.0 lib/omniauth/auth_hash.rb
omniauth-2.0.0.pre.rc1 lib/omniauth/auth_hash.rb
omniauth-1.9.1 lib/omniauth/auth_hash.rb
omniauth-1.9.0 lib/omniauth/auth_hash.rb