Sha256: 40198683a74dd7307bef8a2d4bd1bcbd367ef07fc522605d94f43682489df152

Contents?: true

Size: 1.46 KB

Versions: 14

Compression:

Stored size: 1.46 KB

Contents

require 'omniauth/oauth'
require 'multi_json'

module OmniAuth
  module Strategies
    #
    # Authenticate to Identica via OAuth and retrieve basic
    # user information.
    #
    # Usage:
    #
    #    use OmniAuth::Strategies::Identica, 'consumerkey', 'consumersecret'
    #
    class Identica < OmniAuth::Strategies::OAuth
      def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
        super(app, :identica, consumer_key, consumer_secret,
                {:site => 'http://identi.ca',
                :request_token_path => "/api/oauth/request_token",
                :access_token_path  => "/api/oauth/access_token",
                :authorize_path     => "/api/oauth/authorize"}, options, &block)
      end

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

      def user_info
        user_hash = self.user_hash

        {
          'nickname' => user_hash['screen_name'],
          'name' => user_hash['name'],
          'location' => user_hash['location'],
          'image' => user_hash['profile_image_url'],
          'description' => user_hash['description'],
          'urls' => {'Website' => user_hash['url']}
        }
      end

      def user_hash
        @user_hash ||= MultiJson.decode(@access_token.get('/api/account/verify_credentials.json').body)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
omniauth-0.2.6 oa-oauth/lib/omniauth/strategies/identica.rb
oa-oauth-0.2.6 lib/omniauth/strategies/identica.rb
omniauth-0.2.5 oa-oauth/lib/omniauth/strategies/identica.rb
oa-oauth-0.2.5 lib/omniauth/strategies/identica.rb
oa-oauth-0.2.4 lib/omniauth/strategies/identica.rb
oa-oauth-0.2.3 lib/omniauth/strategies/identica.rb
oa-oauth-0.2.2 lib/omniauth/strategies/identica.rb
oa-oauth-0.2.1 lib/omniauth/strategies/identica.rb
oa-oauth-0.2.0 lib/omniauth/strategies/identica.rb
oa-oauth-0.2.0.beta5 lib/omniauth/strategies/identica.rb
oa-oauth-0.2.0.beta4 lib/omniauth/strategies/identica.rb
oa-oauth-0.2.0.beta3 lib/omniauth/strategies/identica.rb
oa-oauth-0.2.0.beta2 lib/omniauth/strategies/identica.rb
oa-oauth-0.2.0.beta1 lib/omniauth/strategies/identica.rb