Permalink
Browse files

Actually store the refreshed access token

  • Loading branch information...
1 parent 9897a1e commit 4cd78b4ab8e03298f88cc5ad9b46d32729725e71 @dburkes dburkes committed Sep 21, 2011
@@ -95,10 +95,7 @@ def authenticate(options = nil)
result = req.post(path, "")
log_response(result)
raise SalesForceError.new(result) unless result.is_a?(Net::HTTPOK)
- json = JSON.parse(result.body)
- @user_id = json["id"].match(/\/([^\/]+)$/)[1] rescue nil
- self.instance_url = json["instance_url"]
- self.oauth_token = json["access_token"]
+ parse_auth_response(result.body)
elsif options.is_a?(Hash)
if options.has_key?("provider")
@user_id = options["extra"]["user_hash"]["user_id"] rescue nil
@@ -332,6 +329,9 @@ def ensure_expected_response(expected_result_class)
if response.is_a?(Net::HTTPUnauthorized) && self.refresh_token
with_encoded_path_and_checked_response("/services/oauth2/token", { :grant_type => "refresh_token", :refresh_token => self.refresh_token, :client_id => self.client_id, :client_secret => self.client_secret}) do |encoded_path|
response = https_request(self.host).post(encoded_path, nil)
+ if response.is_a?(Net::HTTPOK)
+ parse_auth_response(response.body)
+ end
response
end
@@ -450,5 +450,12 @@ def key_from_label(label)
def user_and_pass?(options)
(self.username && self.password) || (options && options[:username] && options[:password])
end
+
+ def parse_auth_response(body)
+ json = JSON.parse(body)
+ @user_id = json["id"].match(/\/([^\/]+)$/)[1] rescue nil
+ self.instance_url = json["instance_url"]
+ self.oauth_token = json["access_token"]
+ end
end
end
@@ -3,5 +3,5 @@
"issued_at": "1309974610026",
"instance_url": "https://na1.salesforce.com",
"signature": "sig=",
- "access_token": "access_token"
+ "access_token": "refreshed_access_token"
}
@@ -15,6 +15,11 @@
stub_request(:post, "https://bro.baz/services/oauth2/token?client_id=client_id&client_secret=client_secret&grant_type=refresh_token&refresh_token=refresh").to_return(:body => response_body, :status => 200)
end
+ it "stores the new access token" do
+ @client.send("http_#{request_method_name}", URI.parse(request_url).path, {})
+ @client.oauth_token.should == "refreshed_access_token"
+ end
+
it "retries the request" do
@client.send("http_#{request_method_name}", URI.parse(request_url).path, {})
WebMock.should have_requested(request_method, request_url).twice

0 comments on commit 4cd78b4

Please sign in to comment.