@vasrefil/api-toolkit 1.13.7 → 1.14.0
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.
|
@@ -6,6 +6,9 @@ exports.UserApiResp = {
|
|
|
6
6
|
NO_AUTHORIZATION_HEADER: {
|
|
7
7
|
code: 'NAH0401', status: status_interface_1.Status.UN_AUTHORIZED, message: 'Please specify authorization header'
|
|
8
8
|
},
|
|
9
|
+
NO_AUTHORIZATION_TOKEN: {
|
|
10
|
+
code: 'NAT0401', status: status_interface_1.Status.UN_AUTHORIZED, message: 'Please specify authorization token'
|
|
11
|
+
},
|
|
9
12
|
NOT_AUTHORIZED: {
|
|
10
13
|
code: 'NA00401', status: status_interface_1.Status.UN_AUTHORIZED, message: 'You are not authorized'
|
|
11
14
|
},
|
|
@@ -14,6 +14,12 @@ class AdminAuthMidWare_ extends _root_service_1.RootService {
|
|
|
14
14
|
super(...arguments);
|
|
15
15
|
this.get_admin = async (req) => {
|
|
16
16
|
try {
|
|
17
|
+
const authHeader = req.headers.authorization;
|
|
18
|
+
if (!authHeader)
|
|
19
|
+
throw user_response_1.UserApiResp.NO_AUTHORIZATION_HEADER;
|
|
20
|
+
const token = authHeader.split(' ')[1];
|
|
21
|
+
if (!token)
|
|
22
|
+
throw user_response_1.UserApiResp.NO_AUTHORIZATION_TOKEN;
|
|
17
23
|
const baseurl = env_1.default.VASREFIL.BASEURL;
|
|
18
24
|
delete req.headers['host'];
|
|
19
25
|
delete req.headers['content-length'];
|
|
@@ -34,14 +40,11 @@ class AdminAuthMidWare_ extends _root_service_1.RootService {
|
|
|
34
40
|
return async (req, res, next) => {
|
|
35
41
|
try {
|
|
36
42
|
const apiKey = req.headers['api-key'];
|
|
37
|
-
console.log('validate_auth_apiKey', apiKey);
|
|
38
43
|
if (apiKey) {
|
|
39
|
-
console.log('validate_auth_apiKey key found', apiKey);
|
|
40
44
|
if (apiKey !== valid_api_key)
|
|
41
45
|
throw user_response_1.UserApiResp.NO_API_KEY;
|
|
42
46
|
}
|
|
43
47
|
else {
|
|
44
|
-
console.log('validate_auth_else got here');
|
|
45
48
|
const { admin_user } = await this.get_admin(req);
|
|
46
49
|
req.admin = admin_user;
|
|
47
50
|
}
|