eservices-back-core 1.0.91 → 1.0.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Server.d.ts +1 -5
- package/dist/Server.d.ts.map +1 -1
- package/dist/Server.js +15 -35
- package/dist/Server.js.map +1 -1
- package/package.json +1 -1
- package/src/Server.ts +17 -35
- package/tsconfig.json +1 -1
- package/src/app.ts +0 -27
- package/src/middleware/cors-middleware.js +0 -13
- package/src/middleware/user-middleware.js +0 -17
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,45 +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
|
-
});
|
|
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,
|
|
41
21
|
});
|
|
42
|
-
}
|
|
22
|
+
});
|
|
43
23
|
}
|
|
44
|
-
exports.
|
|
24
|
+
exports.initServer = initServer;
|
|
45
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/package.json
CHANGED
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,37 +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
|
-
|
|
52
|
-
|
|
33
|
+
});
|
|
34
|
+
|
|
53
35
|
}
|
package/tsconfig.json
CHANGED
package/src/app.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import Server from "./Server";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
new Server({
|
|
5
|
-
baseUrl: process.env.BASE_URL,
|
|
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'),
|
|
13
|
-
|
|
14
|
-
oidc: {
|
|
15
|
-
issuerBaseURL : process.env.OIDC_ISSUE,
|
|
16
|
-
baseURL : process.env.BASE_URL,
|
|
17
|
-
clientID : process.env.OIDC_CLIENT_ID,
|
|
18
|
-
secret : 'aaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccce',
|
|
19
|
-
clientSecret : process.env.OIDC_SECRET,
|
|
20
|
-
idpLogout : true,
|
|
21
|
-
authorizationParams: {
|
|
22
|
-
response_type: 'code', // This requires you to provide a client secret
|
|
23
|
-
audience: 'https://api.example.com/products',
|
|
24
|
-
scope: 'openid profile email',
|
|
25
|
-
},
|
|
26
|
-
}
|
|
27
|
-
})
|
|
@@ -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
|
-
}
|