diff options
author | Sadie Powell <sadie@witchery.services> | 2025-05-04 14:14:19 +0100 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2025-05-04 14:14:19 +0100 |
commit | 4b854d39357cbcfa43eb833949d48a49b0420ad6 (patch) | |
tree | bdc625b02f2366a64c68ed33826250894e1fa9c0 /docs | |
parent | 0b2b00b37dd2e713129a04bdae4c5b8aab858126 (diff) |
Add support for bearer tokens for authorising with RPC.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/RPC/jsonrpc.js | 9 |
1 files changed, 8 insertions, 1 deletions
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) { |