Sha256: c1e773442a1f71a3499543c5355bbc78ec79d52d37e92b9ea714b00c7f877eaa

Contents?: true

Size: 1.24 KB

Versions: 12

Compression:

Stored size: 1.24 KB

Contents

require 'hashie/mash'

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 < Hashie::Mash
    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 < Hashie::Mash
      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

      def valid?
        name?
      end

      def to_hash
        hash = super
        hash['name'] ||= name
        hash
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
omniauth-1.1.4 lib/omniauth/auth_hash.rb
omniauth-1.1.3 lib/omniauth/auth_hash.rb
omniauth-1.1.2 lib/omniauth/auth_hash.rb
omniauth-1.1.1 lib/omniauth/auth_hash.rb
omniauth-1.1.0 lib/omniauth/auth_hash.rb
omniauth-1.0.3 lib/omniauth/auth_hash.rb
omniauth-1.0.2 lib/omniauth/auth_hash.rb
omniauth-1.0.1 lib/omniauth/auth_hash.rb
omniauth-1.0.0 lib/omniauth/auth_hash.rb
omniauth-1.0.0.rc2 lib/omniauth/auth_hash.rb
omniauth-1.0.0.rc1 lib/omniauth/auth_hash.rb
omniauth-1.0.0.beta1 lib/omniauth/auth_hash.rb