0

I have configured below pre-requisites for JWT based authentication to Salesforce sandbox.

  1. ConnectedApp
  2. server.key
  3. Client Id

I am trying to authenticate Salesforce sandbox from client's Jenkins using below command which is part of Jenkins pipeline.

sfdx auth:jwt:grant --instanceurl https://test.salesforce.com --clientid ${Client_Id} --jwtkeyfile server.key --username ${Username} --json

However, I am getting read ECONNRESET error. Below is the complete json response

{ "status": 1, "name": "JwtGrant", "message": "We encountered a JSON web token error, which is likely not an issue with Salesforce CLI. Here’s the error: Error authenticating with JWT config due to: request to https://test.salesforce.com//services/oauth2/token failed, reason: read ECONNRESET\nrequest to https://login.salesforce.com/services/oauth2/token failed, reason: read ECONNRESET\nrequest to https://test.salesforce.com//services/oauth2/token failed, reason: read ECONNRESET", "exitCode": 1, "context": "Grant", "stack": "JwtGrant: We encountered a JSON web token error, which is likely not an issue with Salesforce CLI. Here’s the error: Error authenticating with JWT config due to: request to https://test.salesforce.com//services/oauth2/token failed, reason: read ECONNRESET\nrequest to https://login.salesforce.com/services/oauth2/token failed, reason: read ECONNRESET\nrequest to https://test.salesforce.com//services/oauth2/token failed, reason: read ECONNRESET\n at Messages.createError (/opt/apps/jenkins/node-v16.15.0-linux-x64/lib/node_modules/sfdx-cli/node_modules/@salesforce/core/lib/messages.js:446:16)\n at Grant.run (/opt/apps/jenkins/node-v16.15.0-linux-x64/lib/node_modules/sfdx-cli/node_modules/@salesforce/plugin-auth/lib/commands/auth/jwt/grant.js:35:28)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\n at async Grant._run (/opt/apps/jenkins/node-v16.15.0-linux-x64/lib/node_modules/sfdx-cli/node_modules/@salesforce/command/lib/sfdxCommand.js:89:40)\n at async Config.runCommand (/opt/apps/jenkins/node-v16.15.0-linux-x64/lib/node_modules/sfdx-cli/node_modules/@oclif/core/lib/config/config.js:272:25)\n at async run (/opt/apps/jenkins/node-v16.15.0-linux-x64/lib/node_modules/sfdx-cli/node_modules/@oclif/core/lib/main.js:76:5)", "warnings": [], "commandName": "Grant" }

With the same set of configuration, I am able to authenticate the same Salesforce sandbox from my local system. To check whether there are any port connectivity issue from client's Jenkins I tried to make Telnet connection to test.salesforce.com and login.salesforce.com on port 443 & telnet was able to communicate to target.

  • telnet test.salesforce.com 443 Trying 13.110.250.33... Connected to test.salesforce.com. Escape character is '^]'. Connection closed by foreign host.

  • telnet login.salesforce.com 443 Trying 13.110.251.32... Connected to login.salesforce.com. Escape character is '^]'. Connection closed by foreign host.

I still suspect that it is underlying network issue. Have anyone faced this type of issue ? Any pointers and help is highly appreciated.

Thanks!

2
  • 1
    Make sure you're on the latest version of sfdx and use instanceurl that is MyDomain-ed. ECONNRESET is usually a proxy issue. telnet might confirm that the port is open but whatever component is intercepting your request might be protocol-specific: it will stop HTTPS but not plain TCP traffic. Usually corporate proxies that rewrite SSL traffic have this property. Use curl or wget to confirm this hypothesis.
    – identigral
    Aug 22, 2022 at 15:21
  • Ok, I did checked earlier with curl and it did timed out for the request. Will check with wget as well. Thanks! Aug 23, 2022 at 8:12

1 Answer 1

1

Post analysis I found that, there was proxy issue which was restricting SFDX CLI to connect to test.salesforce.com or org's domain URL.

You can resolve this if you know the proxy settings of your org or the network you are using.

As I was using this in Jenkins pipeline, what I did is explicitly declare http and https proxy and SFDX CLI was able to pick it to establish connection for authentication. Make sure you replace appropriate values for proxy URL and port.

    environment {
        HTTP_PROXY='http://proxy.yourOrg.com:port/'
        HTTPS_PROXY='http://proxy.youOrg.com:port/'
}
1
  • 1
    Thanks for reporting the outcome of your investigation. Upvoted.
    – identigral
    Aug 26, 2022 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.