Permalink
Browse files

Merge pull request #505 from bradrobertson/0-3-stable

Update salesforce strategy to send proper OAuth header with token
  • Loading branch information...
Michael Bleigh
Michael Bleigh committed Oct 14, 2011
2 parents 84b75d0 + a0abb77 commit daa60979630ddaf7bfbcb8eaee520e8e113e082e
@@ -37,6 +37,7 @@ module Strategies
autoload :Vimeo, 'omniauth/strategies/oauth/vimeo'
autoload :Yahoo, 'omniauth/strategies/oauth/yahoo'
autoload :YouTube, 'omniauth/strategies/oauth/you_tube'
+ autoload :Xing, 'omniauth/strategies/oauth/xing'
autoload :OAuth2, 'omniauth/strategies/oauth2'
autoload :AngelList, 'omniauth/strategies/oauth2/angellist'
@@ -5,12 +5,22 @@ module Strategies
class Salesforce < OmniAuth::Strategies::OAuth2
def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
client_options = {
- :authorize_url => 'https://login.salesforce.com/services/oauth2/authorize',
- :token_url => 'https://login.salesforce.com/services/oauth2/token',
+ :site => 'https://login.salesforce.com',
+ :authorize_url => '/services/oauth2/authorize',
+ :token_url => '/services/oauth2/token',
}
- options.merge!(:response_type => 'code', :grant_type => 'authorization_code')
super(app, :salesforce, client_id, client_secret, client_options, options, &block)
end
+
+ def request_phase
+ options[:response_type] ||= 'code'
+ super
+ end
+
+ def callback_phase
+ options[:grant_type] ||= 'authorization_code'
+ super
+ end
def auth_hash
data = user_data
@@ -35,10 +45,12 @@ def auth_hash
end
def user_data
- @data ||= MultiJson.decode(@access_token.get(@access_token['id']))
+ @access_token.options[:header_format] = 'OAuth %s'
+
+ @data ||= @access_token.get(@access_token['id']).parsed
rescue ::OAuth2::Error => e
if e.response.status == 302
- @data ||= MultiJson.decode(@access_token.get(e.response.headers['location']))
+ @data ||= @access_token.get(e.response.headers['location']).parsed
else
raise e
end
@@ -1,5 +1,5 @@
require 'spec_helper'
-describe OmniAuth::Strategies::XING do
+describe OmniAuth::Strategies::Xing do
it_should_behave_like "an oauth strategy"
end

0 comments on commit daa6097

Please sign in to comment.