mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-18 14:59:42 +02:00
JWT plugin
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@@ -9,7 +9,7 @@
|
|||||||
"plugins/*"
|
"plugins/*"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@yaakapp/api": "^0.2.27"
|
"@yaakapp/api": "^0.2.29"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.7.4",
|
"@types/node": "^22.7.4",
|
||||||
@@ -1013,9 +1013,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@yaakapp/api": {
|
"node_modules/@yaakapp/api": {
|
||||||
"version": "0.2.27",
|
"version": "0.2.29",
|
||||||
"resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.2.27.tgz",
|
"resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.2.29.tgz",
|
||||||
"integrity": "sha512-OkgABeXDxlg3Vx3HbpkIFvAaMTxfqcLQx4X7Tm5/24eZOzbp/n2dtRXRBUcd4w7hI/NjQUetGxjPBTxlJDsQxQ==",
|
"integrity": "sha512-RuyWRUGhYIQjFmaZTYuAekSkidl0b9rWcTV1l+Hs5Pw+LUv8+euedAvNodEJgxAgy42btUns7QUmdM5YNvgoug==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "^22.5.4"
|
"@types/node": "^22.5.4"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,6 @@
|
|||||||
"workspaces-run": "^1.0.2"
|
"workspaces-run": "^1.0.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@yaakapp/api": "^0.2.27"
|
"@yaakapp/api": "^0.2.29"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,10 @@ export const plugin: PluginDefinition = {
|
|||||||
optional: true,
|
optional: true,
|
||||||
password: true,
|
password: true,
|
||||||
}],
|
}],
|
||||||
async onApply(_ctx: any, args: any): Promise<any> {
|
async onApply(_ctx, args) {
|
||||||
const { username, password } = args.config;
|
const { username, password } = args.config;
|
||||||
return {
|
const value = 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64');
|
||||||
url: args.url,
|
return { setHeaders: [{ name: 'Authorization', value }] };
|
||||||
headers: [{
|
|
||||||
name: 'Authorization',
|
|
||||||
value: 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64'),
|
|
||||||
}],
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,15 +12,10 @@ export const plugin: PluginDefinition = {
|
|||||||
optional: true,
|
optional: true,
|
||||||
password: true,
|
password: true,
|
||||||
}],
|
}],
|
||||||
async onApply(_ctx: any, args: any): Promise<any> {
|
async onApply(_ctx, args) {
|
||||||
const { token } = args.config;
|
const { token } = args.config;
|
||||||
return {
|
const value = `Bearer ${token}`.trim();
|
||||||
url: args.url,
|
return { setHeaders: [{ name: 'Authorization', value }] };
|
||||||
headers: [{
|
|
||||||
name: 'Authorization',
|
|
||||||
value: `Bearer ${token}`.trim(),
|
|
||||||
}],
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ const algorithms = [
|
|||||||
'ES256',
|
'ES256',
|
||||||
'ES384',
|
'ES384',
|
||||||
'ES512',
|
'ES512',
|
||||||
];
|
'none',
|
||||||
|
] as const;
|
||||||
|
|
||||||
const defaultAlgorithm = algorithms[0];
|
const defaultAlgorithm = algorithms[0];
|
||||||
|
|
||||||
@@ -29,7 +30,7 @@ export const plugin: PluginDefinition = {
|
|||||||
name: 'algorithm',
|
name: 'algorithm',
|
||||||
label: 'Algorithm',
|
label: 'Algorithm',
|
||||||
defaultValue: defaultAlgorithm,
|
defaultValue: defaultAlgorithm,
|
||||||
options: algorithms.map(value => ({ name: value, value })),
|
options: algorithms.map(value => ({ name: value === 'none' ? 'None' : value, value })),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'text',
|
type: 'text',
|
||||||
@@ -53,11 +54,9 @@ export const plugin: PluginDefinition = {
|
|||||||
async onApply(_ctx, args) {
|
async onApply(_ctx, args) {
|
||||||
const { algorithm, secret: _secret, secretBase64, payload } = args.config;
|
const { algorithm, secret: _secret, secretBase64, payload } = args.config;
|
||||||
const secret = secretBase64 ? Buffer.from(`${_secret}`, 'base64') : `${_secret}`;
|
const secret = secretBase64 ? Buffer.from(`${_secret}`, 'base64') : `${_secret}`;
|
||||||
const token = jwt.sign(`${payload}`, secret, { algorithm: algorithm as any });
|
const token = secret ? jwt.sign(`${payload}`, secret, { algorithm: algorithm as any }) : jwt.sign(`${payload}`, null);
|
||||||
return {
|
const value = `Bearer ${token}`;
|
||||||
url: args.url,
|
return { setHeaders: [{ name: 'Authorization', value }] };
|
||||||
headers: [{ name: 'Authorization', value: `Bearer ${token}` }],
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,27 +2,27 @@ import { DOMParser } from '@xmldom/xmldom';
|
|||||||
import {
|
import {
|
||||||
CallTemplateFunctionArgs,
|
CallTemplateFunctionArgs,
|
||||||
Context,
|
Context,
|
||||||
|
FormInput,
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
PluginDefinition,
|
PluginDefinition,
|
||||||
RenderPurpose,
|
RenderPurpose,
|
||||||
TemplateFunctionArg,
|
|
||||||
} from '@yaakapp/api';
|
} from '@yaakapp/api';
|
||||||
import { JSONPath } from 'jsonpath-plus';
|
import { JSONPath } from 'jsonpath-plus';
|
||||||
import { readFileSync } from 'node:fs';
|
import { readFileSync } from 'node:fs';
|
||||||
import xpath from 'xpath';
|
import xpath from 'xpath';
|
||||||
|
|
||||||
const behaviorArg: TemplateFunctionArg = {
|
const behaviorArg: FormInput = {
|
||||||
type: 'select',
|
type: 'select',
|
||||||
name: 'behavior',
|
name: 'behavior',
|
||||||
label: 'Sending Behavior',
|
label: 'Sending Behavior',
|
||||||
defaultValue: 'smart',
|
defaultValue: 'smart',
|
||||||
options: [
|
options: [
|
||||||
{ label: 'When no responses', value: 'smart' },
|
{ name: 'When no responses', value: 'smart' },
|
||||||
{ label: 'Always', value: 'always' },
|
{ name: 'Always', value: 'always' },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const requestArg: TemplateFunctionArg =
|
const requestArg: FormInput =
|
||||||
{
|
{
|
||||||
type: 'http_request',
|
type: 'http_request',
|
||||||
name: 'request',
|
name: 'request',
|
||||||
|
|||||||
Reference in New Issue
Block a user