Sha256: cf1186d30f80da93cfa2c7fbc205276b28a8ec87892eea1892741ac4be316a1f

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

require 'omniauth/oauth'

module OmniAuth
  module Strategies
    #
    # Authenticate to Dopplr via OAuth and retrieve an access token for API usage
    #
    # Usage:
    #
    #    use OmniAuth::Strategies::Dopplr, 'consumerkey', 'consumersecret'
    #
    class Dopplr < OmniAuth::Strategies::OAuth
      # Initialize the Dopplr strategy.
      #
      # @option options [Hash, {}] :client_options Options to be passed directly to the OAuth Consumer
      def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
        client_options = {
          :site => 'https://www.dopplr.com',
          :request_token_path => "/oauth/request_token",
          :access_token_path  => "/oauth/access_token",
          :authorize_path    => "/oauth/authorize"
        }
        
        super(app, :dopplr, consumer_key, consumer_secret, client_options, options, &block)
      end  
      
      def user_data
        @data ||= MultiJson.decode(@access_token.get('/oauthapi/whoami').body)['whoami']
      end
      
      def user_info
        {
          'nickname' => user_data["nick"],
          'first_name' => user_data["forename"],
          'last_name' => user_data["surname"],
          'name' => "#{user_data['forename']} #{user_data['surname']}",
          'urls' => {
            'Dopplr' => user_data["dopplr_url"],
            'DopplrMobile' => user_data["mobile_url"],
          }
        }
      end      

      def auth_hash
        OmniAuth::Utils.deep_merge(super, {
          'uid' => user_data['nick'],
          'user_info' => user_info
        })
      end      
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oa-oauth-0.2.0.beta1 lib/omniauth/strategies/dopplr.rb