0

I’m coding a sfdx plugin using the new plugin generator found here:

https://github.com/forcedotcom/sfdx-plugin-generate

I was wondering if there’s a way to programatically add a new Salesforce org to the sfdx authenticated orgs.

Imagine invoking a sfdx force:auth:... command directly supplying username and password.

1

You can use JWT grant command, as explained here : https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_auth_jwt_flow.htm ( follow all the steps, and if you need to easily generate a certificate, you can use online sites like https://www.sslchecker.com/csr/self_signed for example )

You will need to locally store the Dev Hub org .crt and .key files , + eventually a JSON file containing your Dev Hub username and clientId

Then call force:auth:jwt:grant like in the example

sfdx force:auth:jwt:grant --clientid YOURDEVHUBCONNECTEDAPPCLIENTID --jwtkeyfile /Path/to/devhub/certificate.key --username YOURSCRATCHORG@USERNAME.COM --instanceurl https://test.salesforce.com

We do that with a groovy script and it works perfectly fine, so i'm confident you can do the same using a SFDX plugin

  • Looks good, too bad it needs to previously create and authorize a connected app otherwise would be perfect for our use case. Since your answer indeed does solve my question I'll mark it as solved. – jonathanwiesel Aug 23 '18 at 11:47

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.