@fonoster/authz 0.8.18 → 0.8.19
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.
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeCheckMethodAuthorized = makeCheckMethodAuthorized;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster/fonoster
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Fonoster
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT License (the "License");
|
|
11
|
+
* you may not use this file except in compliance with
|
|
12
|
+
* the License. You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://opensource.org/licenses/MIT
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
const common_1 = require("@fonoster/common");
|
|
4
23
|
const logger_1 = require("@fonoster/logger");
|
|
5
24
|
const grpc_js_1 = require("@grpc/grpc-js");
|
|
6
25
|
const AuthzClient_1 = require("./client/AuthzClient");
|
|
@@ -36,21 +55,25 @@ function makeCheckMethodAuthorized(authzServer, methods) {
|
|
|
36
55
|
}
|
|
37
56
|
logger.silly("checking if method is authorized", { method });
|
|
38
57
|
const accessKeyId = (0, identity_1.getAccessKeyIdFromCall)(call);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
return new grpc_js_1.ServerInterceptingCall(call, {
|
|
59
|
+
start: async (next) => {
|
|
60
|
+
try {
|
|
61
|
+
await authz.checkMethodAuthorized({
|
|
62
|
+
accessKeyId,
|
|
63
|
+
method
|
|
64
|
+
});
|
|
65
|
+
logger.verbose("method authorized by external service", { method, accessKeyId });
|
|
66
|
+
next();
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
logger.verbose("method unauthorized by external service", { method, accessKeyId });
|
|
70
|
+
(0, common_1.createInterceptingCall)({
|
|
71
|
+
call,
|
|
72
|
+
code: grpc_js_1.status.PERMISSION_DENIED,
|
|
73
|
+
details: `Method '${method}' unauthorized by external service - accessKeyId ${accessKeyId}`
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
53
77
|
});
|
|
54
|
-
return call;
|
|
55
78
|
};
|
|
56
79
|
}
|
|
@@ -75,8 +75,7 @@ class AuthzServer {
|
|
|
75
75
|
const server = new grpc.Server();
|
|
76
76
|
server.addService(serviceDefinition_1.serviceDefinition, {
|
|
77
77
|
checkSessionAuthorized: async (call, callback) => {
|
|
78
|
-
logger.verbose("checkSessionAuthorized called");
|
|
79
|
-
logger.verbose(JSON.stringify(call.request));
|
|
78
|
+
logger.verbose("checkSessionAuthorized called", call.request);
|
|
80
79
|
try {
|
|
81
80
|
const isAuthorized = await handler.checkSessionAuthorized(call.request);
|
|
82
81
|
if (isAuthorized) {
|
|
@@ -98,8 +97,7 @@ class AuthzServer {
|
|
|
98
97
|
}
|
|
99
98
|
},
|
|
100
99
|
checkMethodAuthorized: async (call, callback) => {
|
|
101
|
-
logger.verbose("checkMethodAuthorized called");
|
|
102
|
-
logger.verbose(JSON.stringify(call.request));
|
|
100
|
+
logger.verbose("checkMethodAuthorized called", call.request);
|
|
103
101
|
try {
|
|
104
102
|
const isAuthorized = await handler.checkMethodAuthorized(call.request);
|
|
105
103
|
if (isAuthorized) {
|
|
@@ -121,8 +119,7 @@ class AuthzServer {
|
|
|
121
119
|
}
|
|
122
120
|
},
|
|
123
121
|
addBillingMeterEvent: async (call, callback) => {
|
|
124
|
-
logger.verbose("addBillingMeterEvent called");
|
|
125
|
-
logger.verbose(JSON.stringify(call.request));
|
|
122
|
+
logger.verbose("addBillingMeterEvent called", call.request);
|
|
126
123
|
try {
|
|
127
124
|
const request = {
|
|
128
125
|
accessKeyId: call.request.accessKeyId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/authz",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.19",
|
|
4
4
|
"description": "Authorization module for Fonoster",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"bugs": {
|
|
41
41
|
"url": "https://github.com/fonoster/fonoster/issues"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "3e9b9905b215acd90511512bce1dd42f9897f2a6"
|
|
44
44
|
}
|