lhisp-oauth-client 1.0.5 → 1.0.7
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lhisp-oauth-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"main": "src/index",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"repository": "git@bitbucket.org:leandro_costa/lhisp-oauth-client.git",
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
"test:watch": "jest --watchAll"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@types/jest": "^29.
|
|
16
|
-
"@types/node": "^
|
|
17
|
-
"jest": "^29.
|
|
18
|
-
"ts-jest": "^29.0
|
|
19
|
-
"typescript": "^
|
|
15
|
+
"@types/jest": "^29.5.2",
|
|
16
|
+
"@types/node": "^20.3.1",
|
|
17
|
+
"jest": "^29.5.0",
|
|
18
|
+
"ts-jest": "^29.1.0",
|
|
19
|
+
"typescript": "^5.1.3"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"axios": "^1.
|
|
22
|
+
"axios": "^1.4.0"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import https from
|
|
2
|
+
import https from "https";
|
|
3
3
|
import { AccessToken, ContentType, ExecutarRequestParams, LhispOauthClientConstructorParams } from "./lhisp-oauth-client.t";
|
|
4
4
|
export declare class LhispOauthClient {
|
|
5
5
|
protected authUrl: string;
|
|
@@ -26,11 +26,11 @@ export declare class LhispOauthClient {
|
|
|
26
26
|
}): string | undefined;
|
|
27
27
|
isTokenValid(token: AccessToken): boolean;
|
|
28
28
|
getAccessToken(): Promise<AccessToken>;
|
|
29
|
-
buildAccessToken(data: Omit<AccessToken,
|
|
29
|
+
buildAccessToken(data: Omit<AccessToken, "created_at">): AccessToken;
|
|
30
30
|
getAuthToken(): string;
|
|
31
|
-
executarRequest({ method, path, data, params, contentType }: ExecutarRequestParams): Promise<
|
|
32
|
-
get({ path, contentType, params }: ExecutarRequestParams): Promise<
|
|
33
|
-
put({ path, data, contentType }: ExecutarRequestParams): Promise<
|
|
34
|
-
post({ path, data, contentType }: ExecutarRequestParams): Promise<
|
|
35
|
-
delete({ path, contentType }: ExecutarRequestParams): Promise<
|
|
31
|
+
executarRequest<ResponseType>({ method, path, data, params, contentType, }: ExecutarRequestParams): Promise<ResponseType>;
|
|
32
|
+
get<ResponseType>({ path, contentType, params }: ExecutarRequestParams): Promise<ResponseType>;
|
|
33
|
+
put<ResponseType>({ path, data, contentType }: ExecutarRequestParams): Promise<ResponseType>;
|
|
34
|
+
post<ResponseType>({ path, data, contentType }: ExecutarRequestParams): Promise<ResponseType>;
|
|
35
|
+
delete<ResponseType>({ path, contentType }: ExecutarRequestParams): Promise<ResponseType>;
|
|
36
36
|
}
|
|
@@ -28,7 +28,7 @@ class LhispOauthClient {
|
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
30
|
this.agent = new https_1.default.Agent({
|
|
31
|
-
rejectUnauthorized: false
|
|
31
|
+
rejectUnauthorized: false,
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
this.certificado = params.certificado;
|
|
@@ -51,8 +51,10 @@ class LhispOauthClient {
|
|
|
51
51
|
if (!data || Object.keys(data).length === 0)
|
|
52
52
|
return undefined;
|
|
53
53
|
switch (contentType) {
|
|
54
|
-
case lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON:
|
|
55
|
-
|
|
54
|
+
case lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON:
|
|
55
|
+
return JSON.stringify(data);
|
|
56
|
+
case lhisp_oauth_client_t_1.ContentType.APPLICATION_X_WWW_FORM_URLENCODED:
|
|
57
|
+
return querystring_1.default.stringify(data);
|
|
56
58
|
default:
|
|
57
59
|
throw new Error(`Content Type Inválido: [${contentType}]`);
|
|
58
60
|
}
|
|
@@ -72,12 +74,12 @@ class LhispOauthClient {
|
|
|
72
74
|
}
|
|
73
75
|
// TODO: Implementar Refresh Token.
|
|
74
76
|
let authRequestOpt = {
|
|
75
|
-
method:
|
|
77
|
+
method: "POST",
|
|
76
78
|
url: this.authUrl,
|
|
77
79
|
httpsAgent: this.agent,
|
|
78
80
|
headers: {
|
|
79
81
|
[this.authHeaderName]: this.getAuthHeaderValue(),
|
|
80
|
-
|
|
82
|
+
"Content-Type": this.authContentType,
|
|
81
83
|
},
|
|
82
84
|
data: {},
|
|
83
85
|
};
|
|
@@ -91,7 +93,10 @@ class LhispOauthClient {
|
|
|
91
93
|
if (this.clientSecret)
|
|
92
94
|
authRequestOpt.data.client_secret = this.clientSecret;
|
|
93
95
|
}
|
|
94
|
-
authRequestOpt.data = this.parseData({
|
|
96
|
+
authRequestOpt.data = this.parseData({
|
|
97
|
+
data: authRequestOpt.data,
|
|
98
|
+
contentType: this.authContentType,
|
|
99
|
+
});
|
|
95
100
|
const response = yield axios_1.default.request(authRequestOpt);
|
|
96
101
|
return this.buildAccessToken(response.data);
|
|
97
102
|
});
|
|
@@ -104,7 +109,7 @@ class LhispOauthClient {
|
|
|
104
109
|
var _a, _b;
|
|
105
110
|
return `${(_a = this.accessToken) === null || _a === void 0 ? void 0 : _a.token_type} ${(_b = this.accessToken) === null || _b === void 0 ? void 0 : _b.access_token}`;
|
|
106
111
|
}
|
|
107
|
-
executarRequest({ method, path, data, params, contentType = lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON }) {
|
|
112
|
+
executarRequest({ method, path, data, params, contentType = lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON, }) {
|
|
108
113
|
var _a;
|
|
109
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
115
|
yield this.getAccessToken();
|
|
@@ -112,7 +117,7 @@ class LhispOauthClient {
|
|
|
112
117
|
console.log("## LHOAUTH2 NO TOKEN ?:", this.accessToken);
|
|
113
118
|
}
|
|
114
119
|
let headers = {
|
|
115
|
-
|
|
120
|
+
"Content-Type": contentType,
|
|
116
121
|
[this.tokenHeaderName]: this.getAuthToken(),
|
|
117
122
|
// ...this.headers
|
|
118
123
|
};
|
|
@@ -122,29 +127,48 @@ class LhispOauthClient {
|
|
|
122
127
|
httpsAgent: this.agent,
|
|
123
128
|
headers,
|
|
124
129
|
data,
|
|
125
|
-
params
|
|
130
|
+
params,
|
|
126
131
|
});
|
|
127
132
|
return response.data;
|
|
128
133
|
});
|
|
129
134
|
}
|
|
130
135
|
get({ path, contentType = lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON, params }) {
|
|
131
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
return this.executarRequest({
|
|
137
|
+
return this.executarRequest({
|
|
138
|
+
method: "GET",
|
|
139
|
+
path,
|
|
140
|
+
contentType,
|
|
141
|
+
params,
|
|
142
|
+
});
|
|
133
143
|
});
|
|
134
144
|
}
|
|
135
145
|
put({ path, data, contentType = lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON }) {
|
|
136
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
return this.executarRequest({
|
|
147
|
+
return this.executarRequest({
|
|
148
|
+
method: "PUT",
|
|
149
|
+
path,
|
|
150
|
+
data,
|
|
151
|
+
contentType,
|
|
152
|
+
});
|
|
138
153
|
});
|
|
139
154
|
}
|
|
140
155
|
post({ path, data, contentType = lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON }) {
|
|
141
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
return this.executarRequest({
|
|
157
|
+
return this.executarRequest({
|
|
158
|
+
method: "POST",
|
|
159
|
+
path,
|
|
160
|
+
data,
|
|
161
|
+
contentType,
|
|
162
|
+
});
|
|
143
163
|
});
|
|
144
164
|
}
|
|
145
165
|
delete({ path, contentType = lhisp_oauth_client_t_1.ContentType.APPLICATION_JSON }) {
|
|
146
166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
return this.executarRequest({
|
|
167
|
+
return this.executarRequest({
|
|
168
|
+
method: "DELETE",
|
|
169
|
+
path,
|
|
170
|
+
contentType,
|
|
171
|
+
});
|
|
148
172
|
});
|
|
149
173
|
}
|
|
150
174
|
}
|
|
@@ -5,7 +5,7 @@ var ContentType;
|
|
|
5
5
|
(function (ContentType) {
|
|
6
6
|
ContentType["APPLICATION_JSON"] = "application/json";
|
|
7
7
|
ContentType["APPLICATION_X_WWW_FORM_URLENCODED"] = "application/x-www-form-urlencoded";
|
|
8
|
-
})(ContentType
|
|
8
|
+
})(ContentType || (exports.ContentType = ContentType = {}));
|
|
9
9
|
exports.defaultGrantType = 'client_credentials';
|
|
10
10
|
exports.defaultAuthContentType = ContentType.APPLICATION_X_WWW_FORM_URLENCODED;
|
|
11
11
|
exports.defaultAuthHeaderName = 'Authorization';
|