2

I connected to Production Org with JWT through connected app without any difficulty. However, by applying the same procedure, I could not connect to Sandbox using JWT.

Here is my command:

sfdx force:auth:jwt:grant --clientid consumerKeyOfConnectedAppInSandbox --jwtkeyfile myKey --username myUsername --setalias aliasName --instanceurl https://test.salesforce.com

And the error message goes:

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: user hasn't approved this consumer

I have granted my profile "System Admin" to the connected app. I even created a permission set with my username inside. But the same error message still appears.

8
  • Did you add that jwtfile file in connected app? or the path for jwt file is correct?
    – Ysr Shk
    Jun 22, 2020 at 4:47
  • Yes, the file is added. I got everything right in Production but in Sandbox it fails. Jun 22, 2020 at 5:57
  • Adding : sfdx force:auth:logout --targetusername %USERNAME% -p to the beginning of my build script fixed this! ref-developer.salesforce.com/forums/?id=9062I000000XrgnQAC
    – Ysr Shk
    Jun 22, 2020 at 6:44
  • Neither is it the issue. I had logged out of my sandbox before I ran this command. Jun 22, 2020 at 6:52
  • Did you create a new connected app in your sandbox, or "install" the same app that you made/use in production? If you "installed" the connected app from production (so that the consumer key is the same), you'll need to go through something like the web-server flow before you can use the JWT flow.
    – Derek F
    Jun 22, 2020 at 11:35

1 Answer 1

1

You need to replace the "https://test.salesforce.com" login url by your full sandbox instance url like "https://mydomain--mysandbox.sandbox.my.salesforce.com"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .