feat: allow inject custom headers

This commit is contained in:
Leandro Costa 2023-11-08 23:14:47 -03:00
parent 80eae2e717
commit a49261b767

View file

@ -1,6 +1,6 @@
import qs from "querystring"; import qs from "querystring";
import https from "https"; import https from "https";
import axios, { AxiosRequestConfig } from "axios"; import axios, { AxiosHeaders, AxiosRequestConfig } from "axios";
import { import {
AccessToken, AccessToken,
ContentType, ContentType,
@ -24,7 +24,7 @@ export class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
protected certificado?: string | Buffer; protected certificado?: string | Buffer;
protected senhaCertificado?: string; protected senhaCertificado?: string;
protected authScope?: string; protected authScope?: string;
protected headers?: Headers; protected headers?: AxiosHeaders;
protected grantType?: string; protected grantType?: string;
protected agent: https.Agent; protected agent: https.Agent;
protected accessToken?: iAccessToken; protected accessToken?: iAccessToken;
@ -47,7 +47,7 @@ export class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
} }
this.certificado = params.certificado; 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.apiUrl = params.apiUrl;
this.authUrl = params.authUrl; this.authUrl = params.authUrl;
this.authScope = params.authScope; this.authScope = params.authScope;
@ -144,9 +144,10 @@ export class LhispOauthClient<iAccessToken extends AccessToken = AccessToken> {
try { try {
await this.getAccessToken(); await this.getAccessToken();
let headers = { const headers = {
"Content-Type": contentType, "Content-Type": contentType,
[this.tokenHeaderName]: this.getAuthToken(), [this.tokenHeaderName]: this.getAuthToken(),
...(this.headers || {}),
}; };
const response = await axios.request<ResponseType>({ const response = await axios.request<ResponseType>({