Skip to main content

Hello,

 

I tried to implement Salesforce Auth JWT but am getting unsupported grant type error.

 

JWTBearerTokenExchange Error 400 unsupported grant type

 

Code:

Auth.JWT jwt = new Auth.JWT();

jwt.setSub('user@email.ca');

jwt.setAud('https://custom.sandbox.lightning.force.com');

jwt.setIss('0000000000000000000000000000000000000000000000000');

Auth.JWS jws = new Auth.JWS(jwt, 'certificate');

String token = jws.getCompactSerialization();

System.debug(token);

String tokenEndpoint = 'https://custom.com/services/rest/auth/oauth2/v1/token';

Auth.JWTBearerTokenExchange bearer = new Auth.JWTBearerTokenExchange(tokenEndpoint, jws);

String accessToken = String.valueOf(bearer.getAccessToken());

//String accessToken = String.valueOf(bearer.getHttpResponse());

System.debug(accessToken);

The bearer grant type was defaulted to urn:ietf:params:oauth:grant-type:jwt-bearer. I tried using Named Credentials instead of Apex implementation and am still getting the same error.

 

How do I resolve this issue?

 

Regards,

Shylesh

 

#Apex #Authentication Token #Auth #JWT Bearer Token Exhcange

1 个回答