Sha256: 903ce7b121b7b9da7fe1688db08469412625154fe9cdf6c0eb2857b4985f64d2

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

require 'omniauth-oauth2'

module OmniAuth
  module Strategies
    class Foursquare < OmniAuth::Strategies::OAuth2
      option :client_options, {
        :site => 'https://foursquare.com',
        :authorize_url => '/oauth2/authorize',
        :token_url => '/oauth2/access_token'
      }
      
      uid { raw_info['id'] }
      
      info do
        {
          :first_name => raw_info['firstName'], 
          :last_name  => raw_info['lastName'],
          :name       => raw_info['name'],
          :email      => (raw_info['contact'] || {})['email']
        }
      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
        response = access_token.get('https://api.foursquare.com/v2/users/self').parsed['response']
        @raw_info ||= 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

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-foursquare-0.0.5 lib/omniauth/strategies/foursquare.rb