+ Start a Discussion
Naresh2389Naresh2389 

How to authicate SFDX with sandbox

sfdx force:auth:jwt:grant --instanceurl is failing to authenticate with sfdx and sandbox autheication.
SFDX Authentication is working fine for Scratch Org and DevHub Org but failing with Sanbox
J. W.J. W.
Did you try to add more parameters? If I remember correctly there are some required parametes like username, clientId and jwtkeyfile.

Example:
$ sfdx force:auth:jwt:grant -u me@acme.org -f <path to jwt key file> -i <OAuth client id> -r https://acme.my.salesforce.com
Naresh2389Naresh2389
Yes..Its throing error
ERROR running force:auth:jwt:grant:  We encountered a JSON web token error, which is likely not an issue with Salesforce CLI. Here’s the error: client identifier invalid
 
Naresh2389Naresh2389
As part of JWT FLow for sandbox we have one step -> select the DevHub i  am not sure on this as DevHub is applicable in Sandbox
  -> Select the checkbox next to your Dev Hub username, then click Assign 
J. W.J. W.
Regarding your client identifer error. Could you try to hardcode the client Id instead to use the environemnt variables like here (https://salesforce.stackexchange.com/questions/181148/salesforce-dx-client-identifier-invalid)?


 
J. W.J. W.
Hey Naresh, did you find a solution? Is you problem solved?
Rohit RadhakrishnanRohit Radhakrishnan
Incase this is not yet resolved. Please have a look at this blog on authenticating using JWT.
https://salesforcerealm.com/2020/03/07/authenticate-sfdx-using-jwt/
Randy WallaceRandy Wallace
Some things I've learned since setting this up across prod/sandboxes.

* Refreshing/Cloning sandboxes generates a DIFFERENT Client ID in every sandbox in the Connected App when Cloned/Refreshed
* I found that using https://test.salesforce.com/ for the Login Url works with sandboxes (and not the vanity URL)
* note that your Username is different in every sandbox

Taking these things into consideration, I've had no issues logging into all our sandboxes and production, only changing the Client ID, Username, and Login URL.
Randy WallaceRandy Wallace
To revise my comment, when I say "Client ID" I also mean "Consumer Key"; the SFDX Help primarily refers to this value as the Client ID, but in the Setup in the web UI, it is referred to as the Consumer Key.  They are the same thing.