Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions plugins/auth-jwt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ A JWT consists of three parts separated by dots:

1. Configure the request, folder, or workspace to use JWT Authentication
2. Set up your signing algorithm and secret/key
3. Configure the required claims for your JWT
4. The plugin will generate, sign, and include the JWT in your requests
3. Add custom JWT header fields if needed
4. Configure the required claims for your JWT payload
5. The plugin will generate, sign, and include the JWT in your requests

## Common Use Cases

Expand Down
13 changes: 12 additions & 1 deletion plugins/auth-jwt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ export const plugin: PluginDefinition = {
name: 'secretBase64',
label: 'Secret is base64 encoded',
},
{
type: 'editor',
name: 'headers',
label: 'JWT Headers',
language: 'json',
defaultValue: '{}',
placeholder: '{ }',
optional: true,
description: 'Additional JWT header fields',
},
{
type: 'editor',
name: 'payload',
Expand All @@ -56,10 +66,11 @@ export const plugin: PluginDefinition = {
},
],
async onApply(_ctx, { values }) {
const { algorithm, secret: _secret, secretBase64, payload } = values;
const { algorithm, secret: _secret, secretBase64, payload, headers } = values;
const secret = secretBase64 ? Buffer.from(`${_secret}`, 'base64') : `${_secret}`;
const token = jwt.sign(`${payload}`, secret, {
algorithm: algorithm as (typeof algorithms)[number],
header: JSON.parse(`${headers}`),
});
const value = `Bearer ${token}`;
return { setHeaders: [{ name: 'Authorization', value }] };
Expand Down