1
0
Fork 0
mirror of https://github.com/omniauth/omniauth.git synced 2022-11-09 12:31:49 -05:00

SmugMug provider as OAuth strategy

This commit is contained in:
Paul Chilton 2010-10-28 21:43:49 +13:00
parent f617741b96
commit fc735077d2
3 changed files with 53 additions and 0 deletions

View file

@ -17,5 +17,6 @@ module OmniAuth
autoload :Dopplr, 'omniauth/strategies/dopplr'
autoload :Meetup, 'omniauth/strategies/meetup'
autoload :SoundCloud, 'omniauth/strategies/sound_cloud'
autoload :SmugMug, 'omniauth/strategies/smug_mug'
end
end

View file

@ -0,0 +1,39 @@
require 'omniauth/oauth'
require 'multi_json'
module OmniAuth
module Strategies
#
# Authenticate to SmugMug via OAuth and retrieve basic user information.
# Usage:
# use OmniAuth::Strategies::SmugMug, 'consumerkey', 'consumersecret'
#
class SmugMug < OmniAuth::Strategies::OAuth
def initialize(app, consumer_key, consumer_secret)
super(app, :smugmug, consumer_key, consumer_secret,
:site => 'http://api.smugmug.com',
:request_token_path => "/services/oauth/getRequestToken.mg",
:access_token_path => "/services/oauth/getAccessToken.mg",
:authorize_path => "/services/oauth/authorize.mg")
end
def auth_hash
OmniAuth::Utils.deep_merge(super, {
'uid' => user_hash['id'],
'user_info' => user_info,
'extra' => { 'user_hash' => user_hash }
})
end
# user info according to schema
def user_info
{ 'nickname' => user_hash['NickName'] }
end
# info as supplied by SmugMug
def user_hash
@user_hash ||= MultiJson.decode(@access_token.get('/services/api/json/1.2.2/?method=smugmug.auth.checkAccessToken').body)['Auth']['User']
end
end
end
end

View file

@ -0,0 +1,13 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe OmniAuth::Strategies::SmugMug do
it 'should subclass OAuth' do
OmniAuth::Strategies::SmugMug.should < OmniAuth::Strategies::OAuth
end
it 'should initialize with just consumer key and secret' do
lambda{OmniAuth::Strategies::SmugMug.new({},'abc','def')}.should_not raise_error
end
end