Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@ export default app => {
}

app.get('/workato-jwt', (req, res) => {
const token = sign(
{
sub: `${process.env.WK_API_KEY}:${process.env.WK_USER_ID}`,
jti: nanoid()
},
process.env.WK_JWT_PRIVATE_KEY,
{algorithm: 'RS256'}
);
const {WK_API_KEY, WK_CUSTOMER_ID, WK_USER_ID, WK_CUSTOM_VENDOR_ORIGIN} = process.env;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const {WK_API_KEY, WK_CUSTOMER_ID, WK_USER_ID, WK_CUSTOM_VENDOR_ORIGIN} = process.env;
const {WK_API_KEY, WK_CUSTOMER_ID, WK_USER_ID, WK_CUSTOM_VENDOR_ORIGIN, WK_JWT_PRIVATE_KEY} = process.env;

const subParams = [WK_API_KEY, WK_CUSTOMER_ID];

if (WK_USER_ID) {
subParams.push(WK_USER_ID);
}

const token = sign(
{
sub: subParams.join(':'),
jti: nanoid(),
origin: WK_CUSTOM_VENDOR_ORIGIN || undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If WK_CUSTOM_VENDOR_ORIGIN is not defined it will be undefined.

Suggested change
origin: WK_CUSTOM_VENDOR_ORIGIN || undefined
origin: WK_CUSTOM_VENDOR_ORIGIN

},
process.env.WK_JWT_PRIVATE_KEY,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can extract this value with another env variables:

Suggested change
process.env.WK_JWT_PRIVATE_KEY,
WK_JWT_PRIVATE_KEY,

{algorithm: 'RS256'}
);


res.json(token);
});
Expand Down