Sha256: 75a7aa4df5457bfb52213c716992c2c317399a891a61814bd2b010ebe494247c

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

require 'omniauth/oauth'
require 'multi_json'

module OmniAuth
  module Strategies
    # Authenticate to Bitly utilizing OAuth 2.0 and retrieve
    # basic user information.
    #
    # @example Basic Usage
    #     use OmniAuth::Strategies::Bitly, 'API Key', 'Secret Key'
    class Bitly < OmniAuth::Strategies::OAuth2
      # @param [Rack Application] app standard middleware application parameter
      # @param [String] client_id the application id as [registered on Bitly](http://bit.ly/a/account)
      # @param [String] client_secret the application secret as [registered on Bitly](http://bit.ly/a/account)
      def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
        client_options = {
          :authorize_url => 'https://bit.ly/oauth/authorize',
          :token_url => 'https://api-ssl.bit.ly/oauth/access_token',
        }
        super(app, :bitly, client_id, client_secret, client_options, options, &block)
      end

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

      def user_data
        {
          'login' => @access_token['login'],
          'client_id' => @access_token['apiKey'],
        }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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