@futdevpro/nts-dynamo 1.10.23 → 1.10.25
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/build/_modules/oauth2/_routes/oauth2.controller.d.ts +17 -0
- package/build/_modules/oauth2/_routes/oauth2.controller.d.ts.map +1 -0
- package/build/_modules/oauth2/_routes/oauth2.controller.js +97 -0
- package/build/_modules/oauth2/_routes/oauth2.controller.js.map +1 -0
- package/build/_modules/oauth2/_services/oauth2.auth-service.d.ts +31 -0
- package/build/_modules/oauth2/_services/oauth2.auth-service.d.ts.map +1 -0
- package/build/_modules/oauth2/_services/oauth2.auth-service.js +216 -0
- package/build/_modules/oauth2/_services/oauth2.auth-service.js.map +1 -0
- package/build/_modules/oauth2/_services/oauth2.control-service.d.ts +133 -0
- package/build/_modules/oauth2/_services/oauth2.control-service.d.ts.map +1 -0
- package/build/_modules/oauth2/_services/oauth2.control-service.js +574 -0
- package/build/_modules/oauth2/_services/oauth2.control-service.js.map +1 -0
- package/build/_modules/oauth2/index.d.ts +4 -0
- package/build/_modules/oauth2/index.d.ts.map +1 -0
- package/build/_modules/oauth2/index.js +7 -0
- package/build/_modules/oauth2/index.js.map +1 -0
- package/build/_modules/open-ai/_enums/open-ai-model.enum.d.ts +11 -0
- package/build/_modules/open-ai/_enums/open-ai-model.enum.d.ts.map +1 -0
- package/build/_modules/open-ai/_enums/open-ai-model.enum.js +110 -0
- package/build/_modules/open-ai/_enums/open-ai-model.enum.js.map +1 -0
- package/build/_modules/open-ai/_models/gpt-call-settings.interface.d.ts +54 -0
- package/build/_modules/open-ai/_models/gpt-call-settings.interface.d.ts.map +1 -0
- package/build/_modules/open-ai/_models/gpt-call-settings.interface.js +65 -0
- package/build/_modules/open-ai/_models/gpt-call-settings.interface.js.map +1 -0
- package/build/_modules/open-ai/_models/open-ai-api-env-settings.interface.d.ts +7 -0
- package/build/_modules/open-ai/_models/open-ai-api-env-settings.interface.d.ts.map +1 -0
- package/build/_modules/open-ai/_models/open-ai-api-env-settings.interface.js +3 -0
- package/build/_modules/open-ai/_models/open-ai-api-env-settings.interface.js.map +1 -0
- package/build/_modules/open-ai/_models/open-ai-settings.interface.d.ts +17 -0
- package/build/_modules/open-ai/_models/open-ai-settings.interface.d.ts.map +1 -0
- package/build/_modules/open-ai/_models/open-ai-settings.interface.js +25 -0
- package/build/_modules/open-ai/_models/open-ai-settings.interface.js.map +1 -0
- package/build/_modules/open-ai/_services/embedding.control-service.d.ts +26 -0
- package/build/_modules/open-ai/_services/embedding.control-service.d.ts.map +1 -0
- package/build/_modules/open-ai/_services/embedding.control-service.js +54 -0
- package/build/_modules/open-ai/_services/embedding.control-service.js.map +1 -0
- package/build/_modules/open-ai/_services/gpt.service-base.d.ts +98 -0
- package/build/_modules/open-ai/_services/gpt.service-base.d.ts.map +1 -0
- package/build/_modules/open-ai/_services/gpt.service-base.js +284 -0
- package/build/_modules/open-ai/_services/gpt.service-base.js.map +1 -0
- package/build/_modules/open-ai/_services/open-ai.service-base.d.ts +23 -0
- package/build/_modules/open-ai/_services/open-ai.service-base.d.ts.map +1 -0
- package/build/_modules/open-ai/_services/open-ai.service-base.js +50 -0
- package/build/_modules/open-ai/_services/open-ai.service-base.js.map +1 -0
- package/build/_modules/open-ai/index.d.ts +8 -0
- package/build/_modules/open-ai/index.d.ts.map +1 -0
- package/build/_modules/open-ai/index.js +11 -0
- package/build/_modules/open-ai/index.js.map +1 -0
- package/build/_services/base/db.service.d.ts +38 -0
- package/build/_services/base/db.service.d.ts.map +1 -1
- package/build/_services/base/db.service.js +40 -0
- package/build/_services/base/db.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts +17 -0
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +17 -0
- package/build/_services/server/app.server.js.map +1 -1
- package/package.json +47 -17
- package/src/_modules/oauth2/_routes/oauth2.controller.ts +99 -0
- package/src/_modules/oauth2/_services/oauth2.auth-service.ts +232 -0
- package/src/_modules/oauth2/_services/oauth2.control-service.ts +651 -0
- package/src/_modules/oauth2/index.ts +9 -0
- package/src/_modules/open-ai/_enums/open-ai-model.enum.ts +137 -0
- package/src/_modules/open-ai/_models/gpt-call-settings.interface.ts +69 -0
- package/src/_modules/open-ai/_models/open-ai-api-env-settings.interface.ts +12 -0
- package/src/_modules/open-ai/_models/open-ai-settings.interface.ts +31 -0
- package/src/_modules/open-ai/_services/embedding.control-service.ts +61 -0
- package/src/_modules/open-ai/_services/gpt.service-base.ts +440 -0
- package/src/_modules/open-ai/_services/open-ai.service-base.ts +73 -0
- package/src/_modules/open-ai/index.ts +13 -0
- package/src/_services/base/db.service.ts +41 -0
- package/src/_services/server/app.server.ts +18 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DyNTS_Controller } from '../../../_services/route/controller.service';
|
|
2
|
+
/**
|
|
3
|
+
* OAuth2 Controller implementation
|
|
4
|
+
*
|
|
5
|
+
* This controller handles OAuth2 specific endpoints and authentication flows
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const oauth2Controller = DyNTS_OAuth2_Controller.getInstance();
|
|
9
|
+
* oauth2Controller.setupEndpoints();
|
|
10
|
+
*/
|
|
11
|
+
export declare class DyNTS_OAuth2_Controller extends DyNTS_Controller {
|
|
12
|
+
static getInstance(): DyNTS_OAuth2_Controller;
|
|
13
|
+
private readonly authService;
|
|
14
|
+
private readonly controlService;
|
|
15
|
+
setupEndpoints(): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=oauth2.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth2.controller.d.ts","sourceRoot":"","sources":["../../../../src/_modules/oauth2/_routes/oauth2.controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAK/E;;;;;;;;GAQG;AACH,qBAAa,uBAAwB,SAAQ,gBAAgB;IAC3D,MAAM,CAAC,WAAW,IAAI,uBAAuB;IAI7C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoE;IAChG,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA0E;IAEzG,cAAc,IAAI,IAAI;CA0EvB"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DyNTS_OAuth2_Controller = void 0;
|
|
4
|
+
const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
|
|
5
|
+
const controller_service_1 = require("../../../_services/route/controller.service");
|
|
6
|
+
const endpoint_params_control_model_1 = require("../../../_models/control-models/endpoint-params.control-model");
|
|
7
|
+
const oauth2_auth_service_1 = require("../_services/oauth2.auth-service");
|
|
8
|
+
const oauth2_control_service_1 = require("../_services/oauth2.control-service");
|
|
9
|
+
/**
|
|
10
|
+
* OAuth2 Controller implementation
|
|
11
|
+
*
|
|
12
|
+
* This controller handles OAuth2 specific endpoints and authentication flows
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const oauth2Controller = DyNTS_OAuth2_Controller.getInstance();
|
|
16
|
+
* oauth2Controller.setupEndpoints();
|
|
17
|
+
*/
|
|
18
|
+
class DyNTS_OAuth2_Controller extends controller_service_1.DyNTS_Controller {
|
|
19
|
+
static getInstance() {
|
|
20
|
+
return DyNTS_OAuth2_Controller.getSingletonInstance();
|
|
21
|
+
}
|
|
22
|
+
authService = oauth2_auth_service_1.DyNTS_OAuth2_AuthService.getInstance();
|
|
23
|
+
controlService = oauth2_control_service_1.DyNTS_OAuth2_ControlService.getInstance();
|
|
24
|
+
setupEndpoints() {
|
|
25
|
+
this.endpoints = [
|
|
26
|
+
new endpoint_params_control_model_1.DyNTS_Endpoint_Params({
|
|
27
|
+
name: 'authorize',
|
|
28
|
+
type: fsm_dynamo_1.DyFM_HttpCallType.get,
|
|
29
|
+
endpoint: '/oauth2/authorize',
|
|
30
|
+
tasks: [
|
|
31
|
+
async (req, res) => {
|
|
32
|
+
// TODO: Implement OAuth2 authorization endpoint
|
|
33
|
+
// 1. Validate client_id and redirect_uri
|
|
34
|
+
// 2. Check if user is already authenticated
|
|
35
|
+
// 3. If not authenticated, redirect to login page
|
|
36
|
+
// 4. If authenticated, show consent page
|
|
37
|
+
// 5. Handle user consent
|
|
38
|
+
// 6. Generate authorization code or access token
|
|
39
|
+
// 7. Redirect back to client with code/token
|
|
40
|
+
await this.controlService.handleAuthorizationRequest(req, res);
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
}),
|
|
44
|
+
new endpoint_params_control_model_1.DyNTS_Endpoint_Params({
|
|
45
|
+
name: 'token',
|
|
46
|
+
type: fsm_dynamo_1.DyFM_HttpCallType.post,
|
|
47
|
+
endpoint: '/oauth2/token',
|
|
48
|
+
tasks: [
|
|
49
|
+
async (req, res) => {
|
|
50
|
+
// TODO: Implement OAuth2 token endpoint
|
|
51
|
+
// 1. Validate client credentials
|
|
52
|
+
// 2. Handle different grant types:
|
|
53
|
+
// - authorization_code
|
|
54
|
+
// - refresh_token
|
|
55
|
+
// - client_credentials
|
|
56
|
+
// - password
|
|
57
|
+
// 3. Generate appropriate tokens
|
|
58
|
+
// 4. Return token response
|
|
59
|
+
await this.controlService.handleTokenRequest(req, res);
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
}),
|
|
63
|
+
new endpoint_params_control_model_1.DyNTS_Endpoint_Params({
|
|
64
|
+
name: 'userinfo',
|
|
65
|
+
type: fsm_dynamo_1.DyFM_HttpCallType.get,
|
|
66
|
+
endpoint: '/oauth2/userinfo',
|
|
67
|
+
preProcesses: [this.authService.authenticate_token],
|
|
68
|
+
tasks: [
|
|
69
|
+
async (req, res) => {
|
|
70
|
+
// TODO: Implement OAuth2 userinfo endpoint
|
|
71
|
+
// 1. Extract user information from token
|
|
72
|
+
// 2. Validate token scope
|
|
73
|
+
// 3. Return user information based on scope
|
|
74
|
+
await this.controlService.handleUserInfoRequest(req, res);
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
}),
|
|
78
|
+
new endpoint_params_control_model_1.DyNTS_Endpoint_Params({
|
|
79
|
+
name: 'revoke',
|
|
80
|
+
type: fsm_dynamo_1.DyFM_HttpCallType.post,
|
|
81
|
+
endpoint: '/oauth2/revoke',
|
|
82
|
+
preProcesses: [this.authService.authenticate_token],
|
|
83
|
+
tasks: [
|
|
84
|
+
async (req, res) => {
|
|
85
|
+
// TODO: Implement OAuth2 token revocation endpoint
|
|
86
|
+
// 1. Validate token
|
|
87
|
+
// 2. Revoke token and any associated refresh tokens
|
|
88
|
+
// 3. Clear token from storage/cache
|
|
89
|
+
await this.controlService.handleTokenRevocation(req, res);
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
}),
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.DyNTS_OAuth2_Controller = DyNTS_OAuth2_Controller;
|
|
97
|
+
//# sourceMappingURL=oauth2.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth2.controller.js","sourceRoot":"","sources":["../../../../src/_modules/oauth2/_routes/oauth2.controller.ts"],"names":[],"mappings":";;;AACA,sDAA0D;AAC1D,oFAA+E;AAC/E,iHAAsG;AACtG,0EAA4E;AAC5E,gFAAkF;AAElF;;;;;;;;GAQG;AACH,MAAa,uBAAwB,SAAQ,qCAAgB;IAC3D,MAAM,CAAC,WAAW;QAChB,OAAO,uBAAuB,CAAC,oBAAoB,EAAE,CAAC;IACxD,CAAC;IAEgB,WAAW,GAA6B,8CAAwB,CAAC,WAAW,EAAE,CAAC;IAC/E,cAAc,GAAgC,oDAA2B,CAAC,WAAW,EAAE,CAAC;IAEzG,cAAc;QACZ,IAAI,CAAC,SAAS,GAAG;YACf,IAAI,qDAAqB,CAAC;gBACxB,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE,8BAAiB,CAAC,GAAG;gBAC3B,QAAQ,EAAE,mBAAmB;gBAC7B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gBACd,IAAI,EAAE,8BAAiB,CAAC,IAAI;gBAC5B,QAAQ,EAAE,gBAAgB;gBAC1B,YAAY,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC;gBACnD,KAAK,EAAE;oBACL,KAAK,EAAE,GAAY,EAAE,GAAa,EAAiB,EAAE;wBACnD,mDAAmD;wBACnD,oBAAoB;wBACpB,oDAAoD;wBACpD,oCAAoC;wBACpC,MAAM,IAAI,CAAC,cAAc,CAAC,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;oBAC5D,CAAC;iBACF;aACF,CAAC;SACH,CAAC;IACJ,CAAC;CACF;AAlFD,0DAkFC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
import { DyNTS_AuthService } from '../../../_services/core/auth.service';
|
|
3
|
+
/**
|
|
4
|
+
* OAuth2 Authentication Service implementation
|
|
5
|
+
*
|
|
6
|
+
* This service handles OAuth2 specific authentication flows and token management
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const authService = DyNTS_OAuth2_AuthService.getInstance();
|
|
10
|
+
* await authService.authenticate_token(req, res);
|
|
11
|
+
*/
|
|
12
|
+
export declare class DyNTS_OAuth2_AuthService extends DyNTS_AuthService {
|
|
13
|
+
static getInstance(): DyNTS_OAuth2_AuthService;
|
|
14
|
+
private readonly controlService;
|
|
15
|
+
readonly authenticate_token: (req: Request, res: Response) => Promise<void>;
|
|
16
|
+
readonly authenticate_tokenSelf: (req: Request, res: Response) => Promise<void>;
|
|
17
|
+
readonly authenticate_tokenPerm_accUsageData: (req: Request, res: Response) => Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Gets the issuer (user ID) from the OAuth2 token in the request
|
|
20
|
+
* @param req Express Request object
|
|
21
|
+
* @returns The issuer ID from the token
|
|
22
|
+
*/
|
|
23
|
+
getIssuerFromRequest(req: Request): string;
|
|
24
|
+
/**
|
|
25
|
+
* Gets the username from the OAuth2 token in the request
|
|
26
|
+
* @param req Express Request object
|
|
27
|
+
* @returns The username from the token
|
|
28
|
+
*/
|
|
29
|
+
getUsernameFromRequest(req: Request): string;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=oauth2.auth-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth2.auth-service.d.ts","sourceRoot":"","sources":["../../../../src/_modules/oauth2/_services/oauth2.auth-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAIzE;;;;;;;;GAQG;AACH,qBAAa,wBAAyB,SAAQ,iBAAiB;IAC7D,MAAM,CAAC,WAAW,IAAI,wBAAwB;IAI9C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA0E;IAEzG,QAAQ,CAAC,kBAAkB,QAAe,OAAO,OAAO,QAAQ,KAAG,QAAQ,IAAI,CAAC,CA6C9E;IAEF,QAAQ,CAAC,sBAAsB,QAAe,OAAO,OAAO,QAAQ,KAAG,QAAQ,IAAI,CAAC,CA0DlF;IAEF,QAAQ,CAAC,mCAAmC,QAAe,OAAO,OAAO,QAAQ,KAAG,QAAQ,IAAI,CAAC,CAyD/F;IAEF;;;;OAIG;IACH,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM;IAgB1C;;;;OAIG;IACH,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM;CAiB7C"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DyNTS_OAuth2_AuthService = void 0;
|
|
4
|
+
const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
|
|
5
|
+
const auth_service_1 = require("../../../_services/core/auth.service");
|
|
6
|
+
const global_settings_const_1 = require("../../../_collections/global-settings.const");
|
|
7
|
+
const oauth2_control_service_1 = require("./oauth2.control-service");
|
|
8
|
+
/**
|
|
9
|
+
* OAuth2 Authentication Service implementation
|
|
10
|
+
*
|
|
11
|
+
* This service handles OAuth2 specific authentication flows and token management
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const authService = DyNTS_OAuth2_AuthService.getInstance();
|
|
15
|
+
* await authService.authenticate_token(req, res);
|
|
16
|
+
*/
|
|
17
|
+
class DyNTS_OAuth2_AuthService extends auth_service_1.DyNTS_AuthService {
|
|
18
|
+
static getInstance() {
|
|
19
|
+
return DyNTS_OAuth2_AuthService.getSingletonInstance();
|
|
20
|
+
}
|
|
21
|
+
controlService = oauth2_control_service_1.DyNTS_OAuth2_ControlService.getInstance();
|
|
22
|
+
authenticate_token = async (req, res) => {
|
|
23
|
+
try {
|
|
24
|
+
const token = this.getTokenFromRequest(req);
|
|
25
|
+
// Validate token format
|
|
26
|
+
if (!token?.startsWith('Bearer ')) {
|
|
27
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
28
|
+
status: 401,
|
|
29
|
+
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-OA2-AT1`,
|
|
30
|
+
addECToUserMsg: true,
|
|
31
|
+
message: 'Invalid token format',
|
|
32
|
+
userMessage: this.defaultErrorUserMsg,
|
|
33
|
+
issuerService: this.serviceName,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const accessToken = token.substring(7); // Remove 'Bearer ' prefix
|
|
37
|
+
// Validate token against stored tokens
|
|
38
|
+
const tokenData = this.controlService.getAccessTokenData(accessToken);
|
|
39
|
+
if (!tokenData || tokenData.expiresAt < Date.now()) {
|
|
40
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
41
|
+
status: 401,
|
|
42
|
+
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-OA2-AT2`,
|
|
43
|
+
addECToUserMsg: true,
|
|
44
|
+
message: 'Invalid or expired token',
|
|
45
|
+
userMessage: this.defaultErrorUserMsg,
|
|
46
|
+
issuerService: this.serviceName,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// Set token in response header
|
|
50
|
+
res.setHeader('authorization', `Bearer ${accessToken}`);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
fsm_dynamo_1.DyFM_Log.error('OAuth2 token authentication failed', error);
|
|
54
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
55
|
+
status: 401,
|
|
56
|
+
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-OA2-AT0`,
|
|
57
|
+
addECToUserMsg: true,
|
|
58
|
+
message: 'OAuth2 token authentication failed',
|
|
59
|
+
userMessage: this.defaultErrorUserMsg,
|
|
60
|
+
issuerService: this.serviceName,
|
|
61
|
+
error
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
authenticate_tokenSelf = async (req, res) => {
|
|
66
|
+
try {
|
|
67
|
+
const token = this.getTokenFromRequest(req);
|
|
68
|
+
// Validate token format
|
|
69
|
+
if (!token || !token.startsWith('Bearer ')) {
|
|
70
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
71
|
+
status: 401,
|
|
72
|
+
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-OA2-ATS1`,
|
|
73
|
+
addECToUserMsg: true,
|
|
74
|
+
message: 'Invalid token format',
|
|
75
|
+
userMessage: this.defaultErrorUserMsg,
|
|
76
|
+
issuerService: this.serviceName,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const accessToken = token.substring(7); // Remove 'Bearer ' prefix
|
|
80
|
+
// Validate token against stored tokens
|
|
81
|
+
const tokenData = this.controlService.getAccessTokenData(accessToken);
|
|
82
|
+
if (!tokenData || tokenData.expiresAt < Date.now()) {
|
|
83
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
84
|
+
status: 401,
|
|
85
|
+
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-OA2-ATS2`,
|
|
86
|
+
addECToUserMsg: true,
|
|
87
|
+
message: 'Invalid or expired token',
|
|
88
|
+
userMessage: this.defaultErrorUserMsg,
|
|
89
|
+
issuerService: this.serviceName,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
// For self-token validation, ensure the token is associated with the requesting user
|
|
93
|
+
const issuer = this.getIssuerFromRequest(req);
|
|
94
|
+
if (!issuer || issuer !== tokenData.clientId) {
|
|
95
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
96
|
+
status: 403,
|
|
97
|
+
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-OA2-ATS3`,
|
|
98
|
+
addECToUserMsg: true,
|
|
99
|
+
message: 'Token not associated with requesting user',
|
|
100
|
+
userMessage: this.defaultErrorUserMsg,
|
|
101
|
+
issuerService: this.serviceName,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
// Set token in response header
|
|
105
|
+
res.setHeader('authorization', `Bearer ${accessToken}`);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
fsm_dynamo_1.DyFM_Log.error('OAuth2 self-token authentication failed', error);
|
|
109
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
110
|
+
status: 401,
|
|
111
|
+
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-OA2-ATS0`,
|
|
112
|
+
addECToUserMsg: true,
|
|
113
|
+
message: 'OAuth2 self-token authentication failed',
|
|
114
|
+
userMessage: this.defaultErrorUserMsg,
|
|
115
|
+
issuerService: this.serviceName,
|
|
116
|
+
error
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
authenticate_tokenPerm_accUsageData = async (req, res) => {
|
|
121
|
+
try {
|
|
122
|
+
const token = this.getTokenFromRequest(req);
|
|
123
|
+
// Validate token format
|
|
124
|
+
if (!token || !token.startsWith('Bearer ')) {
|
|
125
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
126
|
+
status: 401,
|
|
127
|
+
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-OA2-ATU1`,
|
|
128
|
+
addECToUserMsg: true,
|
|
129
|
+
message: 'Invalid token format',
|
|
130
|
+
userMessage: this.defaultErrorUserMsg,
|
|
131
|
+
issuerService: this.serviceName,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const accessToken = token.substring(7); // Remove 'Bearer ' prefix
|
|
135
|
+
// Validate token against stored tokens
|
|
136
|
+
const tokenData = this.controlService.getAccessTokenData(accessToken);
|
|
137
|
+
if (!tokenData || tokenData.expiresAt < Date.now()) {
|
|
138
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
139
|
+
status: 401,
|
|
140
|
+
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-OA2-ATU2`,
|
|
141
|
+
addECToUserMsg: true,
|
|
142
|
+
message: 'Invalid or expired token',
|
|
143
|
+
userMessage: this.defaultErrorUserMsg,
|
|
144
|
+
issuerService: this.serviceName,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
// Check if token has usage data permission
|
|
148
|
+
if (!tokenData.scope.includes('usage_data')) {
|
|
149
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
150
|
+
status: 403,
|
|
151
|
+
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-OA2-ATU3`,
|
|
152
|
+
addECToUserMsg: true,
|
|
153
|
+
message: 'Token does not have usage data permission',
|
|
154
|
+
userMessage: this.defaultErrorUserMsg,
|
|
155
|
+
issuerService: this.serviceName,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
// Set token in response header
|
|
159
|
+
res.setHeader('authorization', `Bearer ${accessToken}`);
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
fsm_dynamo_1.DyFM_Log.error('OAuth2 usage data permission check failed', error);
|
|
163
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
164
|
+
status: 401,
|
|
165
|
+
errorCode: `${global_settings_const_1.DyNTS_global_settings.systemShortCodeName}|DyNTS-OA2-ATU0`,
|
|
166
|
+
addECToUserMsg: true,
|
|
167
|
+
message: 'OAuth2 usage data permission check failed',
|
|
168
|
+
userMessage: this.defaultErrorUserMsg,
|
|
169
|
+
issuerService: this.serviceName,
|
|
170
|
+
error
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Gets the issuer (user ID) from the OAuth2 token in the request
|
|
176
|
+
* @param req Express Request object
|
|
177
|
+
* @returns The issuer ID from the token
|
|
178
|
+
*/
|
|
179
|
+
getIssuerFromRequest(req) {
|
|
180
|
+
try {
|
|
181
|
+
const token = this.getTokenFromRequest(req);
|
|
182
|
+
if (!token || !token.startsWith('Bearer ')) {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
const accessToken = token.substring(7); // Remove 'Bearer ' prefix
|
|
186
|
+
const tokenData = this.controlService.getAccessTokenData(accessToken);
|
|
187
|
+
return tokenData?.clientId;
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Gets the username from the OAuth2 token in the request
|
|
195
|
+
* @param req Express Request object
|
|
196
|
+
* @returns The username from the token
|
|
197
|
+
*/
|
|
198
|
+
getUsernameFromRequest(req) {
|
|
199
|
+
try {
|
|
200
|
+
const token = this.getTokenFromRequest(req);
|
|
201
|
+
if (!token || !token.startsWith('Bearer ')) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
const accessToken = token.substring(7); // Remove 'Bearer ' prefix
|
|
205
|
+
const tokenData = this.controlService.getAccessTokenData(accessToken);
|
|
206
|
+
// TODO: Implement user information retrieval from database/storage
|
|
207
|
+
// For now, return the client ID as username
|
|
208
|
+
return tokenData?.clientId;
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.DyNTS_OAuth2_AuthService = DyNTS_OAuth2_AuthService;
|
|
216
|
+
//# sourceMappingURL=oauth2.auth-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth2.auth-service.js","sourceRoot":"","sources":["../../../../src/_modules/oauth2/_services/oauth2.auth-service.ts"],"names":[],"mappings":";;;AACA,sDAA6D;AAC7D,uEAAyE;AACzE,uFAAoF;AACpF,qEAAuE;AAEvE;;;;;;;;GAQG;AACH,MAAa,wBAAyB,SAAQ,gCAAiB;IAC7D,MAAM,CAAC,WAAW;QAChB,OAAO,wBAAwB,CAAC,oBAAoB,EAAE,CAAC;IACzD,CAAC;IAEgB,cAAc,GAAgC,oDAA2B,CAAC,WAAW,EAAE,CAAC;IAEhG,kBAAkB,GAAG,KAAK,EAAE,GAAY,EAAE,GAAa,EAAiB,EAAE;QACjF,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAE5C,wBAAwB;YACxB,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;gBAClC,MAAM,IAAI,uBAAU,CAAC;oBACnB,MAAM,EAAE,GAAG;oBACX,SAAS,EAAE,GAAG,6CAAqB,CAAC,mBAAmB,gBAAgB;oBACvE,cAAc,EAAE,IAAI;oBACpB,OAAO,EAAE,sBAAsB;oBAC/B,WAAW,EAAE,IAAI,CAAC,mBAAmB;oBACrC,aAAa,EAAE,IAAI,CAAC,WAAW;iBAChC,CAAC,CAAC;YACL,CAAC;YAED,MAAM,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,0BAA0B;YAElE,uCAAuC;YACvC,MAAM,SAAS,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C,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAC5C,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC3C,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,MAAM,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,0BAA0B;YAClE,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;YAEtE,OAAO,SAAS,EAAE,QAAQ,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,sBAAsB,CAAC,GAAY;QACjC,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAC5C,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC3C,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,MAAM,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,0BAA0B;YAClE,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;YAEtE,mEAAmE;YACnE,4CAA4C;YAC5C,OAAO,SAAS,EAAE,QAAQ,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AAxND,4DAwNC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
import { DyNTS_SingletonService } from '../../../_services/base/singleton.service';
|
|
3
|
+
/**
|
|
4
|
+
* OAuth2 Control Service implementation
|
|
5
|
+
*
|
|
6
|
+
* This service handles OAuth2 specific business logic and token management
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const oauth2Service = DyNTS_OAuth2_ControlService.getInstance();
|
|
10
|
+
* await oauth2Service.handleAuthorizationRequest(req, res);
|
|
11
|
+
*/
|
|
12
|
+
export declare class DyNTS_OAuth2_ControlService extends DyNTS_SingletonService {
|
|
13
|
+
static getInstance(): DyNTS_OAuth2_ControlService;
|
|
14
|
+
readonly serviceName: string;
|
|
15
|
+
private readonly authService;
|
|
16
|
+
private readonly authorizationCodes;
|
|
17
|
+
private readonly accessTokens;
|
|
18
|
+
private readonly refreshTokens;
|
|
19
|
+
private readonly clients;
|
|
20
|
+
private readonly users;
|
|
21
|
+
/**
|
|
22
|
+
* Handles the OAuth2 authorization request
|
|
23
|
+
* @param req Express Request object
|
|
24
|
+
* @param res Express Response object
|
|
25
|
+
*/
|
|
26
|
+
handleAuthorizationRequest(req: Request, res: Response): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Validates if the client is registered and active
|
|
29
|
+
* @param clientId The client ID to validate
|
|
30
|
+
* @returns true if the client is valid
|
|
31
|
+
*/
|
|
32
|
+
private isValidClient;
|
|
33
|
+
/**
|
|
34
|
+
* Validates if the redirect URI is registered for the client
|
|
35
|
+
* @param clientId The client ID
|
|
36
|
+
* @param redirectUri The redirect URI to validate
|
|
37
|
+
* @returns true if the redirect URI is valid
|
|
38
|
+
*/
|
|
39
|
+
private isValidRedirectUri;
|
|
40
|
+
/**
|
|
41
|
+
* Validates if the scope is allowed for the client
|
|
42
|
+
* @param clientId The client ID
|
|
43
|
+
* @param scope The scope to validate
|
|
44
|
+
* @returns true if the scope is valid
|
|
45
|
+
*/
|
|
46
|
+
private isValidScope;
|
|
47
|
+
/**
|
|
48
|
+
* Handles the OAuth2 token request
|
|
49
|
+
* @param req Express Request object
|
|
50
|
+
* @param res Express Response object
|
|
51
|
+
*/
|
|
52
|
+
handleTokenRequest(req: Request, res: Response): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Validates client credentials
|
|
55
|
+
* @param clientId The client ID
|
|
56
|
+
* @param clientSecret The client secret
|
|
57
|
+
* @returns true if the credentials are valid
|
|
58
|
+
*/
|
|
59
|
+
private validateClientCredentials;
|
|
60
|
+
/**
|
|
61
|
+
* Handles the OAuth2 userinfo request
|
|
62
|
+
* @param req Express Request object
|
|
63
|
+
* @param res Express Response object
|
|
64
|
+
*/
|
|
65
|
+
handleUserInfoRequest(req: Request, res: Response): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Gets user information from the token
|
|
68
|
+
* @param token The access token
|
|
69
|
+
* @returns The user information object
|
|
70
|
+
*/
|
|
71
|
+
private getUserInfoFromToken;
|
|
72
|
+
/**
|
|
73
|
+
* Handles the OAuth2 token revocation request
|
|
74
|
+
* @param req Express Request object
|
|
75
|
+
* @param res Express Response object
|
|
76
|
+
*/
|
|
77
|
+
handleTokenRevocation(req: Request, res: Response): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Generates an authorization code
|
|
80
|
+
* @param clientId The client ID
|
|
81
|
+
* @param scope The requested scope
|
|
82
|
+
* @returns The generated authorization code
|
|
83
|
+
*/
|
|
84
|
+
private generateAuthorizationCode;
|
|
85
|
+
/**
|
|
86
|
+
* Generates an access token
|
|
87
|
+
* @param clientId The client ID
|
|
88
|
+
* @param scope The requested scope
|
|
89
|
+
* @returns The generated access token
|
|
90
|
+
*/
|
|
91
|
+
private generateAccessToken;
|
|
92
|
+
/**
|
|
93
|
+
* Generates a refresh token
|
|
94
|
+
* @param clientId The client ID
|
|
95
|
+
* @returns The generated refresh token
|
|
96
|
+
*/
|
|
97
|
+
private generateRefreshToken;
|
|
98
|
+
/**
|
|
99
|
+
* Gets the access token data
|
|
100
|
+
* @param token The access token
|
|
101
|
+
* @returns The access token data or undefined if not found
|
|
102
|
+
*/
|
|
103
|
+
getAccessTokenData(token: string): {
|
|
104
|
+
clientId: string;
|
|
105
|
+
scope: string;
|
|
106
|
+
expiresAt: number;
|
|
107
|
+
} | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* Registers a new OAuth2 client
|
|
110
|
+
* @param clientId The client ID
|
|
111
|
+
* @param clientSecret The client secret
|
|
112
|
+
* @param redirectUris The allowed redirect URIs
|
|
113
|
+
* @param allowedScopes The allowed scopes
|
|
114
|
+
* @returns true if the client was registered successfully
|
|
115
|
+
*/
|
|
116
|
+
registerClient(clientId: string, clientSecret: string, redirectUris: string[], allowedScopes: string[]): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Authenticates a user with username and password
|
|
119
|
+
* @param username The username
|
|
120
|
+
* @param password The password
|
|
121
|
+
* @returns The user's scopes if authentication is successful, undefined otherwise
|
|
122
|
+
*/
|
|
123
|
+
private authenticateUser;
|
|
124
|
+
/**
|
|
125
|
+
* Registers a new user
|
|
126
|
+
* @param username The username
|
|
127
|
+
* @param password The password
|
|
128
|
+
* @param scopes The user's scopes
|
|
129
|
+
* @returns true if the user was registered successfully
|
|
130
|
+
*/
|
|
131
|
+
registerUser(username: string, password: string, scopes: string[]): boolean;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=oauth2.control-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth2.control-service.d.ts","sourceRoot":"","sources":["../../../../src/_modules/oauth2/_services/oauth2.control-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AAKnF;;;;;;;;GAQG;AACH,qBAAa,2BAA4B,SAAQ,sBAAsB;IACrE,MAAM,CAAC,WAAW,IAAI,2BAA2B;IAIjD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA0B;IAEtD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoE;IAChG,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAkF;IACrH,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkF;IAC/G,OAAO,CAAC,QAAQ,C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