@fonoster/authz 0.8.18 → 0.8.20

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,31 @@ 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
- authz
40
- .checkMethodAuthorized({
41
- accessKeyId,
42
- method
43
- })
44
- .then(() => {
45
- call.sendMessage({ authorized: true }, () => { });
46
- })
47
- .catch((error) => {
48
- logger.verbose("method is not authorized", { method, accessKeyId });
49
- call.sendStatus({
50
- code: grpc_js_1.status.PERMISSION_DENIED,
51
- details: `Method ${method} is not authorized for accessKeyId ${accessKeyId}`
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", {
66
+ method,
67
+ accessKeyId
68
+ });
69
+ next();
70
+ }
71
+ catch (error) {
72
+ logger.verbose("method unauthorized by external service", {
73
+ method,
74
+ accessKeyId
75
+ });
76
+ (0, common_1.createInterceptingCall)({
77
+ call,
78
+ code: grpc_js_1.status.PERMISSION_DENIED,
79
+ details: `Method '${method}' unauthorized by external service - accessKeyId ${accessKeyId}`
80
+ });
81
+ }
82
+ }
53
83
  });
54
- return call;
55
84
  };
56
85
  }
@@ -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.18",
3
+ "version": "0.8.20",
4
4
  "description": "Authorization module for Fonoster",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -26,9 +26,9 @@
26
26
  "access": "public"
27
27
  },
28
28
  "dependencies": {
29
- "@fonoster/common": "^0.8.18",
30
- "@fonoster/identity": "^0.8.18",
31
- "@fonoster/logger": "^0.8.18",
29
+ "@fonoster/common": "^0.8.20",
30
+ "@fonoster/identity": "^0.8.20",
31
+ "@fonoster/logger": "^0.8.20",
32
32
  "@grpc/grpc-js": "~1.10.6",
33
33
  "deepmerge": "^4.3.1",
34
34
  "grpc-health-check": "^2.0.2"
@@ -40,5 +40,5 @@
40
40
  "bugs": {
41
41
  "url": "https://github.com/fonoster/fonoster/issues"
42
42
  },
43
- "gitHead": "83c6089aa8d7d5b9adaf425a80f18925d6a77978"
43
+ "gitHead": "4e605a379fec5ac31bf0a3d2f57cbd54da6c732b"
44
44
  }