Sha256: 8327ccec23881cb28281d611fbcc8bde104a6c32f1e25247754d880461710057

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

# Copied from https://github.com/raysrashmi/omniauth-foursquare
#
# Dependencies on the gem are old but the strategy still works fine
# on its own
#
# License: MIT

require 'omniauth-oauth2'

module OmniAuth
  module Strategies
    class Foursquare < OmniAuth::Strategies::OAuth2
      option :client_options, {
        :site => 'https://foursquare.com',
        :authorize_url => '/oauth2/authenticate',
        :token_url => '/oauth2/access_token'
      }

      uid { raw_info['id'] }

      info do
        {
          :first_name  => raw_info['firstName'],
          :last_name   => raw_info['lastName'],
          :name        => "#{raw_info['firstName']} #{raw_info['lastName']}",
          :email       => (raw_info['contact'] || {})['email'],
          :phone       => (raw_info['contact'] || {})['phone'],
          :image       => raw_info['photo'],
          :location    => raw_info['homeCity'],
          :description => raw_info['bio']
        }
      end

      extra do
        { :raw_info => raw_info }
      end

      def request_phase
        options[:authorize_params] = client_params.merge(options[:authorize_params])
        super
      end

      def auth_hash
        OmniAuth::Utils.deep_merge(super, client_params.merge({
          :grant_type => 'authorization_code'}))
      end

      def raw_info
        access_token.options[:mode] = :query
        access_token.options[:param_name] = :oauth_token
        @raw_info ||= access_token.get('https://api.foursquare.com/v2/users/self?v=20140128').parsed['response']['user']
      end

      private

      def client_params
        {:client_id => options[:client_id], :redirect_uri => callback_url ,:response_type => "code"}
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chronicle-foursquare-0.1.1 lib/omniauth/strategies/foursquare.rb
chronicle-foursquare-0.1.0 lib/omniauth/strategies/foursquare.rb