From d83665d8ffc767b475db9f800a166403cbd2d51f Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sun, 21 Feb 2021 12:05:46 -0500 Subject: [PATCH] fix(rest/request_manager): pass authorization header instead (#534) * fix big brain bot auth on proxy rest * whoops * fix header --- src/bot.ts | 4 ++++ src/rest/request_manager.ts | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 458c2e96b..111f58426 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -10,6 +10,7 @@ import { baseEndpoints, GATEWAY_VERSION } from "./util/constants.ts"; import { spawnShards } from "./ws/shard_manager.ts"; export let authorization = ""; +export let restAuthorization = ""; export let botID = ""; export let applicationID = ""; @@ -94,6 +95,7 @@ export async function startBigBrainBot(data: BigBrainBotConfig) { authorization = `Bot ${data.token}`; identifyPayload.token = `Bot ${data.token}`; + if (data.restAuthorization) restAuthorization = data.restAuthorization; if (data.restURL) baseEndpoints.BASE_URL = data.restURL; if (data.cdnURL) baseEndpoints.CDN_URL = data.cdnURL; if (data.wsURL) proxyWSURL = data.wsURL; @@ -133,4 +135,6 @@ export interface BigBrainBotConfig extends BotConfig { restURL?: string; /** This can be used to forward the CDN handling to a proxy. */ cdnURL?: string; + /** This is the authorization header that your rest proxy will validate */ + restAuthorization?: string; } diff --git a/src/rest/request_manager.ts b/src/rest/request_manager.ts index 421307e03..67a81e7e5 100644 --- a/src/rest/request_manager.ts +++ b/src/rest/request_manager.ts @@ -1,4 +1,4 @@ -import { authorization, eventHandlers } from "../bot.ts"; +import { authorization, eventHandlers, restAuthorization } from "../bot.ts"; import { Errors, FileContent, @@ -221,7 +221,13 @@ function runMethod( !url.startsWith(`${BASE_URL}/v${API_VERSION}`) && !url.startsWith(IMAGE_BASE_URL) ) { - return fetch(url, { method, body: body ? JSON.stringify(body) : undefined }) + return fetch(url, { + method, + body: body ? JSON.stringify(body) : undefined, + headers: { + authorization: restAuthorization, + }, + }) .then((res) => res.json()) .catch((error) => { console.error(error);