function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Akash MangroliyaAkash Mangroliya 

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

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. 
JyothsnaJyothsna (Salesforce Developers) 
Hi,

You need to authorize the application for once with the "authorize URL". You don't have to make the redirect_uri work.
Authorize Url:
 
https://login.salesforce.com/services/oauth2/authorize?client_id=[client_id]&redirect_uri=[redirect_url]&response_type=code



Regards,
Jyothsna
Akash MangroliyaAkash Mangroliya
Hi Jyothsna,

I authorize the application using following request,
https://login.salesforce.com/services/oauth2/authorize?client_id=3MVG9ZL0ppGP5UrDITkMBDGuTYGHeynoEt40ZRWCcaYsycFHYDcm2LnqukCNurLNx33LH1c.0rrfG8VrQaqri&redirect_uri=https://localhost/myapp&response_type=code

But Still it give the same error.
Akash MangroliyaAkash Mangroliya
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. 
Akash MangroliyaAkash Mangroliya
Hi,
Thank You for help :)
I try to give end point Url in remote site setting but then also it give same error
{
     "error" : "invalid_grant",  
     "error_description" : "user hasn't approved this consumer"
}

 
GT1945GT1945
I also have a user with the same issue, am seeing the error in the logs and as a results leads are not being ingested:

"error" : "invalid_grant", 
  "error_description" : "user hasn't approved this consumer"
 
Admin User 9203Admin User 9203
was anyone able to solve this?
 
Fabian Manzano 6Fabian Manzano 6
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
 
Harleen Mann 8Harleen Mann 8
"user hasn't approved this consumer" This is a common error caused when the user doesn't have a prior refresh_token associated with him/her.

The solution is to perform an Autorization grant (Web Server flow or User-Agent Flow) at least once.

I wrote in detail about it; look **specifically at step #3** here - https://mannharleen.github.io/2020-03-03-salesforce-jwt/

That should solve the error.
Akshay SheteAkshay Shete
I tried step #3(Authorization) many times but with no success; Finally , I went through the entire code and made a bit change in the Body where we pass the parameters :

Just change the order of parameters you are passing for ClaimSet :

Body jsonClaim = new Body(iss,prn,aud,exp); 
.
.
Body(string iss,string prn,string aud,string exp){ this.iss=iss; this.aud=aud; this.prn=prn; this.exp=exp; } 

Hope It works for you as well. Good Luck!
ahmed nader 3ahmed nader 3
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.
Avinash Kumar 90Avinash Kumar 90
Even I have tried all the steps mentioned here
 https://mannharleen.github.io/2020-03-03-salesforce-jwt/
but still getting the error 
  error_description: "user hasn't approved this consumer"

Any ideas about be greatly appreciated
Tiago BernardoTiago Bernardo

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

Bronius MotekaitisBronius Motekaitis
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.
Debargha GangulyDebargha Ganguly
I am still getting this issue and not able to fix it.I have followed the steps as is https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_jwt_flow.htm&type=5&language=en_US.Can someone help me. I have already done the authorization.
Maksym ShynkarenkoMaksym Shynkarenko

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