function generateJwt() { // Replace the example values below (remove the brackets). // Store secrets securely based on your team's best practices. // See: https://help.tableau.com/current/online/en-us/connected_apps_direct.htm
const secret = "ktp38go1Dp/TaHRxLpLrZmjm0gllhyPybRzbddxj95Y="; const secretId = "bc0a67aa-3207-4d1f-b79c-7f35089e716b"; const clientId = "a6030cc0-f71c-4f39-879b-ce7fb9ac4308"; const scopes = ["tableau:views:embed", "tableau:views:embed_authoring"]; const userId = "richard.rawson"; const tokenExpiryInMinutes = 300; // Max of 10 minutes.
const userAttributes = { // User attributes are optional. // Add entries to this dictionary if desired. // "[User Attribute Name]": "[User Attribute Value]", };
const header = { alg: "HS256", typ: "JWT", kid: secretId, iss: clientId, };
const data = { jti: uuidv4(), aud: "tableau", sub: userId, scp: scopes, exp: Math.floor(Date.now() / 1000) + tokenExpiryInMinutes * 60, ...userAttributes, };
const token = jwt.sign(data, secret, { header }); return token; };