1

As per the JWT Bearer token documentation The id_token will be return if there is a pre-existing approval for the openid.

I have existing approvals for openid for the user. Am I missing something in flow.

How can I retrieve or generate an openid using APEX class.

function getToken() {
    var cert = {
        key: fs.readFileSync('key.pem', 'utf-8'),
    };
    claims = {
        "iss": client_key, 
        "sub": username, 
        "aud": salesforceCommunityUrl,
        "exp": new Date().getTime() + 5 * 60
    };
    generated_token = jwt.sign(claims, cert, { algorithm: 'RS256'});
    const formData = {
        grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
        assertion: generated_token,
    };

    var url = salesforceCommunityUrl + tokenUri;
    request.post({url, form: formData}, (err, resp, body) => {
        // There is no id_token that is returned as per the documentation
        res.send(JSON.parse(body));
    });
}
  • 2
    Could you edit your question to show us what you've done so far (the code that's being run) and a specific example of the response you get? – David Reed Jan 6 at 2:29
  • Have you created a connected app? Have you looked at the example code in the JWTBearerTokenExchange Class docs or the Auth Namespace in general? Please post your code.. – crmprogdev Jan 6 at 13:00
  • Yes. I have a connected App. I do get the id_token in case of the web-server and user-agent flow but I don't get it in JWT Bearer Flow – Samual krish Jan 7 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.