eservices-back-core 1.0.92 → 1.0.95
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/.env +5 -0
- package/dist/Server.d.ts +1 -5
- package/dist/Server.d.ts.map +1 -1
- package/dist/Server.js +15 -38
- package/dist/Server.js.map +1 -1
- package/dist/app.js +26 -12
- package/dist/app.js.map +1 -1
- package/package.json +2 -1
- package/src/Server.ts +17 -39
- package/src/app.ts +38 -23
- package/tsconfig.json +0 -1
- package/src/middleware/cors-middleware.js +0 -13
- package/src/middleware/user-middleware.js +0 -17
package/.env
ADDED
package/dist/Server.d.ts
CHANGED
|
@@ -12,10 +12,6 @@ interface ServerOptions {
|
|
|
12
12
|
staticFolderDir?: string;
|
|
13
13
|
usingContextFile?: string;
|
|
14
14
|
}
|
|
15
|
-
export
|
|
16
|
-
app: Express;
|
|
17
|
-
options: ServerOptions;
|
|
18
|
-
constructor(options: ServerOptions);
|
|
19
|
-
}
|
|
15
|
+
export declare function initServer(app: Express, options: ServerOptions): void;
|
|
20
16
|
export {};
|
|
21
17
|
//# sourceMappingURL=Server.d.ts.map
|
package/dist/Server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Server.d.ts","sourceRoot":"","sources":["../src/Server.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"Server.d.ts","sourceRoot":"","sources":["../src/Server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAChC,OAAO,EAAC,YAAY,EAAO,MAAM,wBAAwB,CAAC;AAG1D,UAAU,aAAa;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAG,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,YAAY,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,QAiB9D"}
|
package/dist/Server.js
CHANGED
|
@@ -1,48 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
|
|
6
|
+
exports.initServer = void 0;
|
|
16
7
|
const express_openid_connect_1 = require("express-openid-connect");
|
|
17
8
|
const cors_1 = __importDefault(require("cors"));
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const userId = Number(user['AppRegister.Claim.PersonId']);
|
|
31
|
-
res.send(`hello <b>${req.oidc.user.name}</b>, ${req.oidc.user.sub}, ${userId}`);
|
|
32
|
-
});
|
|
33
|
-
app.get("/main*", (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
res.sendFile(path_1.default.join(options.frontendDir, `${options.type}-main.html`));
|
|
35
|
-
}));
|
|
36
|
-
app.use((err, req, res, next) => {
|
|
37
|
-
console.log(err);
|
|
38
|
-
res.status(500).json({
|
|
39
|
-
success: false,
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
app.listen(options.port, () => {
|
|
43
|
-
console.log(`Server start on ${options.port}`);
|
|
9
|
+
function initServer(app, options) {
|
|
10
|
+
app.use((0, cors_1.default)());
|
|
11
|
+
app.use((0, express_openid_connect_1.auth)(options.oidc));
|
|
12
|
+
app.get("/test-page", (req, res) => {
|
|
13
|
+
const user = req.oidc.user;
|
|
14
|
+
const userId = Number(user['AppRegister.Claim.PersonId']);
|
|
15
|
+
res.send(`hello <b>${req.oidc.user.name}</b>, ${req.oidc.user.sub}, ${userId}`);
|
|
16
|
+
});
|
|
17
|
+
app.use((err, req, res, next) => {
|
|
18
|
+
console.log(err);
|
|
19
|
+
res.status(500).json({
|
|
20
|
+
success: false,
|
|
44
21
|
});
|
|
45
|
-
}
|
|
22
|
+
});
|
|
46
23
|
}
|
|
47
|
-
exports.
|
|
24
|
+
exports.initServer = initServer;
|
|
48
25
|
//# sourceMappingURL=Server.js.map
|
package/dist/Server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Server.js","sourceRoot":"","sources":["../src/Server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Server.js","sourceRoot":"","sources":["../src/Server.ts"],"names":[],"mappings":";;;;;;AACA,mEAA0D;AAC1D,gDAAuB;AAevB,SAAgB,UAAU,CAAC,GAAY,EAAE,OAAsB;IAC9D,GAAG,CAAC,GAAG,CAAC,IAAA,cAAI,GAAE,CAAC,CAAC;IAChB,GAAG,CAAC,GAAG,CAAC,IAAA,6BAAI,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5B,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAClC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;QAC3B,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC,CAAC;QAC1D,GAAG,CAAC,IAAI,CAAC,YAAY,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,SAAS,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,MAAM,EAAE,CAAC,CAAC;IACjF,CAAC,CAAC,CAAA;IAGF,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC/B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YACpB,OAAO,EAAE,KAAK;SACd,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AAEJ,CAAC;AAjBD,gCAiBC"}
|
package/dist/app.js
CHANGED
|
@@ -3,29 +3,43 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const Server_1 =
|
|
6
|
+
const Server_1 = require("./Server");
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
|
|
8
|
+
const express_1 = __importDefault(require("express"));
|
|
9
|
+
const projectDir = path_1.default.join(__dirname, '..');
|
|
10
|
+
const dotenv_1 = require("dotenv");
|
|
11
|
+
(0, dotenv_1.config)({
|
|
12
|
+
path: path_1.default.join(__dirname, '../.env')
|
|
13
|
+
});
|
|
14
|
+
const app = (0, express_1.default)();
|
|
15
|
+
const options = {
|
|
9
16
|
baseUrl: process.env.BASE_URL,
|
|
10
|
-
port: Number(process.env.PORT),
|
|
11
17
|
type: process.env.TYPE,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
port: Number(process.env.PORT),
|
|
19
|
+
frontendDir: path_1.default.join(projectDir, '..', 'frontend'),
|
|
20
|
+
staticFolderDir: path_1.default.join(projectDir, 'static'),
|
|
21
|
+
projectDir: projectDir,
|
|
22
|
+
apiUrl: process.env.API_URL,
|
|
23
|
+
usingContextFile: path_1.default.join(projectDir, 'using-context.json'),
|
|
17
24
|
oidc: {
|
|
18
25
|
issuerBaseURL: process.env.OIDC_ISSUE,
|
|
19
26
|
baseURL: process.env.BASE_URL,
|
|
20
|
-
clientID: process.env.OIDC_CLIENT_ID,
|
|
21
27
|
secret: 'aaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccce',
|
|
22
|
-
|
|
28
|
+
clientID: 'AppRegister.WebServer.Public.Client',
|
|
23
29
|
idpLogout: true,
|
|
30
|
+
routes: {
|
|
31
|
+
postLogoutRedirect: '/auth'
|
|
32
|
+
},
|
|
33
|
+
clientSecret: '64D5FAA8-97FB-403F-898C-5D30718AB830',
|
|
24
34
|
authorizationParams: {
|
|
25
35
|
response_type: 'code',
|
|
26
|
-
audience:
|
|
36
|
+
audience: process.env.API_URL,
|
|
27
37
|
scope: 'openid profile email',
|
|
28
38
|
},
|
|
29
|
-
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
(0, Server_1.initServer)(app, options);
|
|
42
|
+
app.listen(options.port, () => {
|
|
43
|
+
console.log(`Running on ${options.port}`);
|
|
30
44
|
});
|
|
31
45
|
//# sourceMappingURL=app.js.map
|
package/dist/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../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,mBAAU,EAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACzB,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE;IAC1B,OAAO,CAAC,GAAG,CAAC,cAAc,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;AAC7C,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eservices-back-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.95",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/Server.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"body-parser": "^1.20.0",
|
|
17
17
|
"cors": "^2.8.5",
|
|
18
|
+
"dotenv": "^16.0.1",
|
|
18
19
|
"express": "^4.18.1",
|
|
19
20
|
"express-openid-connect": "^2.7.2",
|
|
20
21
|
"log4js": "^6.5.2",
|
package/src/Server.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {Express} from "express";
|
|
2
2
|
import {ConfigParams, auth} from "express-openid-connect";
|
|
3
|
-
|
|
4
3
|
import cors from 'cors'
|
|
5
|
-
import path from "path";
|
|
6
4
|
|
|
7
5
|
interface ServerOptions{
|
|
8
6
|
port: number,
|
|
@@ -17,41 +15,21 @@ interface ServerOptions{
|
|
|
17
15
|
usingContextFile?: string,
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
app
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
app.get("/test-page", (req, res) => {
|
|
35
|
-
const user = req.oidc.user;
|
|
36
|
-
const userId = Number(user['AppRegister.Claim.PersonId']);
|
|
37
|
-
res.send(`hello <b>${req.oidc.user.name}</b>, ${req.oidc.user.sub}, ${userId}`);
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
app.get("/main*",async (req, res) => {
|
|
41
|
-
res.sendFile(path.join( options.frontendDir, `${options.type}-main.html` ));
|
|
42
|
-
})
|
|
43
|
-
app.use((err, req, res, next) => {
|
|
44
|
-
console.log(err);
|
|
45
|
-
res.status(500).json({
|
|
46
|
-
success: false,
|
|
47
|
-
});
|
|
18
|
+
export function initServer(app: Express, options: ServerOptions) {
|
|
19
|
+
app.use(cors());
|
|
20
|
+
app.use(auth(options.oidc));
|
|
21
|
+
app.get("/test-page", (req, res) => {
|
|
22
|
+
const user = req.oidc.user;
|
|
23
|
+
const userId = Number(user['AppRegister.Claim.PersonId']);
|
|
24
|
+
res.send(`hello <b>${req.oidc.user.name}</b>, ${req.oidc.user.sub}, ${userId}`);
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
app.use((err, req, res, next) => {
|
|
29
|
+
console.log(err);
|
|
30
|
+
res.status(500).json({
|
|
31
|
+
success: false,
|
|
48
32
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
app.listen(options.port, () => {
|
|
52
|
-
console.log(`Server start on ${options.port}`);
|
|
53
|
-
})
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
33
|
+
});
|
|
34
|
+
|
|
57
35
|
}
|
package/src/app.ts
CHANGED
|
@@ -1,27 +1,42 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {initServer} from "./Server";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import express from "express";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
port: Number(process.env.PORT),
|
|
7
|
-
type: process.env.TYPE as 'front' | 'back',// process.env.TYPE,
|
|
8
|
-
apiUrl: 'https://sandbox.eservices.dev:15015',
|
|
9
|
-
projectDir: path.join(__dirname, '..'),
|
|
10
|
-
frontendDir: path.join(__dirname, '../..', 'frontend'),
|
|
11
|
-
staticFolderDir: path.join(__dirname, '..', 'static'),
|
|
12
|
-
usingContextFile: path.join(__dirname, '..', 'using-context.json'),
|
|
5
|
+
const projectDir = path.join(__dirname, '..');
|
|
6
|
+
import {config as configDotenv} from "dotenv";
|
|
13
7
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
configDotenv({
|
|
9
|
+
path: path.join(__dirname, '../.env')
|
|
10
|
+
})
|
|
11
|
+
const app = express();
|
|
12
|
+
|
|
13
|
+
const options = {
|
|
14
|
+
baseUrl: process.env.BASE_URL,
|
|
15
|
+
type: process.env.TYPE as ('front' | 'back'),
|
|
16
|
+
port: Number(process.env.PORT),
|
|
17
|
+
frontendDir: path.join(projectDir, '..', 'frontend'),
|
|
18
|
+
staticFolderDir: path.join(projectDir, 'static'),
|
|
19
|
+
projectDir: projectDir,
|
|
20
|
+
apiUrl: process.env.API_URL,
|
|
21
|
+
usingContextFile: path.join(projectDir, 'using-context.json'),
|
|
22
|
+
oidc: {
|
|
23
|
+
issuerBaseURL : process.env.OIDC_ISSUE,
|
|
24
|
+
baseURL : process.env.BASE_URL,
|
|
25
|
+
secret : 'aaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccce',
|
|
26
|
+
clientID : 'AppRegister.WebServer.Public.Client',
|
|
27
|
+
idpLogout : true,
|
|
28
|
+
routes: {
|
|
29
|
+
postLogoutRedirect: '/auth'
|
|
30
|
+
},
|
|
31
|
+
clientSecret : '64D5FAA8-97FB-403F-898C-5D30718AB830',
|
|
32
|
+
authorizationParams: {
|
|
33
|
+
response_type: 'code', // This requires you to provide a client secret
|
|
34
|
+
audience: process.env.API_URL,
|
|
35
|
+
scope: 'openid profile email',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
initServer(app, options);
|
|
40
|
+
app.listen(options.port, () => {
|
|
41
|
+
console.log(`Running on ${options.port}`)
|
|
27
42
|
})
|
package/tsconfig.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
module.exports = function corsMiddleware(req, res, next) {
|
|
2
|
-
const origin = req.headers.origin;
|
|
3
|
-
|
|
4
|
-
res.header("Access-Control-Allow-Origin", origin);
|
|
5
|
-
|
|
6
|
-
res.header("Access-Control-Allow-Headers", "Auth_old-Token,Authorization, Origin, X-Requested-With, content-type, Content-Type, Content-Type, content-type, Content_Type, Accept");
|
|
7
|
-
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
|
|
8
|
-
|
|
9
|
-
if (req.method === "OPTIONS") {
|
|
10
|
-
return res.status(200).end();
|
|
11
|
-
}
|
|
12
|
-
next();
|
|
13
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
module.exports = async (req, res, next) => {
|
|
3
|
-
|
|
4
|
-
try {
|
|
5
|
-
let accessToken = req.oidc.accessToken;
|
|
6
|
-
|
|
7
|
-
if (accessToken.isExpired()) {
|
|
8
|
-
accessToken = await accessToken.refresh();
|
|
9
|
-
}
|
|
10
|
-
req.__token = `${accessToken.token_type} ${accessToken.access_token}`;
|
|
11
|
-
req.userInfo = await req.oidc.fetchUserInfo();
|
|
12
|
-
|
|
13
|
-
next();
|
|
14
|
-
} catch (e) {
|
|
15
|
-
next(e);
|
|
16
|
-
}
|
|
17
|
-
}
|