snapshot of https://github.com/mountain-loop/yaak.git (main, 2026-09-23; blobs > 131072B omitted)
This commit is contained in:
44
plugins/auth-basic/README.md
Normal file
44
plugins/auth-basic/README.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Basic Authentication
|
||||
|
||||
A simple Basic Authentication plugin that implements HTTP Basic Auth according
|
||||
to [RFC 7617](https://datatracker.ietf.org/doc/html/rfc7617), enabling secure
|
||||
authentication with username and password credentials.
|
||||
|
||||

|
||||
|
||||
## Overview
|
||||
|
||||
This plugin provides HTTP Basic Authentication support for API requests in Yaak. Basic
|
||||
Auth is one of the most widely supported authentication methods, making it ideal for APIs
|
||||
that require simple username/password authentication without the complexity of OAuth
|
||||
flows.
|
||||
|
||||
## How Basic Authentication Works
|
||||
|
||||
Basic Authentication encodes your username and password credentials using Base64 encoding
|
||||
and sends them in the `Authorization` header with each request. The format is:
|
||||
|
||||
```
|
||||
Authorization: Basic <base64-encoded-credentials>
|
||||
```
|
||||
|
||||
Where `<base64-encoded-credentials>` is the Base64 encoding of `username:password`.
|
||||
|
||||
## Configuration
|
||||
|
||||
The plugin presents two fields:
|
||||
|
||||
- **Username**: Username or user identifier
|
||||
- **Password**: Password or authentication token
|
||||
|
||||
## Usage
|
||||
|
||||
1. Configure the request, folder, or workspace to use Basic Authentication
|
||||
2. Enter your username and password in the authentication configuration
|
||||
3. The plugin will automatically add the proper `Authorization` header to your requests
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- **401 Unauthorized**: Verify your username and password are correct
|
||||
- **403 Forbidden**: Check if your account has the necessary permissions
|
||||
- **Connection Issues**: Ensure you're using HTTPS for secure transmission
|
||||
17
plugins/auth-basic/package.json
Normal file
17
plugins/auth-basic/package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@yaak/auth-basic",
|
||||
"displayName": "Basic Authentication",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "Authenticate requests using Basic Auth",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mountain-loop/yaak.git",
|
||||
"directory": "plugins/auth-basic"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yaakcli build",
|
||||
"dev": "yaakcli dev",
|
||||
"test": "vp test --run tests"
|
||||
}
|
||||
}
|
||||
30
plugins/auth-basic/src/index.ts
Normal file
30
plugins/auth-basic/src/index.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { PluginDefinition } from "@yaakapp/api";
|
||||
|
||||
export const plugin: PluginDefinition = {
|
||||
authentication: {
|
||||
name: "basic",
|
||||
label: "Basic Auth",
|
||||
shortLabel: "Basic",
|
||||
args: [
|
||||
{
|
||||
type: "text",
|
||||
name: "username",
|
||||
label: "Username",
|
||||
optional: true,
|
||||
},
|
||||
{
|
||||
type: "text",
|
||||
name: "password",
|
||||
label: "Password",
|
||||
optional: true,
|
||||
password: true,
|
||||
},
|
||||
],
|
||||
async onApply(_ctx, { values }) {
|
||||
const username = values.username ?? "";
|
||||
const password = values.password ?? "";
|
||||
const value = `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`;
|
||||
return { setHeaders: [{ name: "Authorization", value }] };
|
||||
},
|
||||
},
|
||||
};
|
||||
87
plugins/auth-basic/tests/index.test.ts
Normal file
87
plugins/auth-basic/tests/index.test.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import type { Context } from "@yaakapp/api";
|
||||
import { describe, expect, test } from "vite-plus/test";
|
||||
import { plugin } from "../src";
|
||||
|
||||
const ctx = {} as Context;
|
||||
|
||||
describe("auth-basic", () => {
|
||||
test("Both username and password", async () => {
|
||||
expect(
|
||||
await plugin.authentication?.onApply(ctx, {
|
||||
values: { username: "user", password: "pass" },
|
||||
headers: [],
|
||||
url: "https://yaak.app",
|
||||
method: "POST",
|
||||
contextId: "111",
|
||||
}),
|
||||
).toEqual({
|
||||
setHeaders: [
|
||||
{ name: "Authorization", value: `Basic ${Buffer.from("user:pass").toString("base64")}` },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("Empty password", async () => {
|
||||
expect(
|
||||
await plugin.authentication?.onApply(ctx, {
|
||||
values: { username: "apikey", password: "" },
|
||||
headers: [],
|
||||
url: "https://yaak.app",
|
||||
method: "POST",
|
||||
contextId: "111",
|
||||
}),
|
||||
).toEqual({
|
||||
setHeaders: [
|
||||
{ name: "Authorization", value: `Basic ${Buffer.from("apikey:").toString("base64")}` },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("Missing password (undefined)", async () => {
|
||||
expect(
|
||||
await plugin.authentication?.onApply(ctx, {
|
||||
values: { username: "apikey" },
|
||||
headers: [],
|
||||
url: "https://yaak.app",
|
||||
method: "POST",
|
||||
contextId: "111",
|
||||
}),
|
||||
).toEqual({
|
||||
setHeaders: [
|
||||
{ name: "Authorization", value: `Basic ${Buffer.from("apikey:").toString("base64")}` },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("Missing username (undefined)", async () => {
|
||||
expect(
|
||||
await plugin.authentication?.onApply(ctx, {
|
||||
values: { password: "secret" },
|
||||
headers: [],
|
||||
url: "https://yaak.app",
|
||||
method: "POST",
|
||||
contextId: "111",
|
||||
}),
|
||||
).toEqual({
|
||||
setHeaders: [
|
||||
{ name: "Authorization", value: `Basic ${Buffer.from(":secret").toString("base64")}` },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("No values (both undefined)", async () => {
|
||||
expect(
|
||||
await plugin.authentication?.onApply(ctx, {
|
||||
values: {},
|
||||
headers: [],
|
||||
url: "https://yaak.app",
|
||||
method: "POST",
|
||||
contextId: "111",
|
||||
}),
|
||||
).toEqual({
|
||||
setHeaders: [
|
||||
{ name: "Authorization", value: `Basic ${Buffer.from(":").toString("base64")}` },
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
3
plugins/auth-basic/tsconfig.json
Normal file
3
plugins/auth-basic/tsconfig.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json"
|
||||
}
|
||||
Reference in New Issue
Block a user