Merging identi.ca support. Closes #45

This commit is contained in:
Michael Bleigh 2010-10-12 10:00:04 -05:00
commit 789e8c0683
3 changed files with 63 additions and 0 deletions

View File

@ -12,5 +12,6 @@ module OmniAuth
autoload :ThirtySevenSignals, 'omniauth/strategies/thirty_seven_signals' autoload :ThirtySevenSignals, 'omniauth/strategies/thirty_seven_signals'
autoload :Foursquare, 'omniauth/strategies/foursquare' autoload :Foursquare, 'omniauth/strategies/foursquare'
autoload :Gowalla, 'omniauth/strategies/gowalla' autoload :Gowalla, 'omniauth/strategies/gowalla'
autoload :Identica, 'omniauth/strategies/identica'
end end
end end

View File

@ -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

View File

@ -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