Skip to main content
Aaron Drake (Ram Servicing) 님이 #Integration에 질문했습니다
I have a new issue now that I am attempting to connect into the app. 

$ sfdx force:auth:jwt:grant --clientid 3M...4p --jwtkeyfile domain.key --username ad....k@force.com.client1 --setdefaultdevhubus

ername --setalias ramservicing -r https://cs69.salesforce.com

Successfully authorized adr.....k@force.com.client1 with org ID 00...AU

After this, I attempt to retrieve an access token within my connected app using this code

jwtflow.getToken(clientId, privateKey, salesForceUserId...

and I get this error returned from salesforce.

Error: Unable to authenticate: invalid_grant (user hasn't approved this consumer)

my connected app has all scopes enabled and oath policy permitted users is set to Admin approved users are pre-authorized.

I have noticed just now that the orgid that is returned from the Salesforce CLI is not the same as what I see in Company Information for sandbox client1.

Why is that?

Company Information

Salesforce.com Organization ID0....R1P

Salesforce CLI

Successfully authorized adrake-cpjk@force.com.client1 with org ID 00.....AU
답변 2개
  1. 2020년 6월 15일 오후 5:25
    Hi,

    You should change the audience of your JWT from "https://login.salesforce.com" to your community URL "https://xxx.force.com"

    Don't forget to change also your url+"/services/oauth2/token" : url = 1st or 2nd url.

    For further reference, you can check the below blogs,

    https://salesforce.stackexchange.com/questions/207685/oauth-2-0-jwt-bearer-token-flow-user-hasnt-approved-this-consumer

    https://salesforce.stackexchange.com/questions/271384/jwt-error-user-hasnt-approved-this-consumer

    I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

    Thanks.

     
0/9000