Sha256: e215f5022aece794510b4a3366202f8078777d6dacb78c4e1bb31285f8335b43

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 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, consumer_secret)
        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")
      end

      def auth_hash
        OmniAuth::Utils.deep_merge(super, {
          'uid' => @access_token.params[:user_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

3 entries across 3 versions & 1 rubygems

Version Path
oa-oauth-0.1.6 lib/omniauth/strategies/identica.rb
oa-oauth-0.1.5 lib/omniauth/strategies/identica.rb
oa-oauth-0.1.4 lib/omniauth/strategies/identica.rb