lhisp-oauth-client 1.0.14 → 1.0.16
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,18 +90,6 @@ 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
|
-
}));
|
|
105
93
|
});
|
|
106
94
|
describe("Request", () => {
|
|
107
95
|
beforeEach(() => {
|
package/package.json
CHANGED
|
@@ -9,7 +9,6 @@ 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;
|
|
13
12
|
protected certificado?: string;
|
|
14
13
|
protected senhaCertificado?: string;
|
|
15
14
|
protected authScope?: string;
|
|
@@ -34,6 +33,7 @@ export declare class LhispOauthClient<iAccessToken extends AccessToken = AccessT
|
|
|
34
33
|
executarRequest<ResponseType>({ method, path, data, params, contentType, }: ExecutarRequestParams): Promise<ResponseType>;
|
|
35
34
|
get<ResponseType>({ path, contentType, params }: ExecutarRequestParams): Promise<ResponseType>;
|
|
36
35
|
put<ResponseType>({ path, data, contentType }: ExecutarRequestParams): Promise<ResponseType>;
|
|
36
|
+
patch<ResponseType>({ path, data, contentType }: ExecutarRequestParams): Promise<ResponseType>;
|
|
37
37
|
post<ResponseType>({ path, data, contentType }: ExecutarRequestParams): Promise<ResponseType>;
|
|
38
38
|
delete<ResponseType>({ path, contentType }: ExecutarRequestParams): Promise<ResponseType>;
|
|
39
39
|
}
|
|
@@ -20,7 +20,6 @@ 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;
|
|
24
23
|
this.tokenCreatedAt = 0;
|
|
25
24
|
this.tokenExpiresIn = 0;
|
|
26
25
|
if (params.certificado) {
|
|
@@ -42,7 +41,6 @@ class LhispOauthClient {
|
|
|
42
41
|
this.authScope = params.authScope;
|
|
43
42
|
this.grantType = params.grantType || lhisp_oauth_client_t_1.defaultGrantType;
|
|
44
43
|
this.authContentType = params.authContentType || lhisp_oauth_client_t_1.defaultAuthContentType;
|
|
45
|
-
this.disableAuthContentType = Boolean(params.disableAuthContentType);
|
|
46
44
|
this.clientId = params.clientId;
|
|
47
45
|
this.clientSecret = params.clientSecret;
|
|
48
46
|
this.authHeaderName = params.authHeaderName || lhisp_oauth_client_t_1.defaultAuthHeaderName;
|
|
@@ -84,7 +82,10 @@ class LhispOauthClient {
|
|
|
84
82
|
method: "POST",
|
|
85
83
|
url: this.authUrl,
|
|
86
84
|
httpsAgent: this.agent,
|
|
87
|
-
headers:
|
|
85
|
+
headers: {
|
|
86
|
+
[this.authHeaderName]: this.getAuthHeaderValue(),
|
|
87
|
+
"Content-Type": this.authContentType,
|
|
88
|
+
},
|
|
88
89
|
data: {},
|
|
89
90
|
};
|
|
90
91
|
if (this.grantType)
|
|
@@ -97,7 +98,10 @@ class LhispOauthClient {
|
|
|
97
98
|
if (this.clientSecret)
|
|
98
99
|
authRequestOpt.data.client_secret = this.clientSecret;
|
|
99
100
|
}
|
|
100
|
-
authRequestOpt.data = this.parseData({
|
|
101
|
+
authRequestOpt.data = this.parseData({
|
|
102
|
+
data: authRequestOpt.data,
|
|
103
|
+
contentType: this.authContentType,
|
|
104
|
+
});
|
|
101
105
|
const resp = yield axios_1.default.request(authRequestOpt);
|
|
102
106
|
this.accessToken = this.buildAccessToken(resp.data);
|
|
103
107
|
this.tokenCreatedAt = new Date().getTime();
|
|
@@ -169,6 +173,16 @@ class LhispOauthClient {
|
|
|
169
173
|
});
|
|
170
174
|
});
|
|
171
175
|
}
|
|
176
|
+
patch({ path, data, contentType = lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON }) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
return this.executarRequest({
|
|
179
|
+
method: "PATCH",
|
|
180
|
+
path,
|
|
181
|
+
data,
|
|
182
|
+
contentType,
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
}
|
|
172
186
|
post({ path, data, contentType = lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON }) {
|
|
173
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
174
188
|
return this.executarRequest({
|
|
@@ -16,7 +16,6 @@ export interface LhispOauthClientConstructorParams {
|
|
|
16
16
|
grantType?: string;
|
|
17
17
|
authContentType?: ContentType;
|
|
18
18
|
sendAuthCredentialsOnRequestBody?: boolean;
|
|
19
|
-
disableAuthContentType?: boolean;
|
|
20
19
|
debug?: boolean;
|
|
21
20
|
}
|
|
22
21
|
export interface ExecutarRequestParams extends AxiosRequestConfig {
|