@vcita/oauth-client-nestjs 1.8.10 → 1.10.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.
- package/README.md +6 -6
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/oauth/config/configuration.js +4 -4
- package/dist/oauth/config/configuration.js.map +1 -1
- package/dist/oauth/controllers/oauth.controller.js +3 -3
- package/dist/oauth/controllers/oauth.controller.js.map +1 -1
- package/dist/oauth/enums/{oauth.enum.d.ts → auth.enum.d.ts} +7 -1
- package/dist/oauth/enums/{oauth.enum.js → auth.enum.js} +9 -2
- package/dist/oauth/enums/auth.enum.js.map +1 -0
- package/dist/oauth/exceptions/authentication.exception.d.ts +7 -0
- package/dist/oauth/exceptions/authentication.exception.js +17 -0
- package/dist/oauth/exceptions/authentication.exception.js.map +1 -0
- package/dist/oauth/interfaces/oauth.interface.d.ts +8 -1
- package/dist/oauth/middleware/{oauth.middleware.d.ts → auth.middleware.d.ts} +4 -3
- package/dist/oauth/middleware/{oauth.middleware.js → auth.middleware.js} +64 -34
- package/dist/oauth/middleware/auth.middleware.js.map +1 -0
- package/dist/oauth/middleware/{authorization.middleware.d.ts → oauth-authorization.middleware.d.ts} +1 -1
- package/dist/oauth/middleware/{authorization.middleware.js → oauth-authorization.middleware.js} +10 -10
- package/dist/oauth/middleware/oauth-authorization.middleware.js.map +1 -0
- package/dist/oauth/oauth.module.js +30 -6
- package/dist/oauth/oauth.module.js.map +1 -1
- package/dist/oauth/repositories/authorization-payload.entity.d.ts +5 -0
- package/dist/oauth/repositories/authorization-payload.entity.js +7 -0
- package/dist/oauth/repositories/authorization-payload.entity.js.map +1 -0
- package/dist/oauth/services/Infra-proxy.service.d.ts +42 -0
- package/dist/oauth/services/Infra-proxy.service.js +81 -0
- package/dist/oauth/services/Infra-proxy.service.js.map +1 -0
- package/dist/oauth/services/external-proxy.service.d.ts +7 -0
- package/dist/oauth/services/external-proxy.service.js +28 -0
- package/dist/oauth/services/external-proxy.service.js.map +1 -0
- package/dist/oauth/services/inernal-proxy.service.d.ts +7 -0
- package/dist/oauth/services/inernal-proxy.service.js +45 -0
- package/dist/oauth/services/inernal-proxy.service.js.map +1 -0
- package/dist/oauth/services/internal-proxy.service.d.ts +16 -0
- package/dist/oauth/services/internal-proxy.service.js +77 -0
- package/dist/oauth/services/internal-proxy.service.js.map +1 -0
- package/dist/oauth/services/oauth-http.service.js +2 -2
- package/dist/oauth/services/oauth-http.service.js.map +1 -1
- package/dist/oauth/services/oauth.service.js +4 -4
- package/dist/oauth/services/oauth.service.js.map +1 -1
- package/dist/oauth/utils/authentication.utils.d.ts +24 -0
- package/dist/oauth/utils/authentication.utils.js +78 -0
- package/dist/oauth/utils/authentication.utils.js.map +1 -0
- package/dist/oauth/utils/oauth.utils.d.ts +2 -1
- package/dist/oauth/utils/oauth.utils.js +4 -3
- package/dist/oauth/utils/oauth.utils.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -2
- package/dist/oauth/enums/oauth.enum.js.map +0 -1
- package/dist/oauth/interfaces/jwt.interface.d.ts +0 -7
- package/dist/oauth/interfaces/jwt.interface.js +0 -3
- package/dist/oauth/interfaces/jwt.interface.js.map +0 -1
- package/dist/oauth/middleware/authorization.middleware.js.map +0 -1
- package/dist/oauth/middleware/oauth.middleware.js.map +0 -1
package/README.md
CHANGED
|
@@ -11,19 +11,19 @@ You should add these env variables (you can add then on .env file):
|
|
|
11
11
|
- OAUTH_SERVER: client authorization url
|
|
12
12
|
- API_GW_SERVER: vcita api server
|
|
13
13
|
- OAUTH_REDIRECT_URI
|
|
14
|
+
- CUSTOM_ENTITIES=["/home/vcita/app/node_modules/@vcita/oauth-client-nestjs/dist/oauth/**/*.entity.{ts,js}"]
|
|
14
15
|
|
|
15
16
|
## Usage
|
|
16
17
|
This is a dynamic module. To use it you should call register method:
|
|
17
18
|
```js
|
|
18
19
|
OauthModule.register({ mainRoute: '' })
|
|
19
20
|
```
|
|
20
|
-
mainRoute - the default route to redirect to after
|
|
21
|
+
mainRoute - the default route to redirect to after OAuth completed.
|
|
22
|
+
|
|
23
|
+
## Migration
|
|
24
|
+
After the package installation, you must generate and run a new migration for oauth module - [migration docs](https://typeorm.io/#/migrations/generating-migrations)
|
|
25
|
+
|
|
21
26
|
|
|
22
27
|
### register configuration (all of then are optional)
|
|
23
28
|
- oauthConfig: a config object that includes oauth config for another provider, and target endpoint for vcita oauth - if different from 'vcita'
|
|
24
29
|
- logger: a logger for the app.
|
|
25
|
-
|
|
26
|
-
When using app db, the oauth package uses typeorm, so you should add some staff tou your config files:
|
|
27
|
-
- add this: "node_modules/@vcita/oauth-client-nestjs/**/*.entity*{.ts,.js}" to you entity array of typeorm config.
|
|
28
|
-
- (or:) add OauthData to entities array (db config file)
|
|
29
|
-
Then you need to generate migration, and run it.
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export * from './oauth/oauth.module';
|
|
|
2
2
|
export * from './oauth/controllers/oauth.controller';
|
|
3
3
|
export * from './oauth/services/oauth-http.service';
|
|
4
4
|
export * from './oauth/services/oauth.service';
|
|
5
|
+
export * from './oauth/services/external-proxy.service';
|
|
6
|
+
export * from './oauth/services/internal-proxy.service';
|
|
7
|
+
export * from './oauth/services/infra-proxy.service';
|
|
5
8
|
export * from './oauth/interfaces/oauth.interface';
|
|
6
|
-
export * from './oauth/interfaces/jwt.interface';
|
|
7
9
|
export * from './oauth/repositories/oauth-data.entity';
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,9 @@ __exportStar(require("./oauth/oauth.module"), exports);
|
|
|
14
14
|
__exportStar(require("./oauth/controllers/oauth.controller"), exports);
|
|
15
15
|
__exportStar(require("./oauth/services/oauth-http.service"), exports);
|
|
16
16
|
__exportStar(require("./oauth/services/oauth.service"), exports);
|
|
17
|
+
__exportStar(require("./oauth/services/external-proxy.service"), exports);
|
|
18
|
+
__exportStar(require("./oauth/services/internal-proxy.service"), exports);
|
|
19
|
+
__exportStar(require("./oauth/services/infra-proxy.service"), exports);
|
|
17
20
|
__exportStar(require("./oauth/interfaces/oauth.interface"), exports);
|
|
18
|
-
__exportStar(require("./oauth/interfaces/jwt.interface"), exports);
|
|
19
21
|
__exportStar(require("./oauth/repositories/oauth-data.entity"), exports);
|
|
20
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAqC;AACrC,uEAAqD;AACrD,sEAAoD;AACpD,iEAA+C;AAC/C,qEAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAqC;AACrC,uEAAqD;AACrD,sEAAoD;AACpD,iEAA+C;AAC/C,0EAAwD;AACxD,0EAAwD;AACxD,uEAAqD;AACrD,qEAAmD;AACnD,yEAAuD"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.oauthConfig = void 0;
|
|
4
|
-
const
|
|
4
|
+
const auth_enum_1 = require("../enums/auth.enum");
|
|
5
5
|
const oauthConfig = () => ({
|
|
6
|
-
grantType:
|
|
7
|
-
scope:
|
|
8
|
-
headersType:
|
|
6
|
+
grantType: auth_enum_1.GrantTypes.authorizationCode,
|
|
7
|
+
scope: auth_enum_1.Scopes.openid,
|
|
8
|
+
headersType: auth_enum_1.TokenTypes.Bearer,
|
|
9
9
|
});
|
|
10
10
|
exports.oauthConfig = oauthConfig;
|
|
11
11
|
//# sourceMappingURL=configuration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../../src/oauth/config/configuration.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../../src/oauth/config/configuration.ts"],"names":[],"mappings":";;;AAAA,kDAAoE;AAG7D,MAAM,WAAW,GAAkC,GAAG,EAAE,CAAC,CAAC;IAC/D,SAAS,EAAE,sBAAU,CAAC,iBAAiB;IACvC,KAAK,EAAE,kBAAM,CAAC,MAAM;IACpB,WAAW,EAAE,sBAAU,CAAC,MAAM;CAC/B,CAAC,CAAC;AAJU,QAAA,WAAW,eAIrB"}
|
|
@@ -19,7 +19,7 @@ const config_1 = require("@nestjs/config");
|
|
|
19
19
|
const swagger_1 = require("@nestjs/swagger");
|
|
20
20
|
const infra_logger_service_1 = require("@vcita/infra-nestjs/dist/infra/services/infra-logger.service");
|
|
21
21
|
const oauth_service_1 = require("../services/oauth.service");
|
|
22
|
-
const
|
|
22
|
+
const auth_enum_1 = require("../enums/auth.enum");
|
|
23
23
|
let OauthController = OauthController_1 = class OauthController {
|
|
24
24
|
constructor(configService, connectService) {
|
|
25
25
|
this.configService = configService;
|
|
@@ -28,7 +28,7 @@ let OauthController = OauthController_1 = class OauthController {
|
|
|
28
28
|
}
|
|
29
29
|
async generateOauthToken(code, state, request, response) {
|
|
30
30
|
const isSecure = this.configService.get('ENVIRONMENT') !== 'development';
|
|
31
|
-
const [provider, redirect_url] = state.split(
|
|
31
|
+
const [provider, redirect_url] = state.split(auth_enum_1.stateSeparator);
|
|
32
32
|
const claimsResult = await this.connectService.generateOauthToken(code, provider);
|
|
33
33
|
const oauthConfig = this.configService.get('oauthConfig')[provider];
|
|
34
34
|
const { claimsConfig } = oauthConfig;
|
|
@@ -58,7 +58,7 @@ let OauthController = OauthController_1 = class OauthController {
|
|
|
58
58
|
sameSite: 'none',
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
-
response.cookie(`${provider}${
|
|
61
|
+
response.cookie(`${provider}${auth_enum_1.cookieName}`, cookieData, cookieSettings);
|
|
62
62
|
this.logger.debug(`after oauth. about to redirect to: ${redirectUrl.href}`);
|
|
63
63
|
return response.redirect(redirectUrl.href);
|
|
64
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.controller.js","sourceRoot":"","sources":["../../../src/oauth/controllers/oauth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"oauth.controller.js","sourceRoot":"","sources":["../../../src/oauth/controllers/oauth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAkE;AAClE,2CAA+C;AAC/C,6CAA0C;AAC1C,uGAAkG;AAElG,6DAAyD;AAKzD,kDAAgE;AAIhE,IAAa,eAAe,uBAA5B,MAAa,eAAe;IAE1B,YACU,aAA+C,EACtC,cAA4B;QADrC,kBAAa,GAAb,aAAa,CAAkC;QACtC,mBAAc,GAAd,cAAc,CAAc;QAH9B,WAAM,GAAG,IAAI,yCAAkB,CAAC,iBAAe,CAAC,IAAI,CAAC,CAAC;IAIpE,CAAC;IAGJ,KAAK,CAAC,kBAAkB,CACP,IAAI,EACH,KAAK,EACd,OAAgB,EAChB,QAAkB;QAEzB,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,aAAa,CAAC,KAAK,aAAa,CAAC;QACzE,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,0BAAc,CAAC,CAAC;QAC7D,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAC/D,IAAI,EACJ,QAAQ,CACT,CAAC;QACF,MAAM,WAAW,GACf,IAAI,CAAC,aAAa,CAAC,GAAG,CAAoB,aAAa,CAAC,CAAC,QAAQ,CAAC,CAAC;QACrE,MAAM,EAAE,YAAY,EAAE,GAAG,WAAW,CAAC;QACrC,MAAM,WAAW,GAAG,OAAO,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,OAAO,CAAC,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,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;CACF,CAAA;AAnDC;IADC,YAAG,CAAC,EAAE,CAAC;IAEL,WAAA,cAAK,CAAC,MAAM,CAAC,CAAA;IACb,WAAA,cAAK,CAAC,OAAO,CAAC,CAAA;IACd,WAAA,YAAG,EAAE,CAAA;IACL,WAAA,YAAG,EAAE,CAAA;;;;yDA8CP;AA1DU,eAAe;IAF3B,iBAAO,CAAC,OAAO,CAAC;IAChB,mBAAU,CAAC,OAAO,CAAC;qCAIO,sBAAa;QACH,4BAAY;GAJpC,eAAe,CA2D3B;AA3DY,0CAAe"}
|
|
@@ -2,7 +2,8 @@ export declare enum TokenTypes {
|
|
|
2
2
|
Bearer = "Bearer"
|
|
3
3
|
}
|
|
4
4
|
export declare enum EndPoints {
|
|
5
|
-
generateToken = "oauth/token"
|
|
5
|
+
generateToken = "oauth/token",
|
|
6
|
+
generateStoSToken = "platform/authentication/service/token"
|
|
6
7
|
}
|
|
7
8
|
export declare enum Scopes {
|
|
8
9
|
openid = "openid"
|
|
@@ -13,6 +14,11 @@ export declare enum GrantTypes {
|
|
|
13
14
|
export declare enum ResponseTypes {
|
|
14
15
|
code = "code"
|
|
15
16
|
}
|
|
17
|
+
export declare enum InfraAuthentication {
|
|
18
|
+
InboundHeaderName = "X-AUTHORIZATION",
|
|
19
|
+
OutboundHeaderName = "Authorization",
|
|
20
|
+
Algorithm = "RS512"
|
|
21
|
+
}
|
|
16
22
|
export declare const stateSeparator = ";;;";
|
|
17
23
|
export declare const cookieName = "sessionCookie";
|
|
18
24
|
export declare const mainProvider = "vcita";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mainProvider = exports.cookieName = exports.stateSeparator = exports.ResponseTypes = exports.GrantTypes = exports.Scopes = exports.EndPoints = exports.TokenTypes = void 0;
|
|
3
|
+
exports.mainProvider = exports.cookieName = exports.stateSeparator = exports.InfraAuthentication = exports.ResponseTypes = exports.GrantTypes = exports.Scopes = exports.EndPoints = exports.TokenTypes = void 0;
|
|
4
4
|
var TokenTypes;
|
|
5
5
|
(function (TokenTypes) {
|
|
6
6
|
TokenTypes["Bearer"] = "Bearer";
|
|
@@ -8,6 +8,7 @@ var TokenTypes;
|
|
|
8
8
|
var EndPoints;
|
|
9
9
|
(function (EndPoints) {
|
|
10
10
|
EndPoints["generateToken"] = "oauth/token";
|
|
11
|
+
EndPoints["generateStoSToken"] = "platform/authentication/service/token";
|
|
11
12
|
})(EndPoints = exports.EndPoints || (exports.EndPoints = {}));
|
|
12
13
|
var Scopes;
|
|
13
14
|
(function (Scopes) {
|
|
@@ -21,7 +22,13 @@ var ResponseTypes;
|
|
|
21
22
|
(function (ResponseTypes) {
|
|
22
23
|
ResponseTypes["code"] = "code";
|
|
23
24
|
})(ResponseTypes = exports.ResponseTypes || (exports.ResponseTypes = {}));
|
|
25
|
+
var InfraAuthentication;
|
|
26
|
+
(function (InfraAuthentication) {
|
|
27
|
+
InfraAuthentication["InboundHeaderName"] = "X-AUTHORIZATION";
|
|
28
|
+
InfraAuthentication["OutboundHeaderName"] = "Authorization";
|
|
29
|
+
InfraAuthentication["Algorithm"] = "RS512";
|
|
30
|
+
})(InfraAuthentication = exports.InfraAuthentication || (exports.InfraAuthentication = {}));
|
|
24
31
|
exports.stateSeparator = ';;;';
|
|
25
32
|
exports.cookieName = 'sessionCookie';
|
|
26
33
|
exports.mainProvider = 'vcita';
|
|
27
|
-
//# sourceMappingURL=
|
|
34
|
+
//# sourceMappingURL=auth.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.enum.js","sourceRoot":"","sources":["../../../src/oauth/enums/auth.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAEX;AAFD,WAAY,UAAU;IACpB,+BAAiB,CAAA;AACnB,CAAC,EAFW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAErB;AAED,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,0CAA6B,CAAA;IAC7B,wEAA2D,CAAA;AAC7D,CAAC,EAHW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAGpB;AACD,IAAY,MAEX;AAFD,WAAY,MAAM;IAChB,2BAAiB,CAAA;AACnB,CAAC,EAFW,MAAM,GAAN,cAAM,KAAN,cAAM,QAEjB;AAED,IAAY,UAEX;AAFD,WAAY,UAAU;IACpB,sDAAwC,CAAA;AAC1C,CAAC,EAFW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAErB;AAED,IAAY,aAEX;AAFD,WAAY,aAAa;IACvB,8BAAa,CAAA;AACf,CAAC,EAFW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAExB;AAED,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC7B,4DAAqC,CAAA;IACrC,2DAAoC,CAAA;IACpC,0CAAmB,CAAA;AACrB,CAAC,EAJW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAI9B;AAEY,QAAA,cAAc,GAAG,KAAK,CAAC;AAEvB,QAAA,UAAU,GAAG,eAAe,CAAC;AAE7B,QAAA,YAAY,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvalidPayloadParamsException = exports.MissingTokenException = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
class MissingTokenException extends common_1.UnauthorizedException {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('Bearer Token is missing');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.MissingTokenException = MissingTokenException;
|
|
11
|
+
class InvalidPayloadParamsException extends common_1.UnauthorizedException {
|
|
12
|
+
constructor() {
|
|
13
|
+
super('Invalid token payload params');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.InvalidPayloadParamsException = InvalidPayloadParamsException;
|
|
17
|
+
//# sourceMappingURL=authentication.exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication.exception.js","sourceRoot":"","sources":["../../../src/oauth/exceptions/authentication.exception.ts"],"names":[],"mappings":";;;AAAA,2CAAuD;AAEvD,MAAa,qBAAsB,SAAQ,8BAAqB;IAC9D;QACE,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACnC,CAAC;CACF;AAJD,sDAIC;AAED,MAAa,6BAA8B,SAAQ,8BAAqB;IACtE;QACE,KAAK,CAAC,8BAA8B,CAAC,CAAC;IACxC,CAAC;CACF;AAJD,sEAIC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GrantTypes, ResponseTypes, TokenTypes, Scopes } from '../enums/
|
|
1
|
+
import { GrantTypes, ResponseTypes, TokenTypes, Scopes } from '../enums/auth.enum';
|
|
2
2
|
export declare type ClaimConfig = Array<{
|
|
3
3
|
dataName?: string;
|
|
4
4
|
claimName: string;
|
|
@@ -42,4 +42,11 @@ export interface GrantGenerationParams extends Record<string, string> {
|
|
|
42
42
|
scope: Scopes | string;
|
|
43
43
|
state?: string;
|
|
44
44
|
}
|
|
45
|
+
export interface JwtClaimsInterface extends Record<string, string | number> {
|
|
46
|
+
sub: string;
|
|
47
|
+
iss: string;
|
|
48
|
+
aud: string;
|
|
49
|
+
exp: number;
|
|
50
|
+
iat: number;
|
|
51
|
+
}
|
|
45
52
|
export declare type ProviderOauthConfig = Record<string, OauthInterface>;
|
|
@@ -3,13 +3,14 @@ import { ConfigService } from '@nestjs/config';
|
|
|
3
3
|
import { Request, Response } from 'express';
|
|
4
4
|
import { ApplicationConfig, OauthInterface } from '../interfaces/oauth.interface';
|
|
5
5
|
import { OauthService } from '../services/oauth.service';
|
|
6
|
-
export declare class
|
|
6
|
+
export declare class AuthMiddleware implements NestMiddleware {
|
|
7
7
|
private connectService;
|
|
8
8
|
private configService;
|
|
9
9
|
private logger;
|
|
10
10
|
constructor(connectService: OauthService, configService: ConfigService<ApplicationConfig>);
|
|
11
|
+
use(req: Request, res: Response, next: () => void): Promise<void>;
|
|
12
|
+
authenticateInternalToken(req: Request): Promise<any>;
|
|
11
13
|
isProviderAuthenticated(provider: any, config: OauthInterface, req: Request): Promise<boolean>;
|
|
12
14
|
redirectToProvider(provider: string, config: OauthInterface, req: Request, res: Response): void;
|
|
13
|
-
private
|
|
14
|
-
use(req: Request, res: Response, next: () => void): Promise<void>;
|
|
15
|
+
private defaultExclusion;
|
|
15
16
|
}
|
|
@@ -8,23 +8,76 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var
|
|
11
|
+
var AuthMiddleware_1;
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.
|
|
13
|
+
exports.AuthMiddleware = void 0;
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
15
|
const config_1 = require("@nestjs/config");
|
|
16
16
|
const infra_logger_service_1 = require("@vcita/infra-nestjs/dist/infra/services/infra-logger.service");
|
|
17
|
-
const
|
|
17
|
+
const configuration_1 = require("@vcita/infra-nestjs/dist/infra/config/configuration");
|
|
18
|
+
const auth_enum_1 = require("../enums/auth.enum");
|
|
18
19
|
const oauth_service_1 = require("../services/oauth.service");
|
|
19
|
-
|
|
20
|
+
const authentication_utils_1 = require("../utils/authentication.utils");
|
|
21
|
+
const authentication_exception_1 = require("../exceptions/authentication.exception");
|
|
22
|
+
let AuthMiddleware = AuthMiddleware_1 = class AuthMiddleware {
|
|
20
23
|
constructor(connectService, configService) {
|
|
21
24
|
this.connectService = connectService;
|
|
22
25
|
this.configService = configService;
|
|
23
|
-
this.logger = new infra_logger_service_1.InfraLoggerService(
|
|
26
|
+
this.logger = new infra_logger_service_1.InfraLoggerService(AuthMiddleware_1.name);
|
|
27
|
+
}
|
|
28
|
+
async use(req, res, next) {
|
|
29
|
+
const url = req.baseUrl || req.originalUrl;
|
|
30
|
+
this.logger.debug(`About to check authentication method ${url}`);
|
|
31
|
+
if (this.defaultExclusion(url)) {
|
|
32
|
+
this.logger.debug('Excluded path, continue');
|
|
33
|
+
return next();
|
|
34
|
+
}
|
|
35
|
+
if (configuration_1.default().authInternalRsaPublic != null) {
|
|
36
|
+
this.logger.debug('About to check if it is internal request');
|
|
37
|
+
const decodedToken = await this.authenticateInternalToken(req);
|
|
38
|
+
if (decodedToken) {
|
|
39
|
+
req['authorizationPayload'] = authentication_utils_1.AuthenticationUtils.parseActorFromPayload(decodedToken);
|
|
40
|
+
return next();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
this.logger.debug('About to check if it is oauth request');
|
|
44
|
+
let notAuthenticatedApp;
|
|
45
|
+
for (const providerConfig of Object.entries(this.configService.get('oauthConfig'))) {
|
|
46
|
+
const isConnected = await this.isProviderAuthenticated(...providerConfig, req);
|
|
47
|
+
if (!isConnected) {
|
|
48
|
+
notAuthenticatedApp = providerConfig;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (notAuthenticatedApp) {
|
|
53
|
+
this.redirectToProvider(...notAuthenticatedApp, req, res);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
this.logger.log('user is authenticated, continue');
|
|
57
|
+
return next();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async authenticateInternalToken(req) {
|
|
61
|
+
const token = authentication_utils_1.AuthenticationUtils.extractTokenFromRequest(req);
|
|
62
|
+
if (!token)
|
|
63
|
+
return Promise.resolve(false);
|
|
64
|
+
const PromiseResult = new Promise((resolve, reject) => {
|
|
65
|
+
authentication_utils_1.AuthenticationUtils.verify(token, (err, decoded) => {
|
|
66
|
+
if (err)
|
|
67
|
+
reject(new common_1.UnauthorizedException(err.message));
|
|
68
|
+
if (!authentication_utils_1.AuthenticationUtils.verifyTokenPayload(decoded)) {
|
|
69
|
+
reject(new authentication_exception_1.InvalidPayloadParamsException());
|
|
70
|
+
}
|
|
71
|
+
if (!decoded)
|
|
72
|
+
reject(new common_1.UnauthorizedException());
|
|
73
|
+
resolve(decoded);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
return PromiseResult;
|
|
24
77
|
}
|
|
25
78
|
async isProviderAuthenticated(provider, config, req) {
|
|
26
79
|
const { query } = req;
|
|
27
|
-
const cookieFullName = `${provider}${
|
|
80
|
+
const cookieFullName = `${provider}${auth_enum_1.cookieName}`;
|
|
28
81
|
const cookieValue = (req.signedCookies || {})[cookieFullName] || {};
|
|
29
82
|
return await this.connectService.isConnected(cookieValue, query, provider, config);
|
|
30
83
|
}
|
|
@@ -39,7 +92,7 @@ let OauthMiddleware = OauthMiddleware_1 = class OauthMiddleware {
|
|
|
39
92
|
this.logger.log(`about to redirect to: ${authorizationUrl.href}`);
|
|
40
93
|
res.redirect(authorizationUrl.href);
|
|
41
94
|
}
|
|
42
|
-
|
|
95
|
+
defaultExclusion(url = '') {
|
|
43
96
|
var _a;
|
|
44
97
|
const assetsRegex = /assets\/(.*)\.(..*)$/;
|
|
45
98
|
let excludes = (_a = this.configService.get('excludesOauth')) !== null && _a !== void 0 ? _a : [];
|
|
@@ -48,34 +101,11 @@ let OauthMiddleware = OauthMiddleware_1 = class OauthMiddleware {
|
|
|
48
101
|
assetsRegex.test(url) ||
|
|
49
102
|
url.includes('favicon.ico'));
|
|
50
103
|
}
|
|
51
|
-
async use(req, res, next) {
|
|
52
|
-
const url = req.baseUrl || req.originalUrl;
|
|
53
|
-
this.logger.debug(`in oauth middleware, about to check authentication ${url}`);
|
|
54
|
-
if (this.isMistake(url)) {
|
|
55
|
-
this.logger.debug('in oauth middleware by mistake. continue');
|
|
56
|
-
return next();
|
|
57
|
-
}
|
|
58
|
-
let notAuthenticatedApp;
|
|
59
|
-
for (const providerConfig of Object.entries(this.configService.get('oauthConfig'))) {
|
|
60
|
-
const isConnected = await this.isProviderAuthenticated(...providerConfig, req);
|
|
61
|
-
if (!isConnected) {
|
|
62
|
-
notAuthenticatedApp = providerConfig;
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (notAuthenticatedApp) {
|
|
67
|
-
this.redirectToProvider(...notAuthenticatedApp, req, res);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
this.logger.log('user is authenticated, continue');
|
|
71
|
-
next();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
104
|
};
|
|
75
|
-
|
|
105
|
+
AuthMiddleware = AuthMiddleware_1 = __decorate([
|
|
76
106
|
common_1.Injectable(),
|
|
77
107
|
__metadata("design:paramtypes", [oauth_service_1.OauthService,
|
|
78
108
|
config_1.ConfigService])
|
|
79
|
-
],
|
|
80
|
-
exports.
|
|
81
|
-
//# sourceMappingURL=
|
|
109
|
+
], AuthMiddleware);
|
|
110
|
+
exports.AuthMiddleware = AuthMiddleware;
|
|
111
|
+
//# sourceMappingURL=auth.middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.middleware.js","sourceRoot":"","sources":["../../../src/oauth/middleware/auth.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAIwB;AACxB,2CAA+C;AAE/C,uGAAkG;AAClG,uFAAgF;AAEhF,kDAAgD;AAMhD,6DAAyD;AACzD,wEAAoE;AACpE,qFAAuF;AAGvF,IAAa,cAAc,sBAA3B,MAAa,cAAc;IAEzB,YACU,cAA4B,EAC5B,aAA+C;QAD/C,mBAAc,GAAd,cAAc,CAAc;QAC5B,kBAAa,GAAb,aAAa,CAAkC;QAHjD,WAAM,GAAG,IAAI,yCAAkB,CAAC,gBAAc,CAAC,IAAI,CAAC,CAAC;IAI1D,CAAC;IAEJ,KAAK,CAAC,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAgB;QACrD,MAAM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|
3
3
|
import { Request, Response } from 'express';
|
|
4
4
|
import { ApplicationConfig } from '../interfaces/oauth.interface';
|
|
5
5
|
import { OauthService } from '../services/oauth.service';
|
|
6
|
-
export declare class
|
|
6
|
+
export declare class OauthAuthorizationMiddleware implements NestMiddleware {
|
|
7
7
|
private connectService;
|
|
8
8
|
private configService;
|
|
9
9
|
private logger;
|
package/dist/oauth/middleware/{authorization.middleware.js → oauth-authorization.middleware.js}
RENAMED
|
@@ -8,25 +8,25 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var
|
|
11
|
+
var OauthAuthorizationMiddleware_1;
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.
|
|
13
|
+
exports.OauthAuthorizationMiddleware = void 0;
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
15
|
const config_1 = require("@nestjs/config");
|
|
16
16
|
const infra_logger_service_1 = require("@vcita/infra-nestjs/dist/infra/services/infra-logger.service");
|
|
17
|
-
const
|
|
17
|
+
const auth_enum_1 = require("../enums/auth.enum");
|
|
18
18
|
const oauth_service_1 = require("../services/oauth.service");
|
|
19
|
-
let
|
|
19
|
+
let OauthAuthorizationMiddleware = OauthAuthorizationMiddleware_1 = class OauthAuthorizationMiddleware {
|
|
20
20
|
constructor(connectService, configService) {
|
|
21
21
|
this.connectService = connectService;
|
|
22
22
|
this.configService = configService;
|
|
23
|
-
this.logger = new infra_logger_service_1.InfraLoggerService(
|
|
23
|
+
this.logger = new infra_logger_service_1.InfraLoggerService(OauthAuthorizationMiddleware_1.name);
|
|
24
24
|
}
|
|
25
25
|
async use(req, res, next) {
|
|
26
26
|
this.logger.debug(`in authorization middleware, about to check authentication ${req.url}`);
|
|
27
27
|
const { query } = req;
|
|
28
28
|
const { code, state } = query;
|
|
29
|
-
const [provider, redirectUrl = ''] = (state ||
|
|
29
|
+
const [provider, redirectUrl = ''] = (state || auth_enum_1.mainProvider).split(auth_enum_1.stateSeparator);
|
|
30
30
|
if (code) {
|
|
31
31
|
next();
|
|
32
32
|
}
|
|
@@ -39,10 +39,10 @@ let AuthorizationMiddleware = AuthorizationMiddleware_1 = class AuthorizationMid
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
|
-
|
|
42
|
+
OauthAuthorizationMiddleware = OauthAuthorizationMiddleware_1 = __decorate([
|
|
43
43
|
common_1.Injectable(),
|
|
44
44
|
__metadata("design:paramtypes", [oauth_service_1.OauthService,
|
|
45
45
|
config_1.ConfigService])
|
|
46
|
-
],
|
|
47
|
-
exports.
|
|
48
|
-
//# sourceMappingURL=authorization.middleware.js.map
|
|
46
|
+
], OauthAuthorizationMiddleware);
|
|
47
|
+
exports.OauthAuthorizationMiddleware = OauthAuthorizationMiddleware;
|
|
48
|
+
//# sourceMappingURL=oauth-authorization.middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-authorization.middleware.js","sourceRoot":"","sources":["../../../src/oauth/middleware/oauth-authorization.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,2CAA+C;AAC/C,uGAAkG;AAElG,kDAAkE;AAKlE,6DAAyD;AAGzD,IAAa,4BAA4B,oCAAzC,MAAa,4BAA4B;IAEvC,YACU,cAA4B,EAC5B,aAA+C;QAD/C,mBAAc,GAAd,cAAc,CAAc;QAC5B,kBAAa,GAAb,aAAa,CAAkC;QAHjD,WAAM,GAAG,IAAI,yCAAkB,CAAC,8BAA4B,CAAC,IAAI,CAAC,CAAC;IAIxE,CAAC;IACJ,KAAK,CAAC,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAgB;QACrD,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,8DAA8D,GAAG,CAAC,GAAG,EAAE,CACxE,CAAC;QACF,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;QACtB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;QAC9B,MAAM,CAAC,QAAQ,EAAE,WAAW,GAAG,EAAE,CAAC,GAAG,CAClC,KAAgB,IAAI,wBAAY,CAClC,CAAC,KAAK,CAAC,0BAAc,CAAC,CAAC;QACxB,IAAI,IAAI,EAAE;YACR,IAAI,EAAE,CAAC;SACR;aAAM;YACL,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,4DAA4D,CAC7D,CAAC;YACF,MAAM,WAAW,GACf,IAAI,CAAC,aAAa,CAAC,GAAG,CAAsB,aAAa,CAAC,CAAC,QAAQ,CAAC,CAAC;YACvE,MAAM,gBAAgB,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,CACxD,WAAW,EACX,WAAW,EACX,QAAQ,CACT,CAAC;YACF,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,yBAAyB,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;YAClE,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;SACrC;IACH,CAAC;CACF,CAAA;AAhCY,4BAA4B;IADxC,mBAAU,EAAE;qCAIe,4BAAY;QACb,sBAAa;GAJ3B,4BAA4B,CAgCxC;AAhCY,oEAA4B"}
|
|
@@ -12,21 +12,28 @@ const common_1 = require("@nestjs/common");
|
|
|
12
12
|
const cookieParser = require("cookie-parser");
|
|
13
13
|
const oauth_service_1 = require("./services/oauth.service");
|
|
14
14
|
const oauth_controller_1 = require("./controllers/oauth.controller");
|
|
15
|
-
const
|
|
15
|
+
const auth_middleware_1 = require("./middleware/auth.middleware");
|
|
16
16
|
const oauth_repository_1 = require("./repositories/oauth.repository");
|
|
17
17
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
18
18
|
const oauth_data_entity_1 = require("./repositories/oauth-data.entity");
|
|
19
19
|
const config_1 = require("@nestjs/config");
|
|
20
|
-
const
|
|
20
|
+
const oauth_authorization_middleware_1 = require("./middleware/oauth-authorization.middleware");
|
|
21
21
|
const oauth_utils_1 = require("./utils/oauth.utils");
|
|
22
22
|
const terminus_1 = require("@nestjs/terminus");
|
|
23
23
|
const oauth_http_service_1 = require("./services/oauth-http.service");
|
|
24
24
|
const infra_nestjs_1 = require("@vcita/infra-nestjs");
|
|
25
|
+
const infra_proxy_service_1 = require("./services/infra-proxy.service");
|
|
26
|
+
const external_proxy_service_1 = require("./services/external-proxy.service");
|
|
27
|
+
const internal_proxy_service_1 = require("./services/internal-proxy.service");
|
|
28
|
+
const nestjs_redis_1 = require("nestjs-redis");
|
|
25
29
|
let OauthModule = OauthModule_1 = class OauthModule {
|
|
26
30
|
configure(consumer) {
|
|
27
31
|
consumer.apply(cookieParser('secret')).exclude('*.*').forRoutes('*');
|
|
28
|
-
consumer
|
|
29
|
-
|
|
32
|
+
consumer
|
|
33
|
+
.apply(auth_middleware_1.AuthMiddleware)
|
|
34
|
+
.exclude('oauth', 'metrics', 'health/check.json')
|
|
35
|
+
.forRoutes('*');
|
|
36
|
+
consumer.apply(oauth_authorization_middleware_1.OauthAuthorizationMiddleware).forRoutes(oauth_controller_1.OauthController);
|
|
30
37
|
}
|
|
31
38
|
static register(config) {
|
|
32
39
|
const configModule = config_1.ConfigModule.forFeature(() => {
|
|
@@ -40,15 +47,32 @@ let OauthModule = OauthModule_1 = class OauthModule {
|
|
|
40
47
|
return {
|
|
41
48
|
module: OauthModule_1,
|
|
42
49
|
controllers: [oauth_controller_1.OauthController],
|
|
43
|
-
providers: [
|
|
50
|
+
providers: [
|
|
51
|
+
oauth_repository_1.OauthRepository,
|
|
52
|
+
oauth_service_1.OauthService,
|
|
53
|
+
oauth_http_service_1.OauthHttpService,
|
|
54
|
+
infra_proxy_service_1.InfraProxyService,
|
|
55
|
+
internal_proxy_service_1.InternalProxyService,
|
|
56
|
+
external_proxy_service_1.ExternalProxyService,
|
|
57
|
+
],
|
|
44
58
|
imports: [
|
|
45
59
|
configModule,
|
|
46
60
|
infra_nestjs_1.InfraModule,
|
|
47
61
|
common_1.HttpModule,
|
|
48
62
|
terminus_1.TerminusModule,
|
|
49
63
|
typeorm_1.TypeOrmModule.forFeature([oauth_data_entity_1.OauthData]),
|
|
64
|
+
nestjs_redis_1.RedisModule.register({
|
|
65
|
+
host: process.env.REDIS_HOST,
|
|
66
|
+
port: parseInt(process.env.REDIS_PORT),
|
|
67
|
+
}),
|
|
68
|
+
],
|
|
69
|
+
exports: [
|
|
70
|
+
oauth_service_1.OauthService,
|
|
71
|
+
oauth_http_service_1.OauthHttpService,
|
|
72
|
+
infra_proxy_service_1.InfraProxyService,
|
|
73
|
+
internal_proxy_service_1.InternalProxyService,
|
|
74
|
+
external_proxy_service_1.ExternalProxyService,
|
|
50
75
|
],
|
|
51
|
-
exports: [oauth_service_1.OauthService, oauth_http_service_1.OauthHttpService],
|
|
52
76
|
};
|
|
53
77
|
}
|
|
54
78
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.module.js","sourceRoot":"","sources":["../../src/oauth/oauth.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAMwB;AACxB,8CAA8C;AAC9C,4DAAwD;AACxD,qEAAiE;AACjE,
|
|
1
|
+
{"version":3,"file":"oauth.module.js","sourceRoot":"","sources":["../../src/oauth/oauth.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAMwB;AACxB,8CAA8C;AAC9C,4DAAwD;AACxD,qEAAiE;AACjE,kEAA8D;AAC9D,sEAAkE;AAClE,6CAAgD;AAChD,wEAA6D;AAC7D,2CAA8C;AAE9C,gGAA2F;AAC3F,qDAA4D;AAC5D,+CAAkD;AAClD,sEAAiE;AACjE,sDAAkD;AAClD,wEAAmE;AACnE,8EAAyE;AACzE,8EAAyE;AACzE,+CAA2C;AAG3C,IAAa,WAAW,mBAAxB,MAAa,WAAW;IACtB,SAAS,CAAC,QAA4B;QACp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B;aACrB;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAnDY,WAAW;IADvB,eAAM,CAAC,EAAE,CAAC;GACE,WAAW,CAmDvB;AAnDY,kCAAW"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthorizationPayloadEntity = void 0;
|
|
4
|
+
class AuthorizationPayloadEntity {
|
|
5
|
+
}
|
|
6
|
+
exports.AuthorizationPayloadEntity = AuthorizationPayloadEntity;
|
|
7
|
+
//# sourceMappingURL=authorization-payload.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-payload.entity.js","sourceRoot":"","sources":["../../../src/oauth/repositories/authorization-payload.entity.ts"],"names":[],"mappings":";;;AAEA,MAAa,0BAA0B;CAGtC;AAHD,gEAGC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { InfraLoggerService } from '@vcita/infra-nestjs/dist/infra/services/infra-logger.service';
|
|
2
|
+
export declare class InfraProxyService {
|
|
3
|
+
protected logger: InfraLoggerService;
|
|
4
|
+
http: any;
|
|
5
|
+
baseUrl: any;
|
|
6
|
+
authentication: any;
|
|
7
|
+
constructor(baseUrl: string);
|
|
8
|
+
setAuthentication(token: string): void;
|
|
9
|
+
request<T = any>(method: string, path: string | null, id?: number | string | null, params?: {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}, data?: {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}, tokenCustomClaims?: {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}): Promise<any>;
|
|
16
|
+
getRequest<T = any>(path: string | null, id?: number | string | null, params?: {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}, tokenCustomClaims?: {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}): Promise<any>;
|
|
21
|
+
deleteRequest<T = any>(path: string | null, id: number | string | null, params?: {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}, tokenCustomClaims?: {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}): Promise<any>;
|
|
26
|
+
putRequest<T = any>(path: string | null, id: number | string | null, body?: {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}, tokenCustomClaims?: {
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
}): Promise<any>;
|
|
31
|
+
postRequest<T = any>(path: string | null, body?: {
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
}, tokenCustomClaims?: {
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
}): Promise<any>;
|
|
36
|
+
private buildFullUrl;
|
|
37
|
+
getHeaders(tokenCustomClaims: {
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
headers: any;
|
|
41
|
+
}>;
|
|
42
|
+
}
|