Skip to main content Take our 5-minute Community Survey. Open now through 4/11/2025. Click here to participate.
I have to use Oauth JWT flow to got the access token but while i execute my code then it show me following error,

 

{

"error" : "invalid_grant",

"error_description" : "user hasn't approved this consumer"

}

I setup all the related things like create the App and upload the certificate and also create the currect JWT token as per doc Here

and post the following request for access token,

 

HttpPost httpPost = new HttpPost("https://login.salesforce.com/services/oauth2/token");

httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded");

List<NameValuePair> params = new ArrayList<NameValuePair>();

params.add(new BasicNameValuePair("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer"));

params.add(new BasicNameValuePair("assertion", clientAssertion));

httpPost.setEntity(new UrlEncodedFormEntity(params));

HttpResponse response = httpClient.execute(httpPost);

And I also accept the application and related permission by following request,

https://login.salesforce.com/services/oauth2/authorize?client_id=3MVG9ZL0ppGP5UrDITkMBDGuTYGHeynoEt40ZRWCcaYsycFHYDcm2LnqukCNurLNx33LH1c.0rrfG8VrQaqri&redirect_uri=https://localhost/myapp&response_type=code     

I think I done all the things to get the access token but I M GETTING ERROR.

Could you please somebody help me for solving this problem.

Thank You. 
14 answers
  1. Sep 14, 2022, 4:34 PM

    I had the same error. To resolve it, I had to give the permissions to my user (System Administrator) of the connected app.

    Steps to grant permissions:

    * Left sidebar: Apps -> Connected Apps -> Manage Connected Apps

    * Click on "Edit"

    * Select at "Permitted Users" -> "Admin approved users are pre-authorized"

    * Save it

    * In the same section "Manage Connected Apps" click on your connected app to see the policies

    * Section "Profiles" -> click "Manage Profiles" ->  select "System Administrator"

    * Click "Submit" -> Click "OK" in modal windows
  2. Jan 28, 2021, 9:55 PM
    I am still facing the same issue, you guys are not helping in the support team, check google and you will see all developers facing the same althought they follow your corrupted Help forms , You guys leave me no chance but to change to other CRM for integration.
  3. Jun 28, 2016, 2:13 PM
    Hi Jyothsna,

    Thanking you for reply.

    I refer the same link and I follow same to same as per link but then also it give me error. 
  4. Jun 29, 2021, 8:17 PM
    Hi Folks - Thanks for this thread. Based on @tiagobernardo's response here, I got to double-checking my values and found that when connecting to my sandbox SF instance, I was incorrectly using production username (an email address), whereas sandbox account has a slightly different username (email addres + some ".123dev" kind of string appended. Once corrected, my integration against sandbox now works :) I hope this helps someone.
  5. Apr 19, 2021, 12:38 PM

    Hi all!

    I was bagging my head against the wall with this problem; it worked (using a JWT token to request an OAuth Access token) on my developer cloud SalesForce environment (at login.salesforce.com, Organization Edition: Developer Edition) but when I moved to a company Sanbox environment (at test.salesforce.com

    ) it did not work...

    I was following all necessary configurations, everything seemed to be fine, I could generate the JWT token (using the correct value "https://test.salesforce.com" for the Audience ("aud") Claim) but when using it to request the OAuth Access token it was gave me the error:

    {"error":"invalid_grant","error_description":"user hasn't approved this consumer"}

    I was using https://jwt.io to validate content of the Header and Payload of the JWT token:

    Header:

    {

    "alg": "RS256",

    "typ": "JWT"

    }

    Payload (omitting the value for the "iss" Claim):

    {

      "sub": "<an-email-as-a-username>",

      "jti": "9a65de7b-8972-445a-8b36-8fd06d7923f7",

      "nbf": 0,

      "exp": 1618830145,

      "iat": 0,

      "iss": "3MVG9(...omitted...)D3y",

      "aud": "https://test.salesforce.com"

    }

    The problem turned out to be that I was still sending the request for the OAuth Access token, supplying the JWT token, to the URL login.salesforce.com, instead of using the correct URL test.salesforce.com.

    So, double-check that you are sending the request to the correct URL, as for me everything now works!

    Note: Using API Version 51.0.

    --Tiago Bernardo

  6. Jan 31, 2020, 12:37 AM
    Same question, did anyone solve this?

    I authorize my app after opening the link, but getting this error when trying to do an api call

     
  7. May 24, 2019, 12:15 AM
    was anyone able to solve this?

     
0/9000