Sha256: 7a2368c34b35468841d0d395b211bbe96c7c39290d8c9bf595b306de4367491c

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

module OmniAuth
  module Strategies
    class GPlus < OAuth2
      option :client_options, {
        site: 'https://www.googleapis.com/oauth2/v1',
        authorize_url: 'https://www.google.com/accounts/o8/oauth2/authorization',
        token_url: 'https://www.google.com/accounts/o8/oauth2/token'
      }

      option :scope, 'email'

      option :uid_field, :uid

      info do
        {
          'email' => raw_info['email'],
          'name' => raw_info['name'],
          'first_name' => raw_info['given_name'],
          'last_name' => raw_info['family_name'],
          'image' => raw_info['picture'],
          'urls' => {
            "Google+" => raw_info['link']
          }
        }
      end

      extra do
        {
          'locale' => raw_info['locale'],
          'gender' => raw_info['gender'],
          'birthday' => raw_info['birthday'],
          'raw_info' => raw_info
        }
      end

      def authorize_params
        super.tap do |params|
          params['scope'] = format_scopes(params['scope'])
          custom_parameters(params)
        end
      end

      private

      def format_scopes(scopes)
        scopes.split(/,\s*/).map(&method(:format_scope)).join(" ")
      end

      def format_scope(scope)
        "https://www.googleapis.com/auth/userinfo.#{scope}"
      end

      def custom_parameters(params)
        ["scope", "client_options"].each { |k| add_key_to_params(params, k) }
      end

      def add_key_to_params(params, key)
        params[key] = request.params[key] if request.params[key]
      end

      def raw_info
        access_token.options[:mode] = :query
        @raw_info ||= access_token.get('userinfo').parsed
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-gplus-1.0.0 lib/omniauth/strategies/gplus.rb