2

This is a follow up of the question:

Does SFDX jwt authorization work for scratch orgs as well?

We need to obtain a jsForce connection towards the Scratch Org. After we have created, we select the AuthCode from ScratchOrgInfo and we build the loginUrl from the ActiveScratchOrg as so https://${SignupInstance}.salesforce.com

return new jsforce.Connection({
                instanceUrl: loginUrl,
                clientId: : clientId,
                clientSecret : clientSecret,
                redirectUri: "http://localhost:1717/OauthRedirect",
                accessToken: AuthCode,
                version: '40.0',
              })

using the same clientId we use to perform the jwt auth grant on the DevHub, and the matching clientSecret taken from the DevHub Org. We verified that:

  • our ScratchOrgInfo field ConnectedAppConsumerKey matches the clientId
  • the ConnectedAppCallbackUrl matches the redirectUri in the login

Still, we get

invalid_grant: authentication failure

What are we missing to get the authentication succeed? Also, if the organization has been created some time ago, we notice that we would instead get

invalid_grant: expired authorization code.

One additional strategy we tried was to use the sfdx-cli node package to get the result of force:org:list --json --verbose and pass the accessToken, and now the error is different:

invalid_grant: expired access/refresh token
Edmondo
  • 1,712
  • 16
  • 35
  • are you sure clientSecret is latest one your passing to it. – Umesh Beti Apr 10 '19 at 08:44
  • the error message itself saying it's been authentication failure, the same thing i got few days back(while integrating to the Node api's). check with you email you would have latest token key in it , when you update the password. you would get this. concate it with your password and pass it int password this is missing from you snippet – Umesh Beti Apr 10 '19 at 08:48
  • @UmeshBeti concatenating username and password applies only to the resource owner flow, here we are talking about fully automated processes running on continuos integration server – Edmondo Apr 10 '19 at 08:53

0 Answers0