From 05f4e4c1e62bc2d665998b928c7b880f7298fe5a Mon Sep 17 00:00:00 2001 From: Leandro Costa Date: Thu, 26 Jan 2023 22:21:28 -0300 Subject: [PATCH] Ajustando definicao de tipos nas funcoes --- src/lhisp-oauth-client.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/lhisp-oauth-client.ts b/src/lhisp-oauth-client.ts index 007f2f5..033d8e2 100644 --- a/src/lhisp-oauth-client.ts +++ b/src/lhisp-oauth-client.ts @@ -4,6 +4,7 @@ import axios, { AxiosRequestConfig } from 'axios'; import { AccessToken, ContentType, defaultAuthContentType, defaultAuthHeaderName, + defaultTokenHeaderName, ExecutarRequestParams, GrantType, LhispOauthClientConstructorParams, } from "./lhisp-oauth-client.t"; @@ -14,6 +15,7 @@ export default class LhispOauthClient { protected clientId: string; protected clientSecret: string; protected authHeaderName: string; + protected tokenHeaderName: string; protected authContentType: ContentType; protected certificado?: string; protected senhaCertificado?: string; @@ -49,6 +51,7 @@ export default class LhispOauthClient { this.clientId = params.clientId; this.clientSecret = params.clientSecret; this.authHeaderName = params.authHeaderName || defaultAuthHeaderName; + this.tokenHeaderName = params.tokenHeaderName || defaultTokenHeaderName; this.sendAuthCredentialsOnRequestBody = params.sendAuthCredentialsOnRequestBody; } @@ -112,7 +115,7 @@ export default class LhispOauthClient { return this.accessToken; } - getRequestAuthToken(){ + getAuthToken(){ return `${this.accessToken?.token_type} ${this.accessToken?.access_token}`; } @@ -124,8 +127,8 @@ export default class LhispOauthClient { let headers = { 'Content-Type': contentType, - [this.authRequestHeader]: this.getRequestAuthToken(), - ...this.headers + [this.tokenHeaderName]: this.getAuthToken(), + // ...this.headers }; const response = await axios({ @@ -140,19 +143,19 @@ export default class LhispOauthClient { return response.data; } - async get({ path, contentType = 'application/json', params }) { + async get({ path, contentType = ContentType.APPLICATION_JSON, params }: ExecutarRequestParams) { return this.executarRequest({ method: 'GET', path, contentType, params }); } - async put({ path, data, contentType = 'application/json' }) { + async put({ path, data, contentType = ContentType.APPLICATION_JSON }: ExecutarRequestParams) { return this.executarRequest({ method: 'PUT', path, data, contentType }); } - async post({ path, data, contentType = 'application/json' }) { + async post({ path, data, contentType = ContentType.APPLICATION_JSON }: ExecutarRequestParams) { return this.executarRequest({ method: 'POST', path, data, contentType }); } - async delete({ path, contentType = 'application/json' }) { + async delete({ path, contentType = ContentType.APPLICATION_JSON }: ExecutarRequestParams) { return this.executarRequest({ method: 'DELETE', path, contentType }); } } \ No newline at end of file