Skip to content

Commit

Permalink
JWT plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
gschier committed Jan 17, 2025
1 parent 0644163 commit 16af8bf
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 33 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"workspaces-run": "^1.0.2"
},
"dependencies": {
"@yaakapp/api": "^0.2.27"
"@yaakapp/api": "^0.2.29"
}
}
11 changes: 3 additions & 8 deletions plugins/auth-basic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ export const plugin: PluginDefinition = {
optional: true,
password: true,
}],
async onApply(_ctx: any, args: any): Promise<any> {
async onApply(_ctx, args) {
const { username, password } = args.config;
return {
url: args.url,
headers: [{
name: 'Authorization',
value: 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64'),
}],
};
const value = 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64');
return { setHeaders: [{ name: 'Authorization', value }] };
},
},
};
11 changes: 3 additions & 8 deletions plugins/auth-bearer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ export const plugin: PluginDefinition = {
optional: true,
password: true,
}],
async onApply(_ctx: any, args: any): Promise<any> {
async onApply(_ctx, args) {
const { token } = args.config;
return {
url: args.url,
headers: [{
name: 'Authorization',
value: `Bearer ${token}`.trim(),
}],
};
const value = `Bearer ${token}`.trim();
return { setHeaders: [{ name: 'Authorization', value }] };
},
},
};
13 changes: 6 additions & 7 deletions plugins/auth-jwt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const algorithms = [
'ES256',
'ES384',
'ES512',
];
'none',
] as const;

const defaultAlgorithm = algorithms[0];

Expand All @@ -29,7 +30,7 @@ export const plugin: PluginDefinition = {
name: 'algorithm',
label: 'Algorithm',
defaultValue: defaultAlgorithm,
options: algorithms.map(value => ({ name: value, value })),
options: algorithms.map(value => ({ name: value === 'none' ? 'None' : value, value })),
},
{
type: 'text',
Expand All @@ -53,11 +54,9 @@ export const plugin: PluginDefinition = {
async onApply(_ctx, args) {
const { algorithm, secret: _secret, secretBase64, payload } = args.config;
const secret = secretBase64 ? Buffer.from(`${_secret}`, 'base64') : `${_secret}`;
const token = jwt.sign(`${payload}`, secret, { algorithm: algorithm as any });
return {
url: args.url,
headers: [{ name: 'Authorization', value: `Bearer ${token}` }],
};
const token = secret ? jwt.sign(`${payload}`, secret, { algorithm: algorithm as any }) : jwt.sign(`${payload}`, null);
const value = `Bearer ${token}`;
return { setHeaders: [{ name: 'Authorization', value }] };
}
,
},
Expand Down
10 changes: 5 additions & 5 deletions plugins/template-function-response/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ import { DOMParser } from '@xmldom/xmldom';
import {
CallTemplateFunctionArgs,
Context,
FormInput,
HttpResponse,
PluginDefinition,
RenderPurpose,
TemplateFunctionArg,
} from '@yaakapp/api';
import { JSONPath } from 'jsonpath-plus';
import { readFileSync } from 'node:fs';
import xpath from 'xpath';

const behaviorArg: TemplateFunctionArg = {
const behaviorArg: FormInput = {
type: 'select',
name: 'behavior',
label: 'Sending Behavior',
defaultValue: 'smart',
options: [
{ label: 'When no responses', value: 'smart' },
{ label: 'Always', value: 'always' },
{ name: 'When no responses', value: 'smart' },
{ name: 'Always', value: 'always' },
],
};

const requestArg: TemplateFunctionArg =
const requestArg: FormInput =
{
type: 'http_request',
name: 'request',
Expand Down

0 comments on commit 16af8bf

Please sign in to comment.