0

I develop an Apex class wich calls an web service from another system.

I need to use a JWT to make the authentication but I never used it, so I don't know how to do it.

I read the Salesforce documentation but I am not sure to understand what I esactly have to do.

Do you have an article which deals about it?

Thanks

Oupat
  • 733
  • 16
  • 42

1 Answers1

-2

Just set the header with JWT when calling the web API. Here's some sample code that uses JWT in a http request.

HttpRequest req = new HttpRequest(); 
req.setEndpoint('https://reqres.in/api/users'); 
req.setMethod('GET');
req.setHeader('Authorization', 'Bearer ' + token);

Http http = new Http(); HttpResponse res = http.send(req); Map<String, Object> response;

if (res.getStatusCode() == 200 ) { response = (Map<String, Object>)JSON.deserializeUntyped(res.getBody()); System.debug('response: ' + response); } else { System.debug('Error'); }

Prashanth K
  • 590
  • 2
  • 8