0
votes

I'm using OAuth2.0 User-Agent Authentication flow to get the access & refresh tokens so that I can use the Foce.com REST API over remote access. Now, the problem is that I'm able to authorize successfully and recieve the tokens, but while using those tokens just after authorizing my client application, I'm recieving a java.net.ConnectException: Connection refused error.

Following Steps I'm doing

  1. Redirecting to https://login.salesforce.com/services/oauth2/authorize?response_type=token&client_id={my_client_id}&redirect_uri={my_redirect_uri}&state=myState

  2. Authorizing the app in salesforce and then receiving back the access token and refresh tokens in the hash of the redirect_uri as
    {my_redirect_uri}#access_token={my_access_token}&refresh_token={my_refresh_token}&instance_url=https%3A%2F%2Fap1.salesforce.com&id=https%3A%2F%2Flogin.salesforce.com%2Fid%2F00D90000000gscOEAQ%2F00590000000sdtJAAQ&issued_at=1351151192815&signature={my_signature_value}&state=myState &scope=id+api+refresh_token

  3. Now I'm using the REST API using the same access token by doing a POST to https://ap1.salesforce.com/services/data/v20.0/sobjects/Lead/ with request headers:
    Content-Type: application/json
    Authorization: OAuth {my_access_token}

I have not escaped the access token while sending the post as it needs to be done when using CURL. Is that needed when using HttpClient Java API also?

The response that I'm getting is "java.net.ConnectException: Connection refused error." Can someone please let me know what I'm doing wrong or how I can debug it further ?? Is there any way to see whats happening at Salesforce end? Some logs may be ?

I'm getting the exact same connection refused error if I try OAuth Refresh Token Process also.

1

1 Answers

0
votes

Sorry for the noise.

I was getting "invalid_grant" with "expired access/refresh token" while validating the customer secret using the Refresh Token Procedure but since it was secured transmission so all I was getting in Java was "Connection Refused" with no detailed error message.

I got to know the detailed error by Setting up SSL Proxy in Charles as described here. After that I was able to see the request parameters and response send to https://ap1.salesforce.com which was earlier not readable.