I've been following the documentation on how to create an OAuth token for Salesforce Einstein. I have my private key and able to create the JWT token (code on bottom) yet when I try the CURL command as outlined in the documentation (step 4) with the token I've retrieved I get INVALID JWT Assertion error.
Documentation : https://metamind.readme.io/docs/generate-an-oauth-token-using-your-key
This is how I'm creating the signed JWT
require('dotenv').config();
const jwtToken = require('jsonwebtoken');
const payload =
{
"sub": "<EINSTEIN_PLATFORM_SERVICES_USERNAME>",
"aud": "https://api.einstein.ai/v2/oauth2/token",
"exp": <EXPIRATION_SECONDS_IN_UNIX_TIME>
}
const token = jwtToken.sign(payload, process.env.EINSTEIN_KEY, {algorithm : 'RS256'});
Any idea what I'm doing wrong?
It took me a while to figure this out...the problem was the
UNIXtime I gave was something of the year1970-_- so of course, since theJWTtoken expired I was not able to retrieve an access token fromSalesforce Einstein.I suggest using the following resource to get the correct expiration time in
UNIXseconds : https://www.epochconverter.com/.Here's my final code for generating a
JWT Assertion String:With this code, I was able to retrieve an access token!