lhisp-oauth-client 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -90,6 +90,18 @@ describe("Get Access Token", () => {
90
90
  data: `{"grant_type":"${defaultGrantValue}","client_id":"${clientId}","client_secret":"${clientSecret}"}`,
91
91
  }));
92
92
  }));
93
+ it("Shoud Get with Credentials without ContentType", () => __awaiter(void 0, void 0, void 0, function* () {
94
+ const cli = getOauthClient(Object.assign(Object.assign({}, baseClientParams), { disableAuthContentType: true }));
95
+ yield accessTokenValidator(cli);
96
+ expect(mockedAxios.request).toBeCalledWith(expect.objectContaining({
97
+ url: authUrl,
98
+ method: "POST",
99
+ headers: {
100
+ Authorization: basicAuth,
101
+ },
102
+ data: `grant_type=${defaultGrantValue}`,
103
+ }));
104
+ }));
93
105
  });
94
106
  describe("Request", () => {
95
107
  beforeEach(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lhisp-oauth-client",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "main": "src/index",
5
5
  "types": "src/index.d.ts",
6
6
  "repository": "git@bitbucket.org:leandro_costa/lhisp-oauth-client.git",
@@ -9,6 +9,7 @@ export declare class LhispOauthClient<iAccessToken extends AccessToken = AccessT
9
9
  protected authHeaderName: string;
10
10
  protected tokenHeaderName: string;
11
11
  protected authContentType: ContentType;
12
+ protected disableAuthContentType: boolean;
12
13
  protected certificado?: string;
13
14
  protected senhaCertificado?: string;
14
15
  protected authScope?: string;
@@ -20,6 +20,7 @@ const lhisp_oauth_client_t_1 = require("./lhisp-oauth-client.t");
20
20
  const lhisp_logger_1 = __importDefault(require("lhisp-logger"));
21
21
  class LhispOauthClient {
22
22
  constructor(params) {
23
+ this.disableAuthContentType = false;
23
24
  this.tokenCreatedAt = 0;
24
25
  this.tokenExpiresIn = 0;
25
26
  if (params.certificado) {
@@ -41,6 +42,7 @@ class LhispOauthClient {
41
42
  this.authScope = params.authScope;
42
43
  this.grantType = params.grantType || lhisp_oauth_client_t_1.defaultGrantType;
43
44
  this.authContentType = params.authContentType || lhisp_oauth_client_t_1.defaultAuthContentType;
45
+ this.disableAuthContentType = Boolean(params.disableAuthContentType);
44
46
  this.clientId = params.clientId;
45
47
  this.clientSecret = params.clientSecret;
46
48
  this.authHeaderName = params.authHeaderName || lhisp_oauth_client_t_1.defaultAuthHeaderName;
@@ -82,10 +84,7 @@ class LhispOauthClient {
82
84
  method: "POST",
83
85
  url: this.authUrl,
84
86
  httpsAgent: this.agent,
85
- headers: {
86
- [this.authHeaderName]: this.getAuthHeaderValue(),
87
- "Content-Type": this.authContentType,
88
- },
87
+ headers: Object.assign({ [this.authHeaderName]: this.getAuthHeaderValue() }, (this.disableAuthContentType ? {} : { "Content-Type": this.authContentType })),
89
88
  data: {},
90
89
  };
91
90
  if (this.grantType)
@@ -98,10 +97,7 @@ class LhispOauthClient {
98
97
  if (this.clientSecret)
99
98
  authRequestOpt.data.client_secret = this.clientSecret;
100
99
  }
101
- authRequestOpt.data = this.parseData({
102
- data: authRequestOpt.data,
103
- contentType: this.authContentType,
104
- });
100
+ authRequestOpt.data = this.parseData({ data: authRequestOpt.data, contentType: this.authContentType });
105
101
  const resp = yield axios_1.default.request(authRequestOpt);
106
102
  this.accessToken = this.buildAccessToken(resp.data);
107
103
  this.tokenCreatedAt = new Date().getTime();
@@ -16,6 +16,7 @@ export interface LhispOauthClientConstructorParams {
16
16
  grantType?: string;
17
17
  authContentType?: ContentType;
18
18
  sendAuthCredentialsOnRequestBody?: boolean;
19
+ disableAuthContentType?: boolean;
19
20
  debug?: boolean;
20
21
  }
21
22
  export interface ExecutarRequestParams extends AxiosRequestConfig {