VBA-tools / VBA-Web

VBA-Web: Connect VBA, Excel, Access, and Office for Windows and Mac to web services and the web
http://vba-tools.github.io/VBA-Web/
MIT License
2.01k stars 494 forks source link

Trouble working with Salesforce #256

Closed Smokehouse closed 8 years ago

Smokehouse commented 8 years ago

I've been using an older open source tool, Excel Connector, with great success. But it's built using TLS 1.0 SOAP security access which Salesforce is retiring in the spring of 2017. The developer, Ron Hess, has long since stopped working on this project.

Rather than digging into this old code, I'm looking to build on VBA-Web. It looks great, but I'm stuck getting started with Salesforce. Other sample apps, like Maps, work fine.

I've read in other Issues posts that you haven't done a lot of testing on the Salesforce sample. If I can get this working, I'd be happy to contribute back with some BulkAPI sample implementations.

I created a new developer account at Salesforce, and attempted a Get Object. The Error 400 that I get in response suggests that something is fundamentally wrong with the initial call to get an access token.

Debug text below, with modified password info to protect the innocent.

Thoughts?

--> Request - 2:43:18 PM POST https://login.salesforce.com/services/oauth2/token?grant_type=password&client_id=3MVG9szVa2RxsqBZmtBxmOHisQsUCZNY19IOyic_UzEnr2z5wnbT0a.oPxsF1YxrhsDdYJ69mSM8_DwGvRs9n&client_secret=6202981256669972671&username=egbrown%40yahoo.com&password=PasswordidT9ZLxYTW1VgMbHsUfbbu3E User-Agent: VBA-Web v4.1.1 (https://github.com/VBA-tools/VBA-Web) Content-Type: application/json Accept: application/json Content-Length: 0

<-- Response - 2:44:20 PM 400 Bad Request Cache-Control: no-cache, no-store Date: Sun, 02 Oct 2016 18:44:09 GMT Pragma: no-cache Transfer-Encoding: chunked Content-Type: application/json;charset=UTF-8 Expires: Thu, 01 Jan 1970 00:00:00 GMT Set-Cookie: BrowserId=Hz2ESRUaT8m-dVj43bcOZA;Path=/;Domain=.salesforce.com;Expires=Thu, 01-Dec-2016 18:44:09 GMT Strict-Transport-Security: max-age=10886400; includeSubDomains; preload Content-Security-Policy-Report-Only: default-src https:; script-src https: 'unsafe-inline' 'unsafe-eval'; style-src https: 'unsafe-inline'; img-src https: data:; font-src https: data:; report-uri /_/ContentDomainCSPNoAuth?type=login X-ReadOnlyMode: false Cookie: BrowserId=Hz2ESRUaT8m-dVj43bcOZA

{"error":"unknown_error","error_description":"retry your request"}

ERROR - OAuth2Authenticator.GetToken: -2147210463 (11041 / 80042b21), An error occurred while retrieving token. 400: {"error":"unknown_error","error_description":"retry your request"} ERROR - WebClient.Execute: -2147210493 (11011 / 80042b03), An error occurred during execute -2147210492 (80042b04): An error occurred while preparing http request -2147210463 (80042b21): An error occurred while retrieving token. 400: {"error":"unknown_error","error_description":"retry your request"}

Smokehouse commented 8 years ago

A quick follow up note. Having similar Error 400 problems with Twitter. No problem with the distance sample for Maps. The difference is that Maps doesn't require a login. I used cURL to test the Salesforce POST that VBA-Web generates and that works fine. So I'm assuming that there's something amiss among the authentication code.

The OAuth2Authenticator.Get Token calls WebClient.Execute. The only place in the entire project that calls the [WinHttpRequest].Send is WebClient.Execute. This is where it fails with Error 400. This method passes in a BODY variant (in this case as web_Http.Send Request.Body). At the time of the call, the .Body object is "Empty". I think this is what's causing the error. The code never gets around to loading the .Body object with the key/value pairs.

I'll keep digging. Let me know if you can point me in the right direction.

Smokehouse commented 8 years ago

After much digging I have learned that OAuth2 (at least for Salesforce) requires the token request parameters to be in the URL string in the .Open, not in the Body in the .Send VBA-Web does this correctly. So the whole ado above about "Request.Body being empty" is not really a problem.

So I still have no idea why the Salesforce demo is not working for me. I'm closing this thread. It's off in the wrong direction.