@vcita/oauth-client-nestjs 1.9.2 → 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 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/oauth/enums/auth.enum.d.ts +5 -6
- package/dist/oauth/enums/auth.enum.js +8 -10
- package/dist/oauth/enums/auth.enum.js.map +1 -1
- package/dist/oauth/oauth.module.js +11 -3
- package/dist/oauth/oauth.module.js.map +1 -1
- package/dist/oauth/services/Infra-proxy.service.d.ts +12 -12
- package/dist/oauth/services/Infra-proxy.service.js +22 -10
- package/dist/oauth/services/Infra-proxy.service.js.map +1 -1
- package/dist/oauth/services/external-proxy.service.d.ts +5 -10
- package/dist/oauth/services/external-proxy.service.js +21 -10
- package/dist/oauth/services/external-proxy.service.js.map +1 -1
- 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/utils/authentication.utils.js +3 -3
- package/dist/oauth/utils/authentication.utils.js.map +1 -1
- package/dist/oauth/utils/oauth.utils.d.ts +2 -1
- package/dist/oauth/utils/oauth.utils.js +3 -2
- package/dist/oauth/utils/oauth.utils.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -2
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,5 +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
9
|
export * from './oauth/repositories/oauth-data.entity';
|
package/dist/index.js
CHANGED
|
@@ -14,6 +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
21
|
__exportStar(require("./oauth/repositories/oauth-data.entity"), exports);
|
|
19
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,yEAAuD"}
|
|
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"}
|
|
@@ -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,13 +14,11 @@ export declare enum GrantTypes {
|
|
|
13
14
|
export declare enum ResponseTypes {
|
|
14
15
|
code = "code"
|
|
15
16
|
}
|
|
16
|
-
export declare enum
|
|
17
|
-
|
|
17
|
+
export declare enum InfraAuthentication {
|
|
18
|
+
InboundHeaderName = "X-AUTHORIZATION",
|
|
19
|
+
OutboundHeaderName = "Authorization",
|
|
18
20
|
Algorithm = "RS512"
|
|
19
21
|
}
|
|
20
|
-
export declare enum ExternalAuthentication {
|
|
21
|
-
HeaderName = "Authorization"
|
|
22
|
-
}
|
|
23
22
|
export declare const stateSeparator = ";;;";
|
|
24
23
|
export declare const cookieName = "sessionCookie";
|
|
25
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.
|
|
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,15 +22,12 @@ var ResponseTypes;
|
|
|
21
22
|
(function (ResponseTypes) {
|
|
22
23
|
ResponseTypes["code"] = "code";
|
|
23
24
|
})(ResponseTypes = exports.ResponseTypes || (exports.ResponseTypes = {}));
|
|
24
|
-
var
|
|
25
|
-
(function (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
(function (ExternalAuthentication) {
|
|
31
|
-
ExternalAuthentication["HeaderName"] = "Authorization";
|
|
32
|
-
})(ExternalAuthentication = exports.ExternalAuthentication || (exports.ExternalAuthentication = {}));
|
|
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 = {}));
|
|
33
31
|
exports.stateSeparator = ';;;';
|
|
34
32
|
exports.cookieName = 'sessionCookie';
|
|
35
33
|
exports.mainProvider = 'vcita';
|
|
@@ -1 +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,
|
|
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"}
|
|
@@ -22,8 +22,10 @@ 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
|
|
25
|
+
const infra_proxy_service_1 = require("./services/infra-proxy.service");
|
|
26
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");
|
|
27
29
|
let OauthModule = OauthModule_1 = class OauthModule {
|
|
28
30
|
configure(consumer) {
|
|
29
31
|
consumer.apply(cookieParser('secret')).exclude('*.*').forRoutes('*');
|
|
@@ -49,7 +51,8 @@ let OauthModule = OauthModule_1 = class OauthModule {
|
|
|
49
51
|
oauth_repository_1.OauthRepository,
|
|
50
52
|
oauth_service_1.OauthService,
|
|
51
53
|
oauth_http_service_1.OauthHttpService,
|
|
52
|
-
|
|
54
|
+
infra_proxy_service_1.InfraProxyService,
|
|
55
|
+
internal_proxy_service_1.InternalProxyService,
|
|
53
56
|
external_proxy_service_1.ExternalProxyService,
|
|
54
57
|
],
|
|
55
58
|
imports: [
|
|
@@ -58,11 +61,16 @@ let OauthModule = OauthModule_1 = class OauthModule {
|
|
|
58
61
|
common_1.HttpModule,
|
|
59
62
|
terminus_1.TerminusModule,
|
|
60
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
|
+
}),
|
|
61
68
|
],
|
|
62
69
|
exports: [
|
|
63
70
|
oauth_service_1.OauthService,
|
|
64
71
|
oauth_http_service_1.OauthHttpService,
|
|
65
|
-
|
|
72
|
+
infra_proxy_service_1.InfraProxyService,
|
|
73
|
+
internal_proxy_service_1.InternalProxyService,
|
|
66
74
|
external_proxy_service_1.ExternalProxyService,
|
|
67
75
|
],
|
|
68
76
|
};
|
|
@@ -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,kEAA8D;AAC9D,sEAAkE;AAClE,6CAAgD;AAChD,wEAA6D;AAC7D,2CAA8C;AAE9C,gGAA2F;AAC3F,qDAA4D;AAC5D,+CAAkD;AAClD,sEAAiE;AACjE,sDAAkD;AAClD,wEAAmE;AACnE,8EAAyE;
|
|
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;QACpC,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC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AnDY,kCAAW"}
|
|
@@ -1,30 +1,34 @@
|
|
|
1
|
+
import { InfraLoggerService } from '@vcita/infra-nestjs/dist/infra/services/infra-logger.service';
|
|
1
2
|
export declare class InfraProxyService {
|
|
3
|
+
protected logger: InfraLoggerService;
|
|
2
4
|
http: any;
|
|
3
5
|
baseUrl: any;
|
|
6
|
+
authentication: any;
|
|
4
7
|
constructor(baseUrl: string);
|
|
5
|
-
|
|
8
|
+
setAuthentication(token: string): void;
|
|
9
|
+
request<T = any>(method: string, path: string | null, id?: number | string | null, params?: {
|
|
6
10
|
[key: string]: any;
|
|
7
11
|
}, data?: {
|
|
8
12
|
[key: string]: any;
|
|
9
13
|
}, tokenCustomClaims?: {
|
|
10
14
|
[key: string]: any;
|
|
11
15
|
}): Promise<any>;
|
|
12
|
-
getRequest(path: string | null, id?: number | string | null, params?: {
|
|
16
|
+
getRequest<T = any>(path: string | null, id?: number | string | null, params?: {
|
|
13
17
|
[key: string]: any;
|
|
14
18
|
}, tokenCustomClaims?: {
|
|
15
19
|
[key: string]: any;
|
|
16
20
|
}): Promise<any>;
|
|
17
|
-
deleteRequest(path: string | null, id: number | string | null, params?: {
|
|
21
|
+
deleteRequest<T = any>(path: string | null, id: number | string | null, params?: {
|
|
18
22
|
[key: string]: any;
|
|
19
23
|
}, tokenCustomClaims?: {
|
|
20
24
|
[key: string]: any;
|
|
21
25
|
}): Promise<any>;
|
|
22
|
-
putRequest(path: string | null, id: number | string | null, body?: {
|
|
26
|
+
putRequest<T = any>(path: string | null, id: number | string | null, body?: {
|
|
23
27
|
[key: string]: any;
|
|
24
28
|
}, tokenCustomClaims?: {
|
|
25
29
|
[key: string]: any;
|
|
26
30
|
}): Promise<any>;
|
|
27
|
-
postRequest(path: string | null,
|
|
31
|
+
postRequest<T = any>(path: string | null, body?: {
|
|
28
32
|
[key: string]: any;
|
|
29
33
|
}, tokenCustomClaims?: {
|
|
30
34
|
[key: string]: any;
|
|
@@ -32,11 +36,7 @@ export declare class InfraProxyService {
|
|
|
32
36
|
private buildFullUrl;
|
|
33
37
|
getHeaders(tokenCustomClaims: {
|
|
34
38
|
[key: string]: any;
|
|
35
|
-
}): {
|
|
36
|
-
headers:
|
|
37
|
-
|
|
38
|
-
Accept: string;
|
|
39
|
-
'x-trace-id': string;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
39
|
+
}): Promise<{
|
|
40
|
+
headers: any;
|
|
41
|
+
}>;
|
|
42
42
|
}
|
|
@@ -3,16 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.InfraProxyService = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const infra_nestjs_1 = require("@vcita/infra-nestjs");
|
|
6
|
+
const auth_enum_1 = require("../enums/auth.enum");
|
|
7
|
+
const infra_logger_service_1 = require("@vcita/infra-nestjs/dist/infra/services/infra-logger.service");
|
|
6
8
|
class InfraProxyService {
|
|
7
9
|
constructor(baseUrl) {
|
|
10
|
+
this.logger = new infra_logger_service_1.InfraLoggerService(InfraProxyService.name);
|
|
8
11
|
this.baseUrl = baseUrl;
|
|
9
12
|
this.http = new common_1.HttpService();
|
|
10
13
|
}
|
|
14
|
+
setAuthentication(token) {
|
|
15
|
+
const authentication = {};
|
|
16
|
+
authentication[auth_enum_1.InfraAuthentication.OutboundHeaderName] = `${auth_enum_1.TokenTypes.Bearer} ${token}`;
|
|
17
|
+
this.authentication = authentication;
|
|
18
|
+
}
|
|
11
19
|
async request(method, path, id = null, params = null, data = null, tokenCustomClaims = null) {
|
|
20
|
+
const headers = await this.getHeaders(tokenCustomClaims);
|
|
12
21
|
const requestConfig = {
|
|
13
22
|
url: this.buildFullUrl(path, id, params),
|
|
14
23
|
method: method,
|
|
15
|
-
...
|
|
24
|
+
...headers,
|
|
16
25
|
};
|
|
17
26
|
if (data)
|
|
18
27
|
requestConfig['data'] = data;
|
|
@@ -20,17 +29,19 @@ class InfraProxyService {
|
|
|
20
29
|
.request(requestConfig)
|
|
21
30
|
.toPromise()
|
|
22
31
|
.then((res) => {
|
|
23
|
-
if (res.data && res.data.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
if (res.data && res.data['success'] && res.data['data']) {
|
|
33
|
+
this.logger.log(`requestConfig: ${JSON.stringify(res.data['data'])}`);
|
|
34
|
+
return res.data['data'];
|
|
35
|
+
}
|
|
36
|
+
if (res.data && res.data['errors']) {
|
|
37
|
+
const error = res.data['errors'][0];
|
|
27
38
|
if (error.message)
|
|
28
39
|
throw new Error(error.message);
|
|
29
40
|
}
|
|
30
41
|
throw new Error('Unknown response');
|
|
31
42
|
})
|
|
32
43
|
.catch((e) => {
|
|
33
|
-
|
|
44
|
+
this.logger.error(`Http request: ${e.message}`, '');
|
|
34
45
|
});
|
|
35
46
|
}
|
|
36
47
|
async getRequest(path, id = null, params = null, tokenCustomClaims = null) {
|
|
@@ -42,8 +53,8 @@ class InfraProxyService {
|
|
|
42
53
|
async putRequest(path, id, body = null, tokenCustomClaims = null) {
|
|
43
54
|
return this.request('PUT', path, id, null, body, tokenCustomClaims);
|
|
44
55
|
}
|
|
45
|
-
async postRequest(path,
|
|
46
|
-
return this.request('POST', path,
|
|
56
|
+
async postRequest(path, body = null, tokenCustomClaims = null) {
|
|
57
|
+
return this.request('POST', path, null, null, body, tokenCustomClaims);
|
|
47
58
|
}
|
|
48
59
|
buildFullUrl(path, id, params = null) {
|
|
49
60
|
let fullUrl = this.baseUrl;
|
|
@@ -56,14 +67,15 @@ class InfraProxyService {
|
|
|
56
67
|
fullUrl += '?' + qs;
|
|
57
68
|
return fullUrl;
|
|
58
69
|
}
|
|
59
|
-
getHeaders(tokenCustomClaims) {
|
|
70
|
+
async getHeaders(tokenCustomClaims) {
|
|
60
71
|
const headers = {
|
|
61
72
|
'Content-Type': 'application/json',
|
|
62
73
|
Accept: 'application/json',
|
|
63
74
|
'x-trace-id': infra_nestjs_1.randomStringGen(32),
|
|
75
|
+
...this.authentication,
|
|
64
76
|
};
|
|
65
77
|
return { headers: headers };
|
|
66
78
|
}
|
|
67
79
|
}
|
|
68
80
|
exports.InfraProxyService = InfraProxyService;
|
|
69
|
-
//# sourceMappingURL=
|
|
81
|
+
//# sourceMappingURL=infra-proxy.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"infra-proxy.service.js","sourceRoot":"","sources":["../../../src/oauth/services/infra-proxy.service.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,sDAAsD;AACtD,kDAAqE;AACrE,uGAAkG;AAElG,MAAa,iBAAiB;IAM5B,YAAY,OAAe;QALjB,WAAM,GAAG,IAAI,yCAAkB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAMhE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,oBAAW,EAAE,CAAC;IAChC,CAAC;IAED,iBAAiB,CAAC,KAAa;QAC7B,MAAM,cAAc,GAAG,EAAE,CAAC;QAC1B,cAAc,CACZ,+BAAmB,CAAC,kBAAkB,CACvC,GAAG,GAAG,sBAAU,CAAC,MAAM,IAAI,KAAK,EAAE,CAAC;QACpC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,OAAO,CACX,MAAc,EACd,IAAmB,EACnB,KAA6B,IAAI,EACjC,SAAiC,IAAI,EACrC,OAA+B,IAAI,EACnC,oBAA4C,IAAI;QAEhD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;QACzD,MAAM,aAAa,GAAG;YACpB,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC;YACxC,MAAM,EAAE,MAAM;YACd,GAAG,OAAO;SACX,CAAC;QACF,IAAI,IAAI;YAAE,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;QACvC,OAAO,MAAM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;CACF;AA/GD,8CA+GC"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { InfraProxyService } from './
|
|
1
|
+
import { InfraProxyService } from './infra-proxy.service';
|
|
2
2
|
export declare class ExternalProxyService extends InfraProxyService {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
'Content-Type': string;
|
|
8
|
-
Accept: string;
|
|
9
|
-
'x-trace-id': string;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
3
|
+
privateKey: any;
|
|
4
|
+
constructor(baseUrl: string);
|
|
5
|
+
private setPrivateKey;
|
|
6
|
+
fetchPrivateKey(): Promise<void>;
|
|
12
7
|
}
|
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExternalProxyService = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
'Content-Type': 'application/json',
|
|
10
|
-
Accept: 'application/json',
|
|
11
|
-
'x-trace-id': infra_nestjs_1.randomStringGen(32),
|
|
12
|
-
};
|
|
13
|
-
return { headers: headers };
|
|
4
|
+
const infra_proxy_service_1 = require("./infra-proxy.service");
|
|
5
|
+
class ExternalProxyService extends infra_proxy_service_1.InfraProxyService {
|
|
6
|
+
constructor(baseUrl) {
|
|
7
|
+
super(baseUrl);
|
|
8
|
+
this.setPrivateKey();
|
|
14
9
|
}
|
|
10
|
+
setPrivateKey() {
|
|
11
|
+
let key;
|
|
12
|
+
if (key) {
|
|
13
|
+
this.privateKey = key;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
this.fetchPrivateKey()
|
|
17
|
+
.then((key) => {
|
|
18
|
+
this.privateKey = key;
|
|
19
|
+
})
|
|
20
|
+
.catch((err) => {
|
|
21
|
+
console.error(err);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async fetchPrivateKey() { }
|
|
15
26
|
}
|
|
16
27
|
exports.ExternalProxyService = ExternalProxyService;
|
|
17
28
|
//# sourceMappingURL=external-proxy.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-proxy.service.js","sourceRoot":"","sources":["../../../src/oauth/services/external-proxy.service.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;
|
|
1
|
+
{"version":3,"file":"external-proxy.service.js","sourceRoot":"","sources":["../../../src/oauth/services/external-proxy.service.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAE1D,MAAa,oBAAqB,SAAQ,uCAAiB;IAEzD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IAEO,aAAa;QACnB,IAAI,GAAG,CAAC;QAMR,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;SACvB;aAAM;YACL,IAAI,CAAC,eAAe,EAAE;iBACnB,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;gBACZ,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;YACxB,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACrB,CAAC,CAAC,CAAC;SACN;IACH,CAAC;IAED,KAAK,CAAC,eAAe,KAAI,CAAC;CAC3B;AA5BD,oDA4BC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InternalProxyService = void 0;
|
|
4
|
+
const infra_proxy_service_1 = require("./infra-proxy.service");
|
|
5
|
+
const auth_enum_1 = require("../enums/auth.enum");
|
|
6
|
+
const oauth_utils_1 = require("../utils/oauth.utils");
|
|
7
|
+
class InternalProxyService extends infra_proxy_service_1.InfraProxyService {
|
|
8
|
+
constructor(baseUrl) {
|
|
9
|
+
super(baseUrl);
|
|
10
|
+
this.oauthConfiguration = oauth_utils_1.mainOauthConfig();
|
|
11
|
+
this.setToken();
|
|
12
|
+
}
|
|
13
|
+
setToken() {
|
|
14
|
+
let token;
|
|
15
|
+
if (token) {
|
|
16
|
+
this.setAuthentication(token);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
this.fetchTokenFromAuthService()
|
|
20
|
+
.then((data) => {
|
|
21
|
+
token = data.token;
|
|
22
|
+
this.setAuthentication(token);
|
|
23
|
+
console.log(`The token: ${token}`);
|
|
24
|
+
})
|
|
25
|
+
.catch((err) => {
|
|
26
|
+
console.error(err);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async fetchTokenFromAuthService() {
|
|
31
|
+
const proxy = new infra_proxy_service_1.InfraProxyService(`${this.oauthConfiguration.applicationServer}`);
|
|
32
|
+
this.logger.log(`fetchTokenFromAuthService: test`);
|
|
33
|
+
const { test } = await proxy.getRequest('health/check.json', null, null, null);
|
|
34
|
+
this.logger.log(`fetchTokenFromAuthService: test. data: ${JSON.stringify(test)}`);
|
|
35
|
+
this.logger.log(`fetchTokenFromAuthService: getting access token`);
|
|
36
|
+
const { data } = await proxy.postRequest(auth_enum_1.EndPoints.generateStoSToken, {
|
|
37
|
+
service_secret: this.oauthConfiguration.clientSecret,
|
|
38
|
+
service_id: this.oauthConfiguration.clientId,
|
|
39
|
+
}, null);
|
|
40
|
+
this.logger.log(`after generating access token. data: ${JSON.stringify(data)}`);
|
|
41
|
+
return data.token;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.InternalProxyService = InternalProxyService;
|
|
45
|
+
//# sourceMappingURL=inernal-proxy.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inernal-proxy.service.js","sourceRoot":"","sources":["../../../src/oauth/services/inernal-proxy.service.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAC1D,kDAA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MAAM,KAAK,CAAC,WAAW,CACtC,qBAAS,CAAC,iBAAiB,EAC3B;YACE,cAAc,EAAE,IAAI,CAAC,kBAAkB,CAAC,YAAY;YACpD,UAAU,EAAE,IAAI,CAAC,kBAAkB,CAAC,QAAQ;SAC7C,EACD,IAAI,CACL,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,wCAAwC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAC/D,CAAC;QACF,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AA3DD,oDA2DC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { InfraProxyService } from './infra-proxy.service';
|
|
2
|
+
import { RedisService } from 'nestjs-redis';
|
|
3
|
+
export declare class InternalProxyService extends InfraProxyService {
|
|
4
|
+
private redisService;
|
|
5
|
+
oauthConfiguration: any;
|
|
6
|
+
redisClient: any;
|
|
7
|
+
tokenCacheKey: any;
|
|
8
|
+
constructor(redisService: RedisService);
|
|
9
|
+
getHeaders(tokenCustomClaims: {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
headers: any;
|
|
13
|
+
}>;
|
|
14
|
+
private setToken;
|
|
15
|
+
fetchTokenFromAuthService(): Promise<any>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var InternalProxyService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.InternalProxyService = void 0;
|
|
14
|
+
const infra_proxy_service_1 = require("./infra-proxy.service");
|
|
15
|
+
const auth_enum_1 = require("../enums/auth.enum");
|
|
16
|
+
const oauth_utils_1 = require("../utils/oauth.utils");
|
|
17
|
+
const nestjs_redis_1 = require("nestjs-redis");
|
|
18
|
+
const infra_nestjs_1 = require("@vcita/infra-nestjs");
|
|
19
|
+
const common_1 = require("@nestjs/common");
|
|
20
|
+
let InternalProxyService = InternalProxyService_1 = class InternalProxyService extends infra_proxy_service_1.InfraProxyService {
|
|
21
|
+
constructor(redisService) {
|
|
22
|
+
super(oauth_utils_1.mainOauthConfig().applicationServer);
|
|
23
|
+
this.redisService = redisService;
|
|
24
|
+
this.oauthConfiguration = oauth_utils_1.mainOauthConfig();
|
|
25
|
+
this.redisClient = this.redisService.getClient();
|
|
26
|
+
this.tokenCacheKey = `${InternalProxyService_1.name}::Token`;
|
|
27
|
+
}
|
|
28
|
+
async getHeaders(tokenCustomClaims) {
|
|
29
|
+
await this.setToken();
|
|
30
|
+
const headers = {
|
|
31
|
+
'Content-Type': 'application/json',
|
|
32
|
+
Accept: 'application/json',
|
|
33
|
+
'x-trace-id': infra_nestjs_1.randomStringGen(32),
|
|
34
|
+
...this.authentication,
|
|
35
|
+
};
|
|
36
|
+
return { headers: headers };
|
|
37
|
+
}
|
|
38
|
+
setToken() {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
this.redisClient.get(this.tokenCacheKey).then((token) => {
|
|
41
|
+
if (token) {
|
|
42
|
+
this.logger.debug(`We have cached token`);
|
|
43
|
+
this.setAuthentication(token);
|
|
44
|
+
resolve();
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this.logger.debug(`Need to fetch new token`);
|
|
48
|
+
this.fetchTokenFromAuthService()
|
|
49
|
+
.then((token) => {
|
|
50
|
+
token = this.redisClient.set(this.tokenCacheKey, token);
|
|
51
|
+
this.setAuthentication(token);
|
|
52
|
+
resolve();
|
|
53
|
+
})
|
|
54
|
+
.catch((err) => {
|
|
55
|
+
reject(err);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async fetchTokenFromAuthService() {
|
|
62
|
+
const proxy = new infra_proxy_service_1.InfraProxyService(this.oauthConfiguration.applicationServer);
|
|
63
|
+
const data = await proxy.postRequest(auth_enum_1.EndPoints.generateStoSToken, {
|
|
64
|
+
service_secret: this.oauthConfiguration.clientSecret,
|
|
65
|
+
service_id: this.oauthConfiguration.clientId,
|
|
66
|
+
}, null);
|
|
67
|
+
if (data && data['token'])
|
|
68
|
+
return data['token'];
|
|
69
|
+
throw new Error('Unknown response');
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
InternalProxyService = InternalProxyService_1 = __decorate([
|
|
73
|
+
common_1.Injectable(),
|
|
74
|
+
__metadata("design:paramtypes", [nestjs_redis_1.RedisService])
|
|
75
|
+
], InternalProxyService);
|
|
76
|
+
exports.InternalProxyService = InternalProxyService;
|
|
77
|
+
//# sourceMappingURL=internal-proxy.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal-proxy.service.js","sourceRoot":"","sources":["../../../src/oauth/services/internal-proxy.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,+DAA0D;AAC1D,kDAA+C;AAC/C,sDAAuD;AACvD,+CAA4C;AAC5C,sDAAsD;AACtD,2CAA4C;AAG5C,IAAa,oBAAoB,4BAAjC,MAAa,oBAAqB,SAAQ,uCAAiB;IAKzD,YAAoB,YAA0B;QAC5C,KAAK,CAAC,6BAAe,EAAE,CAAC,iBAAiB,CAAC,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;oBACZ,CAAC,CAAC;yBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;wBACb,MAAM,CAAC,GAAG,CAAC,CAAC;oBACd,CAAC,CAAC,CAAC;iBACN;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,yBAAyB;QAC7B,MAAM,KAAK,GAAG,IAAI,uCAAiB,CACjC,IAAI,CAAC,kBAAkB,CAAC,iBAAiB,CAC1C,CAAC;QAEF,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,WAAW,CAClC,qBAAS,CAAC,iBAAiB,EAC3B;YACE,cAAc,EAAE,IAAI,CAAC,kBAAkB,CAAC,YAAY;YACpD,UAAU,EAAE,IAAI,CAAC,kBAAkB,CAAC,QAAQ;SAC7C,EACD,IAAI,CACL,CAAC;QAEF,IAAI,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;CACF,CAAA;AA/DY,oBAAoB;IADhC,mBAAU,EAAE;qCAMuB,2BAAY;GALnC,oBAAoB,CA+DhC;AA/DY,oDAAoB"}
|
|
@@ -14,7 +14,7 @@ class AuthenticationUtils {
|
|
|
14
14
|
}
|
|
15
15
|
static extractTokenFromRequest(req) {
|
|
16
16
|
let token;
|
|
17
|
-
const authorizationHeader = req.get(auth_enum_1.
|
|
17
|
+
const authorizationHeader = req.get(auth_enum_1.InfraAuthentication.InboundHeaderName);
|
|
18
18
|
if (authorizationHeader &&
|
|
19
19
|
authorizationHeader.startsWith(auth_enum_1.TokenTypes.Bearer)) {
|
|
20
20
|
token = authorizationHeader.replace(auth_enum_1.TokenTypes.Bearer, '');
|
|
@@ -73,6 +73,6 @@ class AuthenticationUtils {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
exports.AuthenticationUtils = AuthenticationUtils;
|
|
76
|
-
AuthenticationUtils.ALGORITHM = auth_enum_1.
|
|
77
|
-
AuthenticationUtils.ALGORITHMS = [auth_enum_1.
|
|
76
|
+
AuthenticationUtils.ALGORITHM = auth_enum_1.InfraAuthentication.Algorithm;
|
|
77
|
+
AuthenticationUtils.ALGORITHMS = [auth_enum_1.InfraAuthentication.Algorithm];
|
|
78
78
|
//# sourceMappingURL=authentication.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.utils.js","sourceRoot":"","sources":["../../../src/oauth/utils/authentication.utils.ts"],"names":[],"mappings":";;;AAQA,+CAA4C;AAC5C,sDAAkD;AAClD,uFAAgF;AAChF,+FAA0F;AAC1F,gGAAoF;AACpF,
|
|
1
|
+
{"version":3,"file":"authentication.utils.js","sourceRoot":"","sources":["../../../src/oauth/utils/authentication.utils.ts"],"names":[],"mappings":";;;AAQA,+CAA4C;AAC5C,sDAAkD;AAClD,uFAAgF;AAChF,+FAA0F;AAC1F,gGAAoF;AACpF,kDAAqE;AAErE,MAAa,mBAAmB;IAI9B,MAAM,CAAC,MAAM,CAAC,KAAa,EAAE,QAAwB;QACnD,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,qBAAM,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,gBAAgB,EAAE,EAAE,QAAQ,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,CAAC,uBAAuB,CAAC,GAAY;QACzC,IAAI,KAAK,CAAC;QACV,MAAM,mBAAmB,GAAG,GAAG,CAAC,GAAG,CAAC,+BAAmB,CAAC,iBAAiB,CAAC,CAAC;QAC3E,IACE,mBAAmB;YACnB,mBAAmB,CAAC,UAAU,CAAC,sBAAU,CAAC,MAAM,CAAC,EACjD;YACA,KAAK,GAAG,mBAAmB,CAAC,OAAO,CAAC,sBAAU,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;SAC5D;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAA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MAAM,GAAG;YACb,GAAG,EAAE,uBAAa,EAAE,CAAC,IAAI;YACzB,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAa,EAAE,CAAC,IAAI;YAC7C,GAAG,EAAE,QAAQ;YACb,GAAG,EAAE,oBAAoB,GAAG,GAAG;YAC/B,GAAG,EAAE,oBAAoB;SAC1B,CAAC;QAEF,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,qBAAqB,CAC1B,OAAmB;QAEnB,IAAI,GAAG,GAAG,IAAI,yDAA0B,EAAE,CAAC;QAC3C,IAAI,OAAO,CAAC,GAAG;YAAE,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrD,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YAC5C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnC,GAAG,CAAC,KAAK,GAAG,IAAI,0BAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,8BAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACxD;QACD,OAAO,GAAG,CAAC;IACb,CAAC;;AAtGH,kDAuGC;AAtGQ,6BAAS,GAAc,+BAAmB,CAAC,SAAS,CAAC;AACrD,8BAAU,GAAgB,CAAC,+BAAmB,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { ProviderOauthConfig } from '../interfaces/oauth.interface';
|
|
1
|
+
import { ProviderOauthConfig, OauthInterface } from '../interfaces/oauth.interface';
|
|
2
|
+
export declare const mainOauthConfig: () => Partial<OauthInterface>;
|
|
2
3
|
export declare const getOauthConfiguration: (subProvidersConfig: ProviderOauthConfig) => ProviderOauthConfig;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getOauthConfiguration = void 0;
|
|
3
|
+
exports.getOauthConfiguration = exports.mainOauthConfig = void 0;
|
|
4
4
|
const configuration_1 = require("../config/configuration");
|
|
5
5
|
const vcitaClaimsConfig = require("./vcita-claims.config.json");
|
|
6
6
|
const auth_enum_1 = require("../enums/auth.enum");
|
|
@@ -26,10 +26,11 @@ const mainOauthConfig = () => ({
|
|
|
26
26
|
applicationServer: process.env.API_GW_SERVER,
|
|
27
27
|
claimsConfig: claimsConfigData(vcitaClaimsConfig),
|
|
28
28
|
});
|
|
29
|
+
exports.mainOauthConfig = mainOauthConfig;
|
|
29
30
|
const getOauthConfiguration = (subProvidersConfig) => {
|
|
30
31
|
const providersOauthConfig = {
|
|
31
32
|
...subProvidersConfig,
|
|
32
|
-
[auth_enum_1.mainProvider]: mainOauthConfig(),
|
|
33
|
+
[auth_enum_1.mainProvider]: exports.mainOauthConfig(),
|
|
33
34
|
};
|
|
34
35
|
return Object.fromEntries(Object.entries(providersOauthConfig).map(([provider, config]) => [
|
|
35
36
|
provider,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.utils.js","sourceRoot":"","sources":["../../../src/oauth/utils/oauth.utils.ts"],"names":[],"mappings":";;;AAKA,2DAAsD;AACtD,gEAAgE;AAChE,kDAAkD;AAElD,MAAM,gBAAgB,GAAG,CACvB,IAAoC,EACvB,EAAE;IACf,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;;QACxB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,SAAS,EAAE,KAAK;aACjB,CAAC;SACH;QACD,OAAO;YACL,GAAG,KAAK;YACR,QAAQ,EAAE,MAAA,KAAK,CAAC,QAAQ,mCAAI,KAAK,CAAC,SAAS;SAC5C,CAAC;IACJ,CAAC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