From 3a0ea0f6a777bc07b9be6895e98004225015085b Mon Sep 17 00:00:00 2001 From: "David A. Cuadrado" Date: Mon, 11 Oct 2010 14:42:46 -0500 Subject: [PATCH] added support for http://identi.ca Signed-off-by: David A. Cuadrado --- oa-oauth/Gemfile.lock | 8 +-- oa-oauth/lib/omniauth/oauth.rb | 1 + oa-oauth/lib/omniauth/strategies/identica.rb | 49 +++++++++++++++++++ .../spec/omniauth/strategies/identica_spec.rb | 13 +++++ 4 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 oa-oauth/lib/omniauth/strategies/identica.rb create mode 100644 oa-oauth/spec/omniauth/strategies/identica_spec.rb diff --git a/oa-oauth/Gemfile.lock b/oa-oauth/Gemfile.lock index b9810f1..87a8e8b 100644 --- a/oa-oauth/Gemfile.lock +++ b/oa-oauth/Gemfile.lock @@ -1,16 +1,16 @@ PATH - remote: /Users/mbleigh/gems/omniauth/oa-core + remote: /home/krawek/Projects/omniauth/oa-core specs: - oa-core (0.1.2) + oa-core (0.1.3) rack (~> 1.1) PATH remote: . specs: - oa-oauth (0.1.2) + oa-oauth (0.1.3) multi_json (~> 0.0.2) nokogiri (~> 1.4.2) - oa-core (= 0.1.2) + oa-core (= 0.1.3) oauth (~> 0.4.0) oauth2 (~> 0.0.10) diff --git a/oa-oauth/lib/omniauth/oauth.rb b/oa-oauth/lib/omniauth/oauth.rb index 696647c..a6d2ea4 100644 --- a/oa-oauth/lib/omniauth/oauth.rb +++ b/oa-oauth/lib/omniauth/oauth.rb @@ -12,5 +12,6 @@ module OmniAuth autoload :ThirtySevenSignals, 'omniauth/strategies/thirty_seven_signals' autoload :Foursquare, 'omniauth/strategies/foursquare' autoload :Gowalla, 'omniauth/strategies/gowalla' + autoload :Identica, 'omniauth/strategies/identica' end end diff --git a/oa-oauth/lib/omniauth/strategies/identica.rb b/oa-oauth/lib/omniauth/strategies/identica.rb new file mode 100644 index 0000000..b038cfd --- /dev/null +++ b/oa-oauth/lib/omniauth/strategies/identica.rb @@ -0,0 +1,49 @@ +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 diff --git a/oa-oauth/spec/omniauth/strategies/identica_spec.rb b/oa-oauth/spec/omniauth/strategies/identica_spec.rb new file mode 100644 index 0000000..a9a0620 --- /dev/null +++ b/oa-oauth/spec/omniauth/strategies/identica_spec.rb @@ -0,0 +1,13 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe 'OmniAuth::Strategies::Identica' do + + it 'should subclass Identica' do + OmniAuth::Strategies::Identica.should < OmniAuth::Strategies::OAuth + end + + it 'should initialize with just consumer key and secret' do + lambda{OmniAuth::Strategies::Identica.new({},'abc','def')}.should_not raise_error + end + +end