From 895b482a026d1425d3a50cc776605dcb375fd658 Mon Sep 17 00:00:00 2001 From: Fleny Date: Thu, 19 Oct 2023 00:21:22 +0200 Subject: [PATCH] Add option for the header of auth on rest proxy (#3153) --- packages/rest/src/manager.ts | 3 ++- packages/rest/src/types.ts | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/rest/src/manager.ts b/packages/rest/src/manager.ts index 007150de0..132ccef3e 100644 --- a/packages/rest/src/manager.ts +++ b/packages/rest/src/manager.ts @@ -84,6 +84,7 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage const rest: RestManager = { applicationId, authorization: options.proxy?.authorization, + authorizationHeader: options.proxy?.authorizationHeader ?? 'authorization', baseUrl, deleteQueueDelay: 60000, globallyRateLimited: false, @@ -464,7 +465,7 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage if (rest.authorization !== undefined) { options ??= {} options.headers ??= {} - options.headers.authorization = rest.authorization + options.headers[rest.authorizationHeader] = rest.authorization } const result = await fetch(`${rest.baseUrl}/v${rest.version}${route}`, rest.createRequestBody(method, options)) diff --git a/packages/rest/src/types.ts b/packages/rest/src/types.ts index e006a223f..92847faa3 100644 --- a/packages/rest/src/types.ts +++ b/packages/rest/src/types.ts @@ -129,8 +129,18 @@ export interface CreateRestManagerOptions { * @default https://discord.com/api */ baseUrl: string - /** The authorization header to attach when sending requests to the proxy. */ + /** The authorization header value to attach when sending requests to the proxy. */ authorization: string + /** + * The authorization header name to use when sending requests to the proxy + * + * @remarks + * If the `authorization` header is used it will override any authorization that is given even if + * the requests uses OAuth2 Bearer tokens / Basic tokens + * + * @default "authorization" // For compatibility purposes + */ + authorizationHeader?: string } /** * The api versions which can be used to make requests. @@ -158,8 +168,10 @@ export interface RestManager { * Mostly used only for intern functions. */ isProxied: boolean - /** The authorization header to attach when sending requests to the proxy. */ + /** The authorization header value to attach when sending requests to the proxy. */ authorization?: string + /** The authorization header name to attach when sending requests to the proxy */ + authorizationHeader: string /** The maximum amount of times a request should be retried. Defaults to Infinity */ maxRetryCount: number /** Whether or not the manager is rate limited globally across all requests. Defaults to false. */