[SalesForce] OAuth 2.0 JWT Bearer Token Flow giving a user hasn’t approved this consumer error

I have setup a connected app and want to use the OAuth JWT. Based on my understanding of the salesforce documentation only preauthorized client can use this flow to get an access token.

I have enabled "admin approved users are pre-authorized" setting in my connected and enabled certain profiles under this. the certificate and other settings required for this flow has been set up as well.

I still get the following error while trying to get an access token using the JWT token.

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

the grant_type is set to "urn:ietf:params:oauth:grant-type:jwt-bearer" and assertion: "base64url-encoded JWT token"

Appreciate any help to get this working!

Best Answer

Based from the salesforce documentation:

The authorization server validates the JWT and issues an access_token based upon prior approval of the application.

It means you have to authorize the application at least once.

https://login.salesforce.com/services/oauth2/authorize?client_id=[clientId]&redirect_uri=[redirectUri]&response_type=code

You don't need to work on the redirectUri.

Related Topic