From 4b854d39357cbcfa43eb833949d48a49b0420ad6 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sun, 4 May 2025 14:14:19 +0100 Subject: Add support for bearer tokens for authorising with RPC. --- docs/RPC/jsonrpc.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'docs/RPC') diff --git a/docs/RPC/jsonrpc.js b/docs/RPC/jsonrpc.js index 8f15a4ee8..76c284553 100644 --- a/docs/RPC/jsonrpc.js +++ b/docs/RPC/jsonrpc.js @@ -8,9 +8,11 @@ class AnopeRPC { * Initializes a new AnopeRPC instance with the specified RPC host. * * @param {string} The RPC host base URL. + * @param {token} The bearer token for authorizing with the RPC token. */ - constructor(host) { + constructor(host, token = "") { this.host = host; + this.token = token; } /** @@ -27,8 +29,13 @@ class AnopeRPC { "params": params, "id": Math.random().toString(36).slice(2) }); + const headers = new Headers(); + if (this.token) { + headers.append("Authorization", `Bearer ${btoa(this.token)}`); + } const response = await fetch(this.host, { method: 'POST', + headers: headers, body: request }); if (!response.ok) { -- cgit