diff --git a/__tests__/lhisp-oauth-client.test.ts b/__tests__/lhisp-oauth-client.test.ts index a47af5b..c4e26bd 100644 --- a/__tests__/lhisp-oauth-client.test.ts +++ b/__tests__/lhisp-oauth-client.test.ts @@ -105,6 +105,24 @@ describe("Get Access Token", () => { }) ); }); + + it("Shoud Get with Credentials without ContentType", async () => { + const cli = getOauthClient({ + ...baseClientParams, + disableAuthContentType: true, + }); + await accessTokenValidator(cli); + expect(mockedAxios.request).toBeCalledWith( + expect.objectContaining({ + url: authUrl, + method: "POST", + headers: { + Authorization: basicAuth, + }, + data: `grant_type=${defaultGrantValue}`, + }) + ); + }); }); describe("Request", () => { diff --git a/package-lock.json b/package-lock.json index 8ef132f..9069b7a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "lhisp-oauth-client", - "version": "1.0.13", + "version": "1.0.14", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "lhisp-oauth-client", - "version": "1.0.13", + "version": "1.0.14", "license": "MIT", "dependencies": { "axios": "^1.4.0", diff --git a/package.json b/package.json index aa68772..abcd646 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lhisp-oauth-client", - "version": "1.0.13", + "version": "1.0.14", "main": "src/index", "types": "src/index.d.ts", "repository": "git@bitbucket.org:leandro_costa/lhisp-oauth-client.git", diff --git a/src/lhisp-oauth-client.t.ts b/src/lhisp-oauth-client.t.ts index cacb4f8..954b77c 100644 --- a/src/lhisp-oauth-client.t.ts +++ b/src/lhisp-oauth-client.t.ts @@ -18,6 +18,7 @@ export interface LhispOauthClientConstructorParams { grantType?: string; authContentType?: ContentType; sendAuthCredentialsOnRequestBody?: boolean; + disableAuthContentType?: boolean; debug?: boolean; } diff --git a/src/lhisp-oauth-client.ts b/src/lhisp-oauth-client.ts index 8c63e33..e51f7a5 100644 --- a/src/lhisp-oauth-client.ts +++ b/src/lhisp-oauth-client.ts @@ -21,6 +21,7 @@ export class LhispOauthClient { protected authHeaderName: string; protected tokenHeaderName: string; protected authContentType: ContentType; + protected disableAuthContentType = false; protected certificado?: string; protected senhaCertificado?: string; protected authScope?: string; @@ -53,6 +54,7 @@ export class LhispOauthClient { this.authScope = params.authScope; this.grantType = params.grantType || defaultGrantType; this.authContentType = params.authContentType || defaultAuthContentType; + this.disableAuthContentType = Boolean(params.disableAuthContentType); this.clientId = params.clientId; this.clientSecret = params.clientSecret; this.authHeaderName = params.authHeaderName || defaultAuthHeaderName; @@ -98,7 +100,7 @@ export class LhispOauthClient { httpsAgent: this.agent, headers: { [this.authHeaderName]: this.getAuthHeaderValue(), - "Content-Type": this.authContentType, + ...(this.disableAuthContentType ? {} : { "Content-Type": this.authContentType }), }, data: {}, }; @@ -111,10 +113,7 @@ export class LhispOauthClient { if (this.clientSecret) authRequestOpt.data.client_secret = this.clientSecret; } - authRequestOpt.data = this.parseData({ - data: authRequestOpt.data, - contentType: this.authContentType, - }); + authRequestOpt.data = this.parseData({ data: authRequestOpt.data, contentType: this.authContentType }); const resp = await axios.request(authRequestOpt); this.accessToken = this.buildAccessToken(resp.data); this.tokenCreatedAt = new Date().getTime();