Sha256: 99023c794ab1f54cff7647051e8edebbd5b4308f4c05bdfbb4df61dfa39b6269

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

require 'omniauth/oauth'
require 'multi_json'

module OmniAuth
  module Strategies
    class Dropbox < OmniAuth::Strategies::OAuth
      def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
        client_options = {
          :authorize_url => 'https://www.dropbox.com/0/oauth/authorize',
          :access_token_url => 'https://api.dropbox.com/0/oauth/access_token',
          :proxy => ENV['HTTP_PROXY'] || ENV['http_proxy'],
          :request_token_url => 'https://api.dropbox.com/0/oauth/request_token',
          :site => 'https://api.dropbox.com',
        }
        super(app, :dropbox, consumer_key, consumer_secret, client_options, options, &block)
      end

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

      def user_data
        @data ||= MultiJson.decode(@access_token.get('/0/account/info').body)
      end

      def user_info
        {
          'name' => user_data['display_name'],
          'uid' => user_data['uid'],
          'email' => user_data['email']
        }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
oa-oauth-0.3.2 lib/omniauth/strategies/oauth/dropbox.rb
oa-oauth-0.3.0 lib/omniauth/strategies/oauth/dropbox.rb
oa-oauth-0.3.0.rc3 lib/omniauth/strategies/oauth/dropbox.rb