mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 00:58:32 +02:00
JWT auth plugin and updates
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.26"
|
"@yaakapp/api": "^0.2.27"
|
||||||
},
|
},
|
||||||
"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.26",
|
"version": "0.2.27",
|
||||||
"resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.2.26.tgz",
|
"resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.2.27.tgz",
|
||||||
"integrity": "sha512-l9oBrh4oHJHcrdHaUQivFswoTui/32iWjaSP2SDA9tjBFVsuJAs2iKsKNMvCsBkr9bu1dN/si3wg2HmtwhDDxw==",
|
"integrity": "sha512-OkgABeXDxlg3Vx3HbpkIFvAaMTxfqcLQx4X7Tm5/24eZOzbp/n2dtRXRBUcd4w7hI/NjQUetGxjPBTxlJDsQxQ==",
|
||||||
"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.26"
|
"@yaakapp/api": "^0.2.27"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ import { PluginDefinition } from '@yaakapp/api';
|
|||||||
|
|
||||||
export const plugin: PluginDefinition = {
|
export const plugin: PluginDefinition = {
|
||||||
authentication: {
|
authentication: {
|
||||||
name: 'Basic',
|
name: 'basic',
|
||||||
|
label: 'Basic Auth',
|
||||||
|
shortLabel: 'Basic',
|
||||||
config: [{
|
config: [{
|
||||||
type: 'text',
|
type: 'text',
|
||||||
name: 'username',
|
name: 'username',
|
||||||
@@ -13,6 +15,7 @@ export const plugin: PluginDefinition = {
|
|||||||
name: 'password',
|
name: 'password',
|
||||||
label: 'Password',
|
label: 'Password',
|
||||||
optional: true,
|
optional: true,
|
||||||
|
password: true,
|
||||||
}],
|
}],
|
||||||
async onApply(_ctx: any, args: any): Promise<any> {
|
async onApply(_ctx: any, args: any): Promise<any> {
|
||||||
const { username, password } = args.config;
|
const { username, password } = args.config;
|
||||||
|
|||||||
@@ -2,12 +2,15 @@ import { PluginDefinition } from '@yaakapp/api';
|
|||||||
|
|
||||||
export const plugin: PluginDefinition = {
|
export const plugin: PluginDefinition = {
|
||||||
authentication: {
|
authentication: {
|
||||||
name: 'Bearer',
|
name: 'bearer',
|
||||||
|
label: 'Bearer Token',
|
||||||
|
shortLabel: 'Bearer',
|
||||||
config: [{
|
config: [{
|
||||||
type: 'text',
|
type: 'text',
|
||||||
name: 'token',
|
name: 'token',
|
||||||
label: 'Token',
|
label: 'Token',
|
||||||
optional: true,
|
optional: true,
|
||||||
|
password: true,
|
||||||
}],
|
}],
|
||||||
async onApply(_ctx: any, args: any): Promise<any> {
|
async onApply(_ctx: any, args: any): Promise<any> {
|
||||||
const { token } = args.config;
|
const { token } = args.config;
|
||||||
|
|||||||
15
plugins/auth-jwt/package.json
Normal file
15
plugins/auth-jwt/package.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "@yaakapp/auth-jwt",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.1",
|
||||||
|
"scripts": {
|
||||||
|
"build": "yaakcli build ./src/index.ts",
|
||||||
|
"dev": "yaakcli dev ./src/index.js"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"jsonwebtoken": "^9.0.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/jsonwebtoken": "^9.0.7"
|
||||||
|
}
|
||||||
|
}
|
||||||
65
plugins/auth-jwt/src/index.ts
Normal file
65
plugins/auth-jwt/src/index.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import { PluginDefinition } from '@yaakapp/api';
|
||||||
|
import jwt from 'jsonwebtoken';
|
||||||
|
|
||||||
|
const algorithms = [
|
||||||
|
'HS256',
|
||||||
|
'HS384',
|
||||||
|
'HS512',
|
||||||
|
'RS256',
|
||||||
|
'RS384',
|
||||||
|
'RS512',
|
||||||
|
'PS256',
|
||||||
|
'PS384',
|
||||||
|
'PS512',
|
||||||
|
'ES256',
|
||||||
|
'ES384',
|
||||||
|
'ES512',
|
||||||
|
];
|
||||||
|
|
||||||
|
const defaultAlgorithm = algorithms[0];
|
||||||
|
|
||||||
|
export const plugin: PluginDefinition = {
|
||||||
|
authentication: {
|
||||||
|
name: 'jwt',
|
||||||
|
label: 'JWT Bearer',
|
||||||
|
shortLabel: 'JWT',
|
||||||
|
config: [
|
||||||
|
{
|
||||||
|
type: 'select',
|
||||||
|
name: 'algorithm',
|
||||||
|
label: 'Algorithm',
|
||||||
|
defaultValue: defaultAlgorithm,
|
||||||
|
options: algorithms.map(value => ({ name: value, value })),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
name: 'secret',
|
||||||
|
label: 'Secret',
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'checkbox',
|
||||||
|
name: 'secretBase64',
|
||||||
|
label: 'Secret Base64 Encoded',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'editor',
|
||||||
|
name: 'payload',
|
||||||
|
label: 'Payload',
|
||||||
|
language: 'json',
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
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}` }],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
;
|
||||||
Reference in New Issue
Block a user