0

I am trying to generate a JSON Web Token(JWT) via named credentials as per user. I want to use this named creds for authentication purpose. So that using them after salesforce providing JSON web token, in exchange my local auth server will provide a token.

Below are the settings I have added while creating the named credentials as per user.

Label : TestJWTCredential

Name : TestJWTCredential

URL : -> external-endpoint <-

In Authentication Part

Certificate : MulesoftJWT

Identity Type : Per User

Authentication Protocol : JWT Token Exchange

Token Endpoint Url : http://localhost:8091/api/provider/token

Scope : refresh_token full

Issuer : -> my-username <-

Per User Subject : $userId

Audience : http://localhost:8091/api/provider/token

Token Valid for : 1 Hours

JWT Signing Certificate : MulesoftJWT

Ref :- https://help.salesforce.com/articleView?err=1&id=sf.named_credentials_about.htm&type=5#language-combobox

"http://localhost:8091/api/provider/token" This is the url of my authorization server which is a mule application deployed on my local.

Also while calling this named creds from developer console, it gives this error System.CalloutException: Unable to complete the JWT token exchange. Below is the APEX code,

HttpRequest req = new HttpRequest();

req.setEndpoint('callout:TestJWTCredential/services/oauth2/userinfo');

req.setMethod('GET');

req.setHeader('Authorization', 'Bearer'+ UserInfo.getSessionId());

Http http = new Http();

System.debug('REQUEST :::: ' + req);

HTTPResponse resp = http.send(req);

System.debug('RESPONSE :::: ' + resp.getBody());

Can any body help me how to do it.

identigral
  • 7,543
  • 29
  • 32
  • 42
  • Apex code runs on Salesforce platform, localhost will not resolve. You can try tunneling via ngrok – identigral Feb 01 '21 at 18:12
  • @identigral I tried with the other external URL(https://....) of my mule app as well but it didn't work. I found a article related to it. Could it be the reason why I am not able to use named creds as JWT token exchange.

    It always throws this error : System.CalloutException: Unable to complete the JWT token exchange.

    – Nikita Jaiswal Feb 02 '21 at 10:15
  • Please review this article once... I missed adding it in previous comment. https://salesforce.stackexchange.com/questions/310834/can-we-use-named-credential-with-jwt-auth-to-make-google-cloud-requests – Nikita Jaiswal Feb 02 '21 at 10:34

0 Answers0