From a49261b767ff7ad95ad373da9e83fb2071688a87 Mon Sep 17 00:00:00 2001 From: Leandro Costa Date: Wed, 8 Nov 2023 23:14:47 -0300 Subject: [PATCH] feat: allow inject custom headers --- src/lhisp-oauth-client.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lhisp-oauth-client.ts b/src/lhisp-oauth-client.ts index 213d8b4..4f60aef 100644 --- a/src/lhisp-oauth-client.ts +++ b/src/lhisp-oauth-client.ts @@ -1,6 +1,6 @@ import qs from "querystring"; import https from "https"; -import axios, { AxiosRequestConfig } from "axios"; +import axios, { AxiosHeaders, AxiosRequestConfig } from "axios"; import { AccessToken, ContentType, @@ -24,7 +24,7 @@ export class LhispOauthClient { protected certificado?: string | Buffer; protected senhaCertificado?: string; protected authScope?: string; - protected headers?: Headers; + protected headers?: AxiosHeaders; protected grantType?: string; protected agent: https.Agent; protected accessToken?: iAccessToken; @@ -47,7 +47,7 @@ export class LhispOauthClient { } this.certificado = params.certificado; - this.headers = (params.headers ? params.headers : {}) as any as Headers; + this.headers = (params.headers ? params.headers : {}) as any as AxiosHeaders; this.apiUrl = params.apiUrl; this.authUrl = params.authUrl; this.authScope = params.authScope; @@ -144,9 +144,10 @@ export class LhispOauthClient { try { await this.getAccessToken(); - let headers = { + const headers = { "Content-Type": contentType, [this.tokenHeaderName]: this.getAuthToken(), + ...(this.headers || {}), }; const response = await axios.request({