@axinom/mosaic-id-guard 0.11.1 → 0.12.0-rc.3
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/dist/common/authenticated-subject.interface.d.ts +1 -2
- package/dist/common/authenticated-subject.interface.d.ts.map +1 -1
- package/dist/common/authentication-request-context.interface.d.ts +4 -0
- package/dist/common/authentication-request-context.interface.d.ts.map +1 -1
- package/dist/common/guard-error.d.ts +7 -2
- package/dist/common/guard-error.d.ts.map +1 -1
- package/dist/common/guard-error.js +11 -1
- package/dist/common/guard-error.js.map +1 -1
- package/dist/common/guard-utils.d.ts +44 -1
- package/dist/common/guard-utils.d.ts.map +1 -1
- package/dist/common/guard-utils.js +132 -15
- package/dist/common/guard-utils.js.map +1 -1
- package/dist/common/index.d.ts +3 -3
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +1 -3
- package/dist/common/index.js.map +1 -1
- package/dist/common/type-assertions.d.ts +46 -0
- package/dist/common/type-assertions.d.ts.map +1 -0
- package/dist/common/type-assertions.js +96 -0
- package/dist/common/type-assertions.js.map +1 -0
- package/dist/graphql/guard.context.d.ts.map +1 -1
- package/dist/graphql/guard.context.js +18 -6
- package/dist/graphql/guard.context.js.map +1 -1
- package/dist/graphql/guard.plugin.d.ts.map +1 -1
- package/dist/graphql/guard.plugin.js +11 -15
- package/dist/graphql/guard.plugin.js.map +1 -1
- package/dist/graphql/subscription-authorization-hook-factory.d.ts.map +1 -1
- package/dist/graphql/subscription-authorization-hook-factory.js +62 -13
- package/dist/graphql/subscription-authorization-hook-factory.js.map +1 -1
- package/package.json +6 -6
- package/dist/common/assert-consumer-token-type.d.ts +0 -14
- package/dist/common/assert-consumer-token-type.d.ts.map +0 -1
- package/dist/common/assert-consumer-token-type.js +0 -30
- package/dist/common/assert-consumer-token-type.js.map +0 -1
|
@@ -7,7 +7,7 @@ export interface EnvironmentInfo {
|
|
|
7
7
|
environmentId: string;
|
|
8
8
|
}
|
|
9
9
|
/** Authenticated subject information extracted from the JWT token */
|
|
10
|
-
interface GenericAuthenticatedSubject extends EnvironmentInfo {
|
|
10
|
+
export interface GenericAuthenticatedSubject extends EnvironmentInfo {
|
|
11
11
|
/**
|
|
12
12
|
* Issued at (seconds since Unix epoch)
|
|
13
13
|
* @example 1638974572
|
|
@@ -96,5 +96,4 @@ export interface AuthenticatedConsumer extends AuthenticatedConsumerApplication
|
|
|
96
96
|
profileId: string;
|
|
97
97
|
extensions: unknown;
|
|
98
98
|
}
|
|
99
|
-
export {};
|
|
100
99
|
//# sourceMappingURL=authenticated-subject.interface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticated-subject.interface.d.ts","sourceRoot":"","sources":["../../src/common/authenticated-subject.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,qFAAqF;AACrF,MAAM,WAAW,eAAe;IAC9B,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IAEjB,qBAAqB;IACrB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,qEAAqE;AACrE,
|
|
1
|
+
{"version":3,"file":"authenticated-subject.interface.d.ts","sourceRoot":"","sources":["../../src/common/authenticated-subject.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,qFAAqF;AACrF,MAAM,WAAW,eAAe;IAC9B,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAC;IAEjB,qBAAqB;IACrB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,qEAAqE;AACrE,MAAM,WAAW,2BAA4B,SAAQ,eAAe;IAClE;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,8BACf,SAAQ,2BAA2B;IACnC;;;OAGG;IACH,WAAW,EAAE;QACX,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;KACzB,CAAC;IAEF;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,gCACf,SAAQ,2BAA2B;IACnC;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,qBACf,SAAQ,gCAAgC;IACxC;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB,UAAU,EAAE,OAAO,CAAC;CACrB"}
|
|
@@ -25,4 +25,8 @@ export interface AuthenticatedConsumerRequest extends Request {
|
|
|
25
25
|
/** Authenticated subject and error information */
|
|
26
26
|
authContext: ConsumerAuthenticationContext;
|
|
27
27
|
}
|
|
28
|
+
/** An Authenticated Request that has either a `ManagementAuthenticationContext` or a `ConsumerAuthenticationContext` as the authContext */
|
|
29
|
+
export interface AuthenticatedRequest extends Request {
|
|
30
|
+
authContext: ManagementAuthenticationContext | ConsumerAuthenticationContext;
|
|
31
|
+
}
|
|
28
32
|
//# sourceMappingURL=authentication-request-context.interface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication-request-context.interface.d.ts","sourceRoot":"","sources":["../../src/common/authentication-request-context.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,8BAA8B,EAC/B,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,wEAAwE;AACxE,MAAM,WAAW,+BAA+B;IAC9C,mDAAmD;IACnD,OAAO,CAAC,EAAE,8BAA8B,CAAC;IAEzC,uCAAuC;IACvC,aAAa,CAAC,EAAE,gBAAgB,CAAC;CAClC;AAED,mFAAmF;AACnF,MAAM,WAAW,6BAA6B;IAC5C,yCAAyC;IACzC,OAAO,CAAC,EAAE,qBAAqB,GAAG,gCAAgC,CAAC;IAEnE,uCAAuC;IACvC,aAAa,CAAC,EAAE,gBAAgB,CAAC;CAClC;AAED,8DAA8D;AAC9D,MAAM,WAAW,8BAA+B,SAAQ,OAAO;IAC7D,kDAAkD;IAClD,WAAW,EAAE,+BAA+B,CAAC;CAC9C;AAED,4DAA4D;AAC5D,MAAM,WAAW,4BAA6B,SAAQ,OAAO;IAC3D,kDAAkD;IAClD,WAAW,EAAE,6BAA6B,CAAC;CAC5C"}
|
|
1
|
+
{"version":3,"file":"authentication-request-context.interface.d.ts","sourceRoot":"","sources":["../../src/common/authentication-request-context.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,8BAA8B,EAC/B,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,wEAAwE;AACxE,MAAM,WAAW,+BAA+B;IAC9C,mDAAmD;IACnD,OAAO,CAAC,EAAE,8BAA8B,CAAC;IAEzC,uCAAuC;IACvC,aAAa,CAAC,EAAE,gBAAgB,CAAC;CAClC;AAED,mFAAmF;AACnF,MAAM,WAAW,6BAA6B;IAC5C,yCAAyC;IACzC,OAAO,CAAC,EAAE,qBAAqB,GAAG,gCAAgC,CAAC;IAEnE,uCAAuC;IACvC,aAAa,CAAC,EAAE,gBAAgB,CAAC;CAClC;AAED,8DAA8D;AAC9D,MAAM,WAAW,8BAA+B,SAAQ,OAAO;IAC7D,kDAAkD;IAClD,WAAW,EAAE,+BAA+B,CAAC;CAC9C;AAED,4DAA4D;AAC5D,MAAM,WAAW,4BAA6B,SAAQ,OAAO;IAC3D,kDAAkD;IAClD,WAAW,EAAE,6BAA6B,CAAC;CAC5C;AAED,2IAA2I;AAC3I,MAAM,WAAW,oBAAqB,SAAQ,OAAO;IACnD,WAAW,EAAE,+BAA+B,GAAG,6BAA6B,CAAC;CAC9E"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { DefaultError } from '@axinom/mosaic-service-common';
|
|
1
2
|
import { ErrorCode } from './error-code.enum';
|
|
2
|
-
import { DefaultError } from "@axinom/mosaic-service-common";
|
|
3
3
|
export declare class AxGuardErrorInfo {
|
|
4
4
|
code: ErrorCode;
|
|
5
5
|
message: string;
|
|
@@ -9,7 +9,12 @@ export declare class AxGuardErrorInfo {
|
|
|
9
9
|
}
|
|
10
10
|
export declare class AxGuardError extends DefaultError {
|
|
11
11
|
constructor(info: AxGuardErrorInfo);
|
|
12
|
-
|
|
12
|
+
code: string;
|
|
13
13
|
protected details: Record<string, unknown>;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Asserts if a parsed error is of type AxGuardError
|
|
17
|
+
* @param error
|
|
18
|
+
*/
|
|
19
|
+
export declare const assertAxGuardError: (error: unknown) => asserts error is AxGuardError;
|
|
15
20
|
//# sourceMappingURL=guard-error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard-error.d.ts","sourceRoot":"","sources":["../../src/common/guard-error.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"guard-error.d.ts","sourceRoot":"","sources":["../../src/common/guard-error.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAGb,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,qBAAa,gBAAgB;IAElB,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,MAAM;IACf,aAAa,CAAC;IACd,OAAO,CAAC;gBAHR,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,MAAM,EACf,aAAa,CAAC,mBAAO,EACrB,OAAO,CAAC,qCAAyB;CAE3C;AAED,qBAAa,YAAa,SAAQ,YAAY;gBAChC,IAAI,EAAE,gBAAgB;IAWlC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC5C;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,CAC/B,KAAK,EAAE,OAAO,KACX,OAAO,CAAC,KAAK,IAAI,YASrB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AxGuardError = exports.AxGuardErrorInfo = void 0;
|
|
3
|
+
exports.assertAxGuardError = exports.AxGuardError = exports.AxGuardErrorInfo = void 0;
|
|
4
4
|
const mosaic_service_common_1 = require("@axinom/mosaic-service-common");
|
|
5
5
|
class AxGuardErrorInfo {
|
|
6
6
|
constructor(code, message, originalError, details) {
|
|
@@ -25,4 +25,14 @@ class AxGuardError extends mosaic_service_common_1.DefaultError {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
exports.AxGuardError = AxGuardError;
|
|
28
|
+
/**
|
|
29
|
+
* Asserts if a parsed error is of type AxGuardError
|
|
30
|
+
* @param error
|
|
31
|
+
*/
|
|
32
|
+
const assertAxGuardError = (error) => {
|
|
33
|
+
if (!(error instanceof AxGuardError)) {
|
|
34
|
+
throw new mosaic_service_common_1.GeneralError(`A caught error is not an instance of an AxGuardError class.`, { error });
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.assertAxGuardError = assertAxGuardError;
|
|
28
38
|
//# sourceMappingURL=guard-error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard-error.js","sourceRoot":"","sources":["../../src/common/guard-error.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"guard-error.js","sourceRoot":"","sources":["../../src/common/guard-error.ts"],"names":[],"mappings":";;;AAAA,yEAIuC;AAGvC,MAAa,gBAAgB;IAC3B,YACS,IAAe,EACf,OAAe,EACf,aAAqB,EACrB,OAAiC;QAHjC,SAAI,GAAJ,IAAI,CAAW;QACf,YAAO,GAAP,OAAO,CAAQ;QACf,kBAAa,GAAb,aAAa,CAAQ;QACrB,YAAO,GAAP,OAAO,CAA0B;IACvC,CAAC;CACL;AAPD,4CAOC;AAED,MAAa,YAAa,SAAQ,oCAAY;IAC5C,YAAY,IAAsB;;QAChC,IAAI,IAAI,CAAC,aAAa,EAAE;YACtB,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;SACzC;aAAM;YACL,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACrB;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,OAAO,mBAAK,WAAW,EAAX,mCAAW,IAAK,CAAC,MAAA,IAAI,CAAC,OAAO,mCAAI,EAAE,CAAC,CAAE,CAAC;IAC1D,CAAC;CAIF;AAdD,oCAcC;AAED;;;GAGG;AACI,MAAM,kBAAkB,GAEM,CACnC,KAAc,EACiB,EAAE;IACjC,IAAI,CAAC,CAAC,KAAK,YAAY,YAAY,CAAC,EAAE;QACpC,MAAM,IAAI,oCAAY,CACpB,6DAA6D,EAC7D,EAAE,KAAK,EAAE,CACV,CAAC;KACH;AACH,CAAC,CAAC;AAXW,QAAA,kBAAkB,sBAW7B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PermissionDefinition } from '@axinom/mosaic-id-utils';
|
|
2
2
|
import { AuthenticatedManagementSubject } from '.';
|
|
3
|
+
import { GenericAuthenticatedSubject } from './authenticated-subject.interface';
|
|
3
4
|
import { AxGuardErrorInfo } from './guard-error';
|
|
4
5
|
/**
|
|
5
6
|
* Options that are extracted from Postgraphile context and required by IdGuard plugin to check if operation is authorized.
|
|
@@ -28,5 +29,47 @@ export interface AxGuardOptions {
|
|
|
28
29
|
*/
|
|
29
30
|
authorizationOptions: GqlAuthorizationOptions;
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
+
/**
|
|
33
|
+
* This function returns if an operation sent in `GqlAuthorizationOptions` is an Anonymous operation or not.
|
|
34
|
+
* @param options `GqlAuthorizationOptions` object
|
|
35
|
+
* @returns `true` if `options.operation` is an Anonymous operation. `false` otherwise.
|
|
36
|
+
*/
|
|
37
|
+
export declare const isAnonymousOperation: (options: GqlAuthorizationOptions) => boolean;
|
|
38
|
+
/**
|
|
39
|
+
* This function asserts if the subject authentication is valid. It checks if there're any errors in the
|
|
40
|
+
* `errorInfo` found in the `AuthenticationContext`, if the Authenticated Subject is defined and if the token has not expired.
|
|
41
|
+
* If any of these conditions fail, it throws an error.
|
|
42
|
+
*
|
|
43
|
+
* @param user GenericAuthenticatedSubject
|
|
44
|
+
* @param options GqlAuthorizationOptions
|
|
45
|
+
* @param errorInfo AxGuardErrorInfo
|
|
46
|
+
*/
|
|
47
|
+
export declare const assertSubjectAuthenticated: (user: GenericAuthenticatedSubject | undefined, options: GqlAuthorizationOptions, errorInfo: AxGuardErrorInfo | undefined) => void;
|
|
48
|
+
/**
|
|
49
|
+
* This function asserts if a passed `AuthenticatedManagementSubject` has necessary permission to execute a given operation.
|
|
50
|
+
* If any checks fail, it raises an `AxGuardError` with the code `UserNotAuthorized`.
|
|
51
|
+
*
|
|
52
|
+
* @param subject `AuthenticatedManagementSubject`
|
|
53
|
+
* @param options `GqlAuthorizationOptions`
|
|
54
|
+
*/
|
|
55
|
+
export declare const assertSubjectAuthorized: (subject: AuthenticatedManagementSubject, options: GqlAuthorizationOptions) => void;
|
|
56
|
+
/**
|
|
57
|
+
* This function asserts if a passed JWT has not expired.
|
|
58
|
+
* If it has, it throws an `AxGuardError` with code `AccessTokenExpired`.
|
|
59
|
+
* @param accessToken
|
|
60
|
+
* @param serviceId
|
|
61
|
+
*/
|
|
62
|
+
export declare const assertTokenNotExpired: (accessToken: GenericAuthenticatedSubject, serviceId: string) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Returns if a passed Authenticated Subject is a Management Subject
|
|
65
|
+
* @param subject GenericAuthenticatedSubject
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
68
|
+
export declare const isAuthenticatedManagementSubject: (subject: GenericAuthenticatedSubject | undefined) => boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Returns if a passed Authenticated Subject is a Consumer
|
|
71
|
+
* @param subject GenericAuthenticatedSubject
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
export declare const isAuthenticatedConsumer: (subject: GenericAuthenticatedSubject | undefined) => boolean;
|
|
32
75
|
//# sourceMappingURL=guard-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard-utils.d.ts","sourceRoot":"","sources":["../../src/common/guard-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,8BAA8B,
|
|
1
|
+
{"version":3,"file":"guard-utils.d.ts","sourceRoot":"","sources":["../../src/common/guard-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,8BAA8B,EAAe,MAAM,GAAG,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAC;AAEhF,OAAO,EAAgB,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC/D;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,oBAAoB,EAAE,oBAAoB,CAAC;CAC5C;AAED,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,wBAAwB,EAAE,OAAO,CAAC;IAElC;;OAEG;IACH,oBAAoB,EAAE,uBAAuB,CAAC;CAC/C;AAED;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,YACtB,uBAAuB,KAC/B,OAaF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,SAC/B,2BAA2B,GAAG,SAAS,WACpC,uBAAuB,aACrB,gBAAgB,GAAG,SAAS,KACtC,IAiBF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,YACzB,8BAA8B,WAC9B,uBAAuB,KAC/B,IAoCF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,gBACnB,2BAA2B,aAC7B,MAAM,KAChB,IAQF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,YAClC,2BAA2B,GAAG,SAAS,KAC/C,OAsBF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,YACzB,2BAA2B,GAAG,SAAS,KAC/C,OAsBF,CAAC"}
|
|
@@ -1,16 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isAuthenticatedConsumer = exports.isAuthenticatedManagementSubject = exports.assertTokenNotExpired = exports.assertSubjectAuthorized = exports.assertSubjectAuthenticated = exports.isAnonymousOperation = void 0;
|
|
4
4
|
const mosaic_id_utils_1 = require("@axinom/mosaic-id-utils");
|
|
5
|
+
const _1 = require(".");
|
|
5
6
|
const error_code_enum_1 = require("./error-code.enum");
|
|
6
7
|
const guard_error_1 = require("./guard-error");
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* This function returns if an operation sent in `GqlAuthorizationOptions` is an Anonymous operation or not.
|
|
10
|
+
* @param options `GqlAuthorizationOptions` object
|
|
11
|
+
* @returns `true` if `options.operation` is an Anonymous operation. `false` otherwise.
|
|
12
|
+
*/
|
|
13
|
+
const isAnonymousOperation = (options) => {
|
|
8
14
|
var _a, _b;
|
|
9
|
-
const {
|
|
15
|
+
const { permissionDefinition, operation } = options;
|
|
10
16
|
const isAnonymousOperation = (_b = (_a = permissionDefinition.gqlOptions) === null || _a === void 0 ? void 0 : _a.anonymousGqlOperations) === null || _b === void 0 ? void 0 : _b.includes(operation);
|
|
11
17
|
if (isAnonymousOperation) {
|
|
12
18
|
return true;
|
|
13
19
|
}
|
|
20
|
+
return false;
|
|
21
|
+
};
|
|
22
|
+
exports.isAnonymousOperation = isAnonymousOperation;
|
|
23
|
+
/**
|
|
24
|
+
* This function asserts if the subject authentication is valid. It checks if there're any errors in the
|
|
25
|
+
* `errorInfo` found in the `AuthenticationContext`, if the Authenticated Subject is defined and if the token has not expired.
|
|
26
|
+
* If any of these conditions fail, it throws an error.
|
|
27
|
+
*
|
|
28
|
+
* @param user GenericAuthenticatedSubject
|
|
29
|
+
* @param options GqlAuthorizationOptions
|
|
30
|
+
* @param errorInfo AxGuardErrorInfo
|
|
31
|
+
*/
|
|
32
|
+
const assertSubjectAuthenticated = (user, options, errorInfo) => {
|
|
14
33
|
// Error occurred and handled while extracting user information from JWT token
|
|
15
34
|
if (errorInfo !== undefined) {
|
|
16
35
|
throw new guard_error_1.AxGuardError(errorInfo);
|
|
@@ -25,22 +44,120 @@ const isUserAuthorized = (user, options, errorInfo) => {
|
|
|
25
44
|
},
|
|
26
45
|
});
|
|
27
46
|
}
|
|
28
|
-
// Check
|
|
29
|
-
|
|
47
|
+
// Check access-token validity.
|
|
48
|
+
(0, exports.assertTokenNotExpired)(user, options.serviceId);
|
|
49
|
+
};
|
|
50
|
+
exports.assertSubjectAuthenticated = assertSubjectAuthenticated;
|
|
51
|
+
/**
|
|
52
|
+
* This function asserts if a passed `AuthenticatedManagementSubject` has necessary permission to execute a given operation.
|
|
53
|
+
* If any checks fail, it raises an `AxGuardError` with the code `UserNotAuthorized`.
|
|
54
|
+
*
|
|
55
|
+
* @param subject `AuthenticatedManagementSubject`
|
|
56
|
+
* @param options `GqlAuthorizationOptions`
|
|
57
|
+
*/
|
|
58
|
+
const assertSubjectAuthorized = (subject, options) => {
|
|
59
|
+
const { serviceId, permissionDefinition, operation } = options;
|
|
60
|
+
// Not authorized to use this operation
|
|
61
|
+
if (subject.permissions !== undefined && serviceId in subject.permissions) {
|
|
62
|
+
const grantedPermissions = subject.permissions[serviceId];
|
|
63
|
+
const requiredPermissions = (0, mosaic_id_utils_1.getPermissionsForOperation)(operation, permissionDefinition);
|
|
64
|
+
if (!grantedPermissions.some((permission) => requiredPermissions.includes(permission))) {
|
|
65
|
+
throw new guard_error_1.AxGuardError({
|
|
66
|
+
message: 'User is not authorized to access the operation.',
|
|
67
|
+
code: error_code_enum_1.ErrorCode.UserNotAuthorized,
|
|
68
|
+
details: {
|
|
69
|
+
user: subject.sub,
|
|
70
|
+
serviceId: options.serviceId,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
30
76
|
throw new guard_error_1.AxGuardError({
|
|
31
|
-
message: 'User
|
|
77
|
+
message: 'User is not authorized to access the operation.',
|
|
32
78
|
code: error_code_enum_1.ErrorCode.UserNotAuthorized,
|
|
33
|
-
details: {
|
|
79
|
+
details: {
|
|
80
|
+
user: subject.sub,
|
|
81
|
+
serviceId: options.serviceId,
|
|
82
|
+
},
|
|
34
83
|
});
|
|
35
84
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
85
|
+
};
|
|
86
|
+
exports.assertSubjectAuthorized = assertSubjectAuthorized;
|
|
87
|
+
/**
|
|
88
|
+
* This function asserts if a passed JWT has not expired.
|
|
89
|
+
* If it has, it throws an `AxGuardError` with code `AccessTokenExpired`.
|
|
90
|
+
* @param accessToken
|
|
91
|
+
* @param serviceId
|
|
92
|
+
*/
|
|
93
|
+
const assertTokenNotExpired = (accessToken, serviceId) => {
|
|
94
|
+
if (accessToken.exp < new Date().getTime() / 1000) {
|
|
95
|
+
throw new guard_error_1.AxGuardError({
|
|
96
|
+
message: 'User Token has expired.',
|
|
97
|
+
code: error_code_enum_1.ErrorCode.AccessTokenExpired,
|
|
98
|
+
details: { serviceId },
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
exports.assertTokenNotExpired = assertTokenNotExpired;
|
|
103
|
+
/**
|
|
104
|
+
* Returns if a passed Authenticated Subject is a Management Subject
|
|
105
|
+
* @param subject GenericAuthenticatedSubject
|
|
106
|
+
* @returns
|
|
107
|
+
*/
|
|
108
|
+
const isAuthenticatedManagementSubject = (subject) => {
|
|
109
|
+
if (subject === undefined) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
switch (subject.subjectType) {
|
|
114
|
+
case _1.SubjectType.UserAccount:
|
|
115
|
+
case _1.SubjectType.ServiceAccount:
|
|
116
|
+
case _1.SubjectType.ManagedServiceAccount:
|
|
117
|
+
case _1.SubjectType.ImpersonatedUserAccount:
|
|
118
|
+
case _1.SubjectType.SuperUserAccount:
|
|
119
|
+
case _1.SubjectType.EnvironmentAdminAccount:
|
|
120
|
+
return true;
|
|
121
|
+
case _1.SubjectType.ConsumerAccount:
|
|
122
|
+
case _1.SubjectType.ConsumerApplication:
|
|
123
|
+
return false;
|
|
124
|
+
default: {
|
|
125
|
+
// This block would never execute in runtime, and used as a build-time exhaustive switch-case check for the `SubjectType` ENUM.
|
|
126
|
+
const exhaustiveCheck = subject.subjectType;
|
|
127
|
+
throw new Error(`Unhandled SubjectType case: ${exhaustiveCheck}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
exports.isAuthenticatedManagementSubject = isAuthenticatedManagementSubject;
|
|
133
|
+
/**
|
|
134
|
+
* Returns if a passed Authenticated Subject is a Consumer
|
|
135
|
+
* @param subject GenericAuthenticatedSubject
|
|
136
|
+
* @returns
|
|
137
|
+
*/
|
|
138
|
+
const isAuthenticatedConsumer = (subject) => {
|
|
139
|
+
if (subject === undefined) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
switch (subject.subjectType) {
|
|
144
|
+
case _1.SubjectType.ConsumerAccount:
|
|
145
|
+
case _1.SubjectType.ConsumerApplication:
|
|
146
|
+
return true;
|
|
147
|
+
case _1.SubjectType.UserAccount:
|
|
148
|
+
case _1.SubjectType.ServiceAccount:
|
|
149
|
+
case _1.SubjectType.ManagedServiceAccount:
|
|
150
|
+
case _1.SubjectType.ImpersonatedUserAccount:
|
|
151
|
+
case _1.SubjectType.SuperUserAccount:
|
|
152
|
+
case _1.SubjectType.EnvironmentAdminAccount:
|
|
153
|
+
return false;
|
|
154
|
+
default: {
|
|
155
|
+
// This block would never execute in runtime, and used as a build-time exhaustive switch-case check for the `SubjectType` ENUM.
|
|
156
|
+
const exhaustiveCheck = subject.subjectType;
|
|
157
|
+
throw new Error(`Unhandled SubjectType case: ${exhaustiveCheck}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
41
160
|
}
|
|
42
|
-
// Not authorized to use this service
|
|
43
|
-
return false;
|
|
44
161
|
};
|
|
45
|
-
exports.
|
|
162
|
+
exports.isAuthenticatedConsumer = isAuthenticatedConsumer;
|
|
46
163
|
//# sourceMappingURL=guard-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard-utils.js","sourceRoot":"","sources":["../../src/common/guard-utils.ts"],"names":[],"mappings":";;;AAAA,6DAGiC;
|
|
1
|
+
{"version":3,"file":"guard-utils.js","sourceRoot":"","sources":["../../src/common/guard-utils.ts"],"names":[],"mappings":";;;AAAA,6DAGiC;AACjC,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AAO,CAAC,WAAW,CAAC;gBACnD,MAAM,IAAI,KAAK,CAAC,+BAA+B,eAAe,EAAE,CAAC,CAAC;aACnE;SACF;KACF;AACH,CAAC,CAAC;AAxBW,QAAA,uBAAuB,2BAwBlC"}
|
package/dist/common/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from './authenticated-subject.interface';
|
|
1
|
+
export { AuthenticatedConsumer, AuthenticatedConsumerApplication, AuthenticatedManagementSubject, EnvironmentInfo, } from './authenticated-subject.interface';
|
|
3
2
|
export * from './authentication-config.interface';
|
|
4
|
-
export
|
|
3
|
+
export { AuthenticatedConsumerRequest, AuthenticatedManagementRequest, ConsumerAuthenticationContext, ManagementAuthenticationContext, } from './authentication-request-context.interface';
|
|
5
4
|
export * from './error-code.enum';
|
|
6
5
|
export * from './get-authenticated-subject';
|
|
7
6
|
export * from './guard-error';
|
|
8
7
|
export * from './jwt-verify-options';
|
|
9
8
|
export * from './parse-jwt-token';
|
|
10
9
|
export * from './subject-type.enum';
|
|
10
|
+
export * from './type-assertions';
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,8BAA8B,EAC9B,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,EAC9B,6BAA6B,EAC7B,+BAA+B,GAChC,MAAM,4CAA4C,CAAC;AACpD,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
|
package/dist/common/index.js
CHANGED
|
@@ -10,14 +10,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./assert-consumer-token-type"), exports);
|
|
14
|
-
__exportStar(require("./authenticated-subject.interface"), exports);
|
|
15
13
|
__exportStar(require("./authentication-config.interface"), exports);
|
|
16
|
-
__exportStar(require("./authentication-request-context.interface"), exports);
|
|
17
14
|
__exportStar(require("./error-code.enum"), exports);
|
|
18
15
|
__exportStar(require("./get-authenticated-subject"), exports);
|
|
19
16
|
__exportStar(require("./guard-error"), exports);
|
|
20
17
|
__exportStar(require("./jwt-verify-options"), exports);
|
|
21
18
|
__exportStar(require("./parse-jwt-token"), exports);
|
|
22
19
|
__exportStar(require("./subject-type.enum"), exports);
|
|
20
|
+
__exportStar(require("./type-assertions"), exports);
|
|
23
21
|
//# sourceMappingURL=index.js.map
|
package/dist/common/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,oEAAkD;AAOlD,oDAAkC;AAClC,8DAA4C;AAC5C,gDAA8B;AAC9B,uDAAqC;AACrC,oDAAkC;AAClC,sDAAoC;AACpC,oDAAkC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ConsumerAuthenticationContext, ManagementAuthenticationContext } from '.';
|
|
2
|
+
import { AuthenticatedConsumer, AuthenticatedConsumerApplication, AuthenticatedManagementSubject, GenericAuthenticatedSubject } from './authenticated-subject.interface';
|
|
3
|
+
import { AuthenticatedRequest } from './authentication-request-context.interface';
|
|
4
|
+
/**
|
|
5
|
+
* Asserts if the passed subject object is of type AuthenticatedConsumer.
|
|
6
|
+
*
|
|
7
|
+
* @param subject subject object of type unknown
|
|
8
|
+
*/
|
|
9
|
+
export declare const assertAuthenticatedConsumer: (subject: unknown) => asserts subject is AuthenticatedConsumer;
|
|
10
|
+
/**
|
|
11
|
+
* Asserts if the passed subject object is of type AuthenticatedConsumerApplication.
|
|
12
|
+
*
|
|
13
|
+
* @param subject subject object of type unknown
|
|
14
|
+
*/
|
|
15
|
+
export declare const assertConsumerApplication: (subject: unknown) => asserts subject is AuthenticatedConsumerApplication;
|
|
16
|
+
/**
|
|
17
|
+
* Asserts if the passed subject object is of type GenericAuthenticatedSubject.
|
|
18
|
+
*
|
|
19
|
+
* @param subject subject object of type unknown
|
|
20
|
+
*/
|
|
21
|
+
export declare const assertGenericAuthenticatedSubject: (subject: unknown) => asserts subject is GenericAuthenticatedSubject;
|
|
22
|
+
/**
|
|
23
|
+
* Asserts if the passed subject object is of type AuthenticatedManagementSubject.
|
|
24
|
+
*
|
|
25
|
+
* @param subject subject object of type unknown
|
|
26
|
+
*/
|
|
27
|
+
export declare const assertAuthenticatedManagementSubject: (subject: unknown) => asserts subject is AuthenticatedManagementSubject;
|
|
28
|
+
/**
|
|
29
|
+
* Asserts if the passed subject object is of type AuthenticatedRequest.
|
|
30
|
+
*
|
|
31
|
+
* @param subject subject object of type unknown
|
|
32
|
+
*/
|
|
33
|
+
export declare const assertAuthenticatedRequest: (request: unknown) => asserts request is AuthenticatedRequest;
|
|
34
|
+
/**
|
|
35
|
+
* Asserts if the passed context object is of type ManagementAuthenticationContext.
|
|
36
|
+
*
|
|
37
|
+
* @param subject context object of type unknown
|
|
38
|
+
*/
|
|
39
|
+
export declare const assertManagementAuthenticationContext: (context: unknown) => asserts context is ManagementAuthenticationContext;
|
|
40
|
+
/**
|
|
41
|
+
* Asserts if the passed context object is of type ConsumerAuthenticationContext.
|
|
42
|
+
*
|
|
43
|
+
* @param subject context object of type unknown
|
|
44
|
+
*/
|
|
45
|
+
export declare const assertConsumerAuthenticationContext: (context: unknown) => asserts context is ConsumerAuthenticationContext;
|
|
46
|
+
//# sourceMappingURL=type-assertions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-assertions.d.ts","sourceRoot":"","sources":["../../src/common/type-assertions.ts"],"names":[],"mappings":"AACA,OAAO,EACL,6BAA6B,EAC7B,+BAA+B,EAEhC,MAAM,GAAG,CAAC;AACX,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EAChC,8BAA8B,EAC9B,2BAA2B,EAC5B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAMlF;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,EAAE,CACxC,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,OAAO,IAAI,qBASvB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,EAAE,CACtC,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,OAAO,IAAI,gCASvB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,EAAE,CAC9C,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,OAAO,IAAI,2BAMvB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oCAAoC,EAAE,CACjD,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,OAAO,IAAI,8BAUvB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,CACvC,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,OAAO,IAAI,oBAMvB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,qCAAqC,EAAE,CAClD,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,OAAO,IAAI,+BAevB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mCAAmC,EAAE,CAChD,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,OAAO,IAAI,6BAavB,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertConsumerAuthenticationContext = exports.assertManagementAuthenticationContext = exports.assertAuthenticatedRequest = exports.assertAuthenticatedManagementSubject = exports.assertGenericAuthenticatedSubject = exports.assertConsumerApplication = exports.assertAuthenticatedConsumer = void 0;
|
|
4
|
+
const mosaic_service_common_1 = require("@axinom/mosaic-service-common");
|
|
5
|
+
const _1 = require(".");
|
|
6
|
+
const guard_utils_1 = require("./guard-utils");
|
|
7
|
+
/**
|
|
8
|
+
* Asserts if the passed subject object is of type AuthenticatedConsumer.
|
|
9
|
+
*
|
|
10
|
+
* @param subject subject object of type unknown
|
|
11
|
+
*/
|
|
12
|
+
const assertAuthenticatedConsumer = (subject) => {
|
|
13
|
+
if (subject.subjectType !==
|
|
14
|
+
_1.SubjectType.ConsumerAccount) {
|
|
15
|
+
throw new mosaic_service_common_1.GeneralError(`The token is not an Authenticated Consumer`);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.assertAuthenticatedConsumer = assertAuthenticatedConsumer;
|
|
19
|
+
/**
|
|
20
|
+
* Asserts if the passed subject object is of type AuthenticatedConsumerApplication.
|
|
21
|
+
*
|
|
22
|
+
* @param subject subject object of type unknown
|
|
23
|
+
*/
|
|
24
|
+
const assertConsumerApplication = (subject) => {
|
|
25
|
+
if (subject.subjectType !==
|
|
26
|
+
_1.SubjectType.ConsumerApplication) {
|
|
27
|
+
throw new mosaic_service_common_1.GeneralError(`The token is not an Consumer Application`);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.assertConsumerApplication = assertConsumerApplication;
|
|
31
|
+
/**
|
|
32
|
+
* Asserts if the passed subject object is of type GenericAuthenticatedSubject.
|
|
33
|
+
*
|
|
34
|
+
* @param subject subject object of type unknown
|
|
35
|
+
*/
|
|
36
|
+
const assertGenericAuthenticatedSubject = (subject) => {
|
|
37
|
+
if (subject.subjectType === undefined) {
|
|
38
|
+
throw new mosaic_service_common_1.GeneralError(`The object is not a GenericAuthenticatedSubject`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.assertGenericAuthenticatedSubject = assertGenericAuthenticatedSubject;
|
|
42
|
+
/**
|
|
43
|
+
* Asserts if the passed subject object is of type AuthenticatedManagementSubject.
|
|
44
|
+
*
|
|
45
|
+
* @param subject subject object of type unknown
|
|
46
|
+
*/
|
|
47
|
+
const assertAuthenticatedManagementSubject = (subject) => {
|
|
48
|
+
if (!(0, guard_utils_1.isAuthenticatedManagementSubject)(subject)) {
|
|
49
|
+
throw new mosaic_service_common_1.GeneralError(`The object is not a AuthenticatedManagementSubject`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.assertAuthenticatedManagementSubject = assertAuthenticatedManagementSubject;
|
|
53
|
+
/**
|
|
54
|
+
* Asserts if the passed subject object is of type AuthenticatedRequest.
|
|
55
|
+
*
|
|
56
|
+
* @param subject subject object of type unknown
|
|
57
|
+
*/
|
|
58
|
+
const assertAuthenticatedRequest = (request) => {
|
|
59
|
+
if (request.authContext === undefined) {
|
|
60
|
+
throw new mosaic_service_common_1.GeneralError(`The object is not a AuthenticatedRequest`);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
exports.assertAuthenticatedRequest = assertAuthenticatedRequest;
|
|
64
|
+
/**
|
|
65
|
+
* Asserts if the passed context object is of type ManagementAuthenticationContext.
|
|
66
|
+
*
|
|
67
|
+
* @param subject context object of type unknown
|
|
68
|
+
*/
|
|
69
|
+
const assertManagementAuthenticationContext = (context) => {
|
|
70
|
+
const managementAuthContext = context;
|
|
71
|
+
if ((managementAuthContext.subject === undefined &&
|
|
72
|
+
managementAuthContext.authErrorInfo === undefined) ||
|
|
73
|
+
// the call to isAuthenticatedManagementSubject should only happen if a subject is available in the ManagementAuthenticationContext
|
|
74
|
+
(managementAuthContext.subject !== undefined &&
|
|
75
|
+
!(0, guard_utils_1.isAuthenticatedManagementSubject)(managementAuthContext.subject))) {
|
|
76
|
+
throw new mosaic_service_common_1.GeneralError(`The object is not a ManagementAuthenticationContext`);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
exports.assertManagementAuthenticationContext = assertManagementAuthenticationContext;
|
|
80
|
+
/**
|
|
81
|
+
* Asserts if the passed context object is of type ConsumerAuthenticationContext.
|
|
82
|
+
*
|
|
83
|
+
* @param subject context object of type unknown
|
|
84
|
+
*/
|
|
85
|
+
const assertConsumerAuthenticationContext = (context) => {
|
|
86
|
+
const consumerAuthContext = context;
|
|
87
|
+
if ((consumerAuthContext.subject === undefined &&
|
|
88
|
+
consumerAuthContext.authErrorInfo === undefined) ||
|
|
89
|
+
// the call to isAuthenticatedConsumer should only happen if a subject is available in the ConsumerAuthenticationContext
|
|
90
|
+
(consumerAuthContext.subject !== undefined &&
|
|
91
|
+
!(0, guard_utils_1.isAuthenticatedConsumer)(consumerAuthContext.subject))) {
|
|
92
|
+
throw new mosaic_service_common_1.GeneralError(`The object is not a ConsumerAuthenticationContext`);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
exports.assertConsumerAuthenticationContext = assertConsumerAuthenticationContext;
|
|
96
|
+
//# sourceMappingURL=type-assertions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-assertions.js","sourceRoot":"","sources":["../../src/common/type-assertions.ts"],"names":[],"mappings":";;;AAAA,yEAA6D;AAC7D,wBAIW;AAQX,+CAGuB;AAEvB;;;;GAIG;AACI,MAAM,2BAA2B,GAEQ,CAC9C,OAAgB,EAC0B,EAAE;IAC5C,IACG,OAAiC,CAAC,WAAW;QAC9C,cAAW,CAAC,eAAe,EAC3B;QACA,MAAM,IAAI,oCAAY,CAAC,4CAA4C,CAAC,CAAC;KACt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CAAgC,EAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,EACnE;QACA,MAAM,IAAI,oCAAY,CACpB,qDAAqD,CACtD,CAAC;KACH;AACH,CAAC,CAAC;AAjBW,QAAA,qCAAqC,yCAiBhD;AAEF;;;;GAIG;AACI,MAAM,mCAAmC,GAEQ,CACtD,OAAgB,EACkC,EAAE;IACpD,MAAM,mBAAmB,GAAG,OAAwC,CAAC;IACrE,IACE,CAAC,mBAAmB,CAAC,OAAO,KAAK,SAAS;QACxC,mBAAmB,CAAC,aAAa,KAAK,SAAS,CAAC;QAClD,wHAAwH;QACxH,CAAC,mBAAmB,CAAC,OAAO,KAAK,SAAS;YACxC,CAAC,IAAA,qCAAuB,EAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,EACxD;QACA,MAAM,IAAI,oCAAY,CAAC,mDAAmD,CAAC,CAAC;KAC7E;AACH,CAAC,CAAC;AAfW,QAAA,mCAAmC,uCAe9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard.context.d.ts","sourceRoot":"","sources":["../../src/graphql/guard.context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,
|
|
1
|
+
{"version":3,"file":"guard.context.d.ts","sourceRoot":"","sources":["../../src/graphql/guard.context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAKL,oBAAoB,EACpB,6BAA6B,EAC7B,+BAA+B,EAEhC,MAAM,WAAW,CAAC;AAEnB;;;;;;;;GAQG;AACH,eAAO,MAAM,kCAAkC,QACxC,OAAO,6DAEX,QAAQ,+BAA+B,CA0BzC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,gCAAgC,QACtC,OAAO,6DAEX,QAAQ,6BAA6B,CAwBvC,CAAC"}
|
|
@@ -14,8 +14,9 @@ const common_1 = require("../common");
|
|
|
14
14
|
const getManagementAuthenticationContext = async (req, authParams) => {
|
|
15
15
|
var _a;
|
|
16
16
|
let context = req.authContext;
|
|
17
|
+
// Subscription requests avoid regular express http middleware pipeline.
|
|
18
|
+
// `context` can be undefined when using websocket protocol for subscriptions.
|
|
17
19
|
if (context === undefined && authParams !== undefined) {
|
|
18
|
-
//Subscription requests avoid regular express http middleware pipeline
|
|
19
20
|
const token = ((_a = req.headers['authorization']) !== null && _a !== void 0 ? _a : '').replace('Bearer ', '');
|
|
20
21
|
if (typeof authParams === 'string') {
|
|
21
22
|
const authConfig = {
|
|
@@ -23,10 +24,16 @@ const getManagementAuthenticationContext = async (req, authParams) => {
|
|
|
23
24
|
tenantId: '',
|
|
24
25
|
environmentId: '',
|
|
25
26
|
};
|
|
26
|
-
|
|
27
|
+
// TODO: refactor parseJwtToken to be Generic
|
|
28
|
+
const tempContext = await (0, common_1.parseJwtToken)(token, authConfig, 'MANAGEMENT');
|
|
29
|
+
(0, common_1.assertManagementAuthenticationContext)(tempContext);
|
|
30
|
+
context = tempContext;
|
|
31
|
+
// handle http requests
|
|
27
32
|
}
|
|
28
33
|
else {
|
|
29
|
-
|
|
34
|
+
const tempContext = await (0, common_1.parseJwtToken)(token, authParams, 'MANAGEMENT');
|
|
35
|
+
(0, common_1.assertManagementAuthenticationContext)(tempContext);
|
|
36
|
+
context = tempContext;
|
|
30
37
|
}
|
|
31
38
|
}
|
|
32
39
|
return context !== null && context !== void 0 ? context : {};
|
|
@@ -44,8 +51,9 @@ exports.getManagementAuthenticationContext = getManagementAuthenticationContext;
|
|
|
44
51
|
const getConsumerAuthenticationContext = async (req, authParams) => {
|
|
45
52
|
var _a;
|
|
46
53
|
let context = req.authContext;
|
|
54
|
+
// Subscription requests avoid regular express http middleware pipeline.
|
|
55
|
+
// `context` can be undefined when using websocket protocol for subscriptions.
|
|
47
56
|
if (context === undefined && authParams !== undefined) {
|
|
48
|
-
//Subscription requests avoid regular express http middleware pipeline
|
|
49
57
|
const token = ((_a = req.headers['authorization']) !== null && _a !== void 0 ? _a : '').replace('Bearer ', '');
|
|
50
58
|
if (typeof authParams === 'string') {
|
|
51
59
|
const authConfig = {
|
|
@@ -53,10 +61,14 @@ const getConsumerAuthenticationContext = async (req, authParams) => {
|
|
|
53
61
|
tenantId: '',
|
|
54
62
|
environmentId: '',
|
|
55
63
|
};
|
|
56
|
-
|
|
64
|
+
const tempContext = await (0, common_1.parseJwtToken)(token, authConfig, 'CONSUMER');
|
|
65
|
+
(0, common_1.assertConsumerAuthenticationContext)(tempContext);
|
|
66
|
+
context = tempContext;
|
|
57
67
|
}
|
|
58
68
|
else {
|
|
59
|
-
|
|
69
|
+
const tempContext = await (0, common_1.parseJwtToken)(token, authParams, 'CONSUMER');
|
|
70
|
+
(0, common_1.assertConsumerAuthenticationContext)(tempContext);
|
|
71
|
+
context = tempContext;
|
|
60
72
|
}
|
|
61
73
|
}
|
|
62
74
|
return context !== null && context !== void 0 ? context : {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard.context.js","sourceRoot":"","sources":["../../src/graphql/guard.context.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"guard.context.js","sourceRoot":"","sources":["../../src/graphql/guard.context.ts"],"names":[],"mappings":";;;AACA,sCASmB;AAEnB;;;;;;;;GAQG;AACI,MAAM,kCAAkC,GAAG,KAAK,EACrD,GAAY,EACZ,UAA0C,EACA,EAAE;;IAC5C,IAAI,OAAO,GAAI,GAAsC,CAAC,WAAW,CAAC;IAElE,wEAAwE;IACxE,8EAA8E;IAC9E,IAAI,OAAO,KAAK,SAAS,IAAI,UAAU,KAAK,SAAS,EAAE;QACrD,MAAM,KAAK,GAAG,CAAC,MAAA,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,mCAAI,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAC1E,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YAClC,MAAM,UAAU,GAAyB;gBACvC,Y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AC;YACjD,OAAO,GAAG,WAAW,CAAC;SACvB;aAAM;YACL,MAAM,WAAW,GAAG,MAAM,IAAA,sBAAa,EAAC,KAAK,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;YACvE,IAAA,4CAAmC,EAAC,WAAW,CAAC,CAAC;YACjD,OAAO,GAAG,WAAW,CAAC;SACvB;KACF;IAED,OAAO,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;AACvB,CAAC,CAAC;AA3BW,QAAA,gCAAgC,oCA2B3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard.plugin.d.ts","sourceRoot":"","sources":["../../src/graphql/guard.plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"guard.plugin.d.ts","sourceRoot":"","sources":["../../src/graphql/guard.plugin.ts"],"names":[],"mappings":"AAaA;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,iCAmEzB,CAAC"}
|
|
@@ -35,18 +35,18 @@ exports.AxGuardPlugin = (0, graphile_utils_1.makeWrapResolversPlugin)(({ scope }
|
|
|
35
35
|
const { authErrorInfo, subject } = context; // The context could be either a Management or an Consumer context.
|
|
36
36
|
if (!options.ensureOnlyAuthentication) {
|
|
37
37
|
// If the ensureOnlyAuthentication flag is set, it is assumed that the subject is a AuthenticatedManagementSubject
|
|
38
|
-
|
|
38
|
+
// If the requested operation is an Anonymous operation, return the resolver without further validation.
|
|
39
|
+
if ((0, guard_utils_1.isAnonymousOperation)(options.authorizationOptions)) {
|
|
39
40
|
return resolver(source, args, context, resolveInfo);
|
|
40
41
|
}
|
|
41
42
|
else {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
43
|
+
// Check if the authentication is valid
|
|
44
|
+
(0, guard_utils_1.assertSubjectAuthenticated)(subject, options.authorizationOptions, authErrorInfo);
|
|
45
|
+
// Check if the subject type is a Management Subject
|
|
46
|
+
(0, common_1.assertAuthenticatedManagementSubject)(subject);
|
|
47
|
+
// Check if the user is authorized to execute the GQL operation.
|
|
48
|
+
(0, guard_utils_1.assertSubjectAuthorized)(subject, options.authorizationOptions);
|
|
49
|
+
return resolver(source, args, context, resolveInfo);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
@@ -56,12 +56,8 @@ exports.AxGuardPlugin = (0, graphile_utils_1.makeWrapResolversPlugin)(({ scope }
|
|
|
56
56
|
* the token carrier will have access to all operations for the given GQL endpoint.
|
|
57
57
|
* Entities in this endpoint must have RLS for user_id enabled.
|
|
58
58
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
return resolver(source, args, context, resolveInfo);
|
|
64
|
-
}
|
|
59
|
+
(0, guard_utils_1.assertSubjectAuthenticated)(subject, options.authorizationOptions, authErrorInfo);
|
|
60
|
+
return resolver(source, args, context, resolveInfo);
|
|
65
61
|
}
|
|
66
62
|
});
|
|
67
63
|
//# sourceMappingURL=guard.plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard.plugin.js","sourceRoot":"","sources":["../../src/graphql/guard.plugin.ts"],"names":[],"mappings":";;;AAAA,mDAAyD;AACzD,
|
|
1
|
+
{"version":3,"file":"guard.plugin.js","sourceRoot":"","sources":["../../src/graphql/guard.plugin.ts"],"names":[],"mappings":";;;AAAA,mDAAyD;AACzD,sCAImB;AACnB,uDAK+B;AAE/B;;;;;;;;GAQG;AACU,QAAA,aAAa,GAAG,IAAA,wCAAuB,EAClD,CACE,EAAE,KAAK,EAAE,EACT,KAAK,EACL,MAAM,EACN,EAAE,wBAAwB,EAAE,SAAS,EAAE,oBAAoB,EAAE,EAC7D,EAAE;IACF,MAAM,uBAAuB,GAC3B,KAAK,CAAC,SAAS,KAAK,OAAO;QAC3B,CAAC,KAAK,CAAC,WAAW;YAChB,KAAK,CAAC,cAAc;YACp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AE,IAAI,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;KACrD;AACH,CAAC,CACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription-authorization-hook-factory.d.ts","sourceRoot":"","sources":["../../src/graphql/subscription-authorization-hook-factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAU5C,OAAO,EAEL,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"subscription-authorization-hook-factory.d.ts","sourceRoot":"","sources":["../../src/graphql/subscription-authorization-hook-factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAU5C,OAAO,EAEL,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,cAAc,CAAC;AAqBtB;;;;;;;;GAQG;AACH,eAAO,MAAM,oCAAoC,iBACjC,oBAAoB,OAAO,EAAE,QAAQ,CAAC,GAAG,SAAS,KAC/D,kBAyLF,CAAC"}
|
|
@@ -16,7 +16,8 @@ const guard_utils_1 = require("../common/guard-utils");
|
|
|
16
16
|
*/
|
|
17
17
|
const subscriptionAuthorizationHookFactory = (buildOptions) => {
|
|
18
18
|
return {
|
|
19
|
-
//
|
|
19
|
+
// Handles subscription requests coming through protocol `graphql-ws`
|
|
20
|
+
// This is maintained for backwards compatibility. Managed services use `graphql-transport-ws` protocol (implemented below)
|
|
20
21
|
'postgraphile:ws:onOperation': (params) => {
|
|
21
22
|
var _a;
|
|
22
23
|
// Extract GQL query and build an AST
|
|
@@ -35,8 +36,23 @@ const subscriptionAuthorizationHookFactory = (buildOptions) => {
|
|
|
35
36
|
serviceId: params.context.config.serviceId,
|
|
36
37
|
};
|
|
37
38
|
const error = undefined;
|
|
39
|
+
const subject = params.context.subject;
|
|
40
|
+
(0, common_1.assertGenericAuthenticatedSubject)(subject);
|
|
38
41
|
// If the authorization fails, throw error
|
|
39
|
-
if ((0, guard_utils_1.
|
|
42
|
+
if ((0, guard_utils_1.isAuthenticatedManagementSubject)(subject)) {
|
|
43
|
+
if ((0, guard_utils_1.isAnonymousOperation)(options)) {
|
|
44
|
+
return params;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// Check if the authentication is valid
|
|
48
|
+
(0, guard_utils_1.assertSubjectAuthenticated)(subject, options, error);
|
|
49
|
+
// Check if the user is authorized to execute the GQL operation.
|
|
50
|
+
(0, guard_utils_1.assertSubjectAuthorized)(subject, options);
|
|
51
|
+
return params;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else if ((0, guard_utils_1.isAuthenticatedConsumer)(subject)) {
|
|
55
|
+
(0, guard_utils_1.assertTokenNotExpired)(subject, params.context.config.serviceId);
|
|
40
56
|
return params;
|
|
41
57
|
}
|
|
42
58
|
else {
|
|
@@ -52,12 +68,13 @@ const subscriptionAuthorizationHookFactory = (buildOptions) => {
|
|
|
52
68
|
}
|
|
53
69
|
throw new Error('Error in subscription setup. This is likely caused by a development time issue.');
|
|
54
70
|
},
|
|
55
|
-
//
|
|
71
|
+
// Handles subscription requests coming through protocol `graphql-transport-ws`
|
|
72
|
+
// Managed services use this protocol for subscriptions.
|
|
56
73
|
'postgraphile:ws:onSubscribe': (args, params) => {
|
|
57
74
|
var _a;
|
|
58
75
|
// If there were any Authentication Errors, close the web socket.
|
|
59
|
-
if (params.context.extra.request
|
|
60
|
-
.
|
|
76
|
+
if (params.context.extra.request.authContext
|
|
77
|
+
.authErrorInfo !== undefined) {
|
|
61
78
|
params.context.extra.socket.close(graphql_ws_1.CloseCode.Forbidden, common_1.ErrorCode.AccessTokenInvalid);
|
|
62
79
|
return args;
|
|
63
80
|
}
|
|
@@ -75,16 +92,48 @@ const subscriptionAuthorizationHookFactory = (buildOptions) => {
|
|
|
75
92
|
serviceId: args.contextValue.config.serviceId,
|
|
76
93
|
};
|
|
77
94
|
const error = undefined;
|
|
95
|
+
const subject = args.contextValue.subject;
|
|
96
|
+
(0, common_1.assertGenericAuthenticatedSubject)(subject);
|
|
78
97
|
// If the authorization fails, throw error
|
|
79
|
-
|
|
80
|
-
|
|
98
|
+
// Authorization is only checked for Management tokens
|
|
99
|
+
if ((0, guard_utils_1.isAuthenticatedManagementSubject)(subject)) {
|
|
100
|
+
if ((0, guard_utils_1.isAnonymousOperation)(options)) {
|
|
101
|
+
return args;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
try {
|
|
105
|
+
// Check if the authentication is valid
|
|
106
|
+
(0, guard_utils_1.assertSubjectAuthenticated)(subject, options, error);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
(0, common_1.assertAxGuardError)(error);
|
|
110
|
+
/**
|
|
111
|
+
* If the token has expired, we close the connection with CloseCode.Forbidden, and allow the client to automatically re-establish
|
|
112
|
+
* the connection with a new token.
|
|
113
|
+
*/
|
|
114
|
+
if (error.code === common_1.ErrorCode.AccessTokenExpired) {
|
|
115
|
+
/**
|
|
116
|
+
* `CloseCode.Forbidden` is used so that the client will automatically start retry process with a newer token.
|
|
117
|
+
* Any other CloseCode will result in a client exception and the client will not automatically retry.
|
|
118
|
+
*/
|
|
119
|
+
params.context.extra.socket.close(graphql_ws_1.CloseCode.Forbidden, common_1.ErrorCode.AccessTokenExpired);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Check if the user is authorized to execute the GQL operation.
|
|
126
|
+
(0, guard_utils_1.assertSubjectAuthorized)(subject, options);
|
|
127
|
+
return args;
|
|
128
|
+
}
|
|
81
129
|
}
|
|
82
|
-
else {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
130
|
+
else if ((0, guard_utils_1.isAuthenticatedConsumer)(subject)) {
|
|
131
|
+
try {
|
|
132
|
+
(0, guard_utils_1.assertTokenNotExpired)(subject, args.contextValue.config.serviceId);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
params.context.extra.socket.close(graphql_ws_1.CloseCode.Forbidden, common_1.ErrorCode.AccessTokenExpired);
|
|
136
|
+
}
|
|
88
137
|
return args;
|
|
89
138
|
}
|
|
90
139
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription-authorization-hook-factory.js","sourceRoot":"","sources":["../../src/graphql/subscription-authorization-hook-factory.ts"],"names":[],"mappings":";;;AAQA,6CAA8B;AAC9B,2CAAkE;AAQlE,
|
|
1
|
+
{"version":3,"file":"subscription-authorization-hook-factory.js","sourceRoot":"","sources":["../../src/graphql/subscription-authorization-hook-factory.ts"],"names":[],"mappings":";;;AAQA,6CAA8B;AAC9B,2CAAkE;AAQlE,sCAOmB;AAEnB,uDAQ+B;AAE/B;;;;;;;;GAQG;AACI,MAAM,oCAAoC,GAAG,CAClD,YAAgE,EAC5C,EAAE;IACtB,OAAO;QACL,qEAAqE;QACrE,2HAA2H;QAC3H,6BAA6B,EAAE,CAAC,MAAuB,EAAE,EAAE;;YACzD,qCAAqC;YACrC,0DAA0D;YAC1D,MAAM,QAAQ,GAAG,IAAA,qBAAG,EAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC9C,MAAM,oBAAoB,GACxB,QAAQ,CAAC,WAAwC,CAAC;YAEpD,MAAM,YAAY,GAAG,eAAe,CAClC,oBAAoB,EACpB,MAAM,CAAC,aAAa,CACrB,CAAC;YAEF,IACE,YAAY,KAAK,SAAS;gBAC1B,YAAY,CAAC,oBAAoB,KAAK,SAAS;gBAC/C,YAAY,KAAK,SAAS,EAC1B;gBACA,qDAAqD;gBACrD,MAAM,oBAAoB,GAAG,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,oBAAoB,CAC5D,oBAA4C,CAAC;gBAEhD,MAAM,OAAO,GAA4B;oBACvC,SAAS,EAAE,YAAY,CAAC,IA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,CAAC,IAAI,0CAAE,KAAK,MAAK,aAAa,CAAA,EAAA,CACjD,CAAC,CAAC,CAAC,CAAC;IAEL,IAAI,sBAAsB,KAAK,SAAS,EAAE;QACxC,iDAAiD;QACjD,yEAAyE;QACzE,mGAAmG;QACnG,MAAM,YAAY,GAChB,sBAAsB,CAAC,YAAY,CAAC,UACrC,CAAC,CAAC,CAAC,CAAC;QACL,OAAO,YAAY,CAAC;KACrB;AACH,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-id-guard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0-rc.3",
|
|
4
4
|
"description": "Authentication and authorization helpers for Axinom Mosaic services",
|
|
5
5
|
"author": "Axinom",
|
|
6
6
|
"license": "PROPRIETARY",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"test:ci": "jest --reporters=default --reporters=jest-junit --coverage --coverageReporters=cobertura --coverageReporters=html"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@axinom/mosaic-id-link-be": "^0.5.
|
|
30
|
-
"@axinom/mosaic-id-utils": "^0.6.
|
|
31
|
-
"@axinom/mosaic-message-bus": "^0.7.
|
|
32
|
-
"@axinom/mosaic-service-common": "^0.13.
|
|
29
|
+
"@axinom/mosaic-id-link-be": "^0.5.2-rc.3",
|
|
30
|
+
"@axinom/mosaic-id-utils": "^0.6.2-rc.3",
|
|
31
|
+
"@axinom/mosaic-message-bus": "^0.7.1-rc.3",
|
|
32
|
+
"@axinom/mosaic-service-common": "^0.13.1-rc.3",
|
|
33
33
|
"amqplib": "^0.6.0",
|
|
34
34
|
"express": "^4.17.1",
|
|
35
35
|
"express-bearer-token": "^2.4.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "e08ea414273c428a14d90e0809906c2bce2660ae"
|
|
64
64
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AuthenticatedConsumer, AuthenticatedConsumerApplication } from './authenticated-subject.interface';
|
|
2
|
-
/**
|
|
3
|
-
* Asserts if the passed subject object is of type AuthenticatedConsumer.
|
|
4
|
-
*
|
|
5
|
-
* @param subject subject object of type unknown
|
|
6
|
-
*/
|
|
7
|
-
export declare const assertAuthenticatedConsumer: (subject: unknown) => asserts subject is AuthenticatedConsumer;
|
|
8
|
-
/**
|
|
9
|
-
* Asserts if the passed subject object is of type AuthenticatedConsumerApplication.
|
|
10
|
-
*
|
|
11
|
-
* @param subject subject object of type unknown
|
|
12
|
-
*/
|
|
13
|
-
export declare const assertConsumerApplication: (subject: unknown) => asserts subject is AuthenticatedConsumerApplication;
|
|
14
|
-
//# sourceMappingURL=assert-consumer-token-type.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assert-consumer-token-type.d.ts","sourceRoot":"","sources":["../../src/common/assert-consumer-token-type.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,qBAAqB,EACrB,gCAAgC,EACjC,MAAM,mCAAmC,CAAC;AAE3C;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,EAAE,CACxC,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,OAAO,IAAI,qBASvB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,EAAE,CACtC,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,OAAO,IAAI,gCASvB,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertConsumerApplication = exports.assertAuthenticatedConsumer = void 0;
|
|
4
|
-
const mosaic_service_common_1 = require("@axinom/mosaic-service-common");
|
|
5
|
-
const _1 = require(".");
|
|
6
|
-
/**
|
|
7
|
-
* Asserts if the passed subject object is of type AuthenticatedConsumer.
|
|
8
|
-
*
|
|
9
|
-
* @param subject subject object of type unknown
|
|
10
|
-
*/
|
|
11
|
-
const assertAuthenticatedConsumer = (subject) => {
|
|
12
|
-
if (subject.subjectType !==
|
|
13
|
-
_1.SubjectType.ConsumerAccount) {
|
|
14
|
-
throw new mosaic_service_common_1.GeneralError(`The token is not an Authenticated Consumer`);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
exports.assertAuthenticatedConsumer = assertAuthenticatedConsumer;
|
|
18
|
-
/**
|
|
19
|
-
* Asserts if the passed subject object is of type AuthenticatedConsumerApplication.
|
|
20
|
-
*
|
|
21
|
-
* @param subject subject object of type unknown
|
|
22
|
-
*/
|
|
23
|
-
const assertConsumerApplication = (subject) => {
|
|
24
|
-
if (subject.subjectType !==
|
|
25
|
-
_1.SubjectType.ConsumerApplication) {
|
|
26
|
-
throw new mosaic_service_common_1.GeneralError(`The token is not an Consumer Application`);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
exports.assertConsumerApplication = assertConsumerApplication;
|
|
30
|
-
//# sourceMappingURL=assert-consumer-token-type.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assert-consumer-token-type.js","sourceRoot":"","sources":["../../src/common/assert-consumer-token-type.ts"],"names":[],"mappings":";;;AAAA,yEAA6D;AAC7D,wBAAgC;AAMhC;;;;GAIG;AACI,MAAM,2BAA2B,GAEQ,CAC9C,OAAgB,EAC0B,EAAE;IAC5C,IACG,OAAiC,CAAC,WAAW;QAC9C,cAAW,CAAC,eAAe,EAC3B;QACA,MAAM,IAAI,oCAAY,CAAC,4CAA4C,CAAC,CAAC;KACtE;AACH,CAAC,CAAC;AAXW,QAAA,2BAA2B,+BAWtC;AAEF;;;;GAIG;AACI,MAAM,yBAAyB,GAEqB,CACzD,OAAgB,EACqC,EAAE;IACvD,IACG,OAA4C,CAAC,WAAW;QACzD,cAAW,CAAC,mBAAmB,EAC/B;QACA,MAAM,IAAI,oCAAY,CAAC,0CAA0C,CAAC,CAAC;KACpE;AACH,CAAC,CAAC;AAXW,QAAA,yBAAyB,6BAWpC"}
|