@sassoftware/viya-serverjs 0.5.4 → 0.6.1-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/.env +14 -30
- package/.env.proxy +24 -0
- package/.env.server +20 -35
- package/Dockerfile +7 -7
- package/README.md +69 -37
- package/cli.js +2 -1
- package/lib/handlers/codeAuth.js +11 -9
- package/lib/handlers/getApp.js +5 -2
- package/lib/handlers/logon.js +4 -5
- package/lib/handlers/proxyMapUri.js +1 -1
- package/lib/handlers/setCookies.js +23 -12
- package/lib/iService.js +98 -234
- package/lib/index.js +29 -15
- package/lib/plugins/SASauth.js +2 -4
- package/lib/plugins/appCookie.js +3 -4
- package/lib/plugins/setContext.js +3 -1
- package/lib/plugins/setDefaultRoutes.js +33 -61
- package/lib/plugins/setupUserRoutes.js +11 -5
- package/lib/readCerts.js +38 -0
- package/package.json +14 -19
- package/public/help.html +1 -1
- package/public/index.html +302 -304
- package/public/indexold.html +356 -0
- package/server.js +10 -11
- package/src/handlers/codeAuth.js +10 -10
- package/src/handlers/getApp.js +4 -1
- package/src/handlers/logon.js +3 -4
- package/src/handlers/proxyMapUri.js +3 -3
- package/src/handlers/setCookies.js +8 -8
- package/src/iService.js +82 -173
- package/src/index.js +30 -17
- package/src/plugins/SASauth.js +2 -6
- package/src/plugins/appCookie.js +4 -5
- package/src/plugins/setContext.js +3 -2
- package/src/plugins/setDefaultRoutes.js +19 -25
- package/src/plugins/setupUserRoutes.js +6 -3
- package/src/readCerts.js +33 -0
- package/tls/viyatls.sh +3 -0
- package/mcpServer.js +0 -364
- package/public/auth.html +0 -24
- package/testca.js +0 -10
package/src/iService.js
CHANGED
|
@@ -27,16 +27,15 @@ let NodeCache = require("node-cache-promise");
|
|
|
27
27
|
let Vision = require('@hapi/vision');
|
|
28
28
|
let inert = require('@hapi/inert');
|
|
29
29
|
let selfsigned = require('selfsigned');
|
|
30
|
-
|
|
31
|
-
import { log } from 'console';
|
|
32
30
|
import setupAuth from './plugins/setupAuth';
|
|
31
|
+
import readCerts from './readCerts';
|
|
33
32
|
|
|
34
33
|
let os = require('os');
|
|
35
34
|
|
|
36
|
-
function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode,
|
|
35
|
+
function iService (userRouteTable, useDefault, asset, allAppEnv, serverMode, userCache) {
|
|
37
36
|
// process.env.APPHOST_ADDR = process.env.APPHOST;
|
|
38
37
|
const init = async () => {
|
|
39
|
-
|
|
38
|
+
|
|
40
39
|
if (process.env.APPHOST === '*') {
|
|
41
40
|
process.env.APPHOST = os.hostname();
|
|
42
41
|
}
|
|
@@ -49,7 +48,7 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
|
|
|
49
48
|
}
|
|
50
49
|
let isSameSite = 'None';
|
|
51
50
|
let isSecure = false;
|
|
52
|
-
|
|
51
|
+
|
|
53
52
|
if (process.env.SAMESITE != null) {
|
|
54
53
|
let [s1, s2] = process.env.SAMESITE.split(',');
|
|
55
54
|
isSameSite = s1;
|
|
@@ -58,7 +57,7 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
|
|
|
58
57
|
isSecure = false;
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
|
-
|
|
60
|
+
|
|
62
61
|
|
|
63
62
|
let sConfig = {
|
|
64
63
|
port: process.env.APPPORT,
|
|
@@ -66,19 +65,19 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
|
|
|
66
65
|
|
|
67
66
|
state: {
|
|
68
67
|
isSameSite: isSameSite,
|
|
69
|
-
isSecure: isSecure,
|
|
68
|
+
isSecure : isSecure,
|
|
70
69
|
|
|
71
70
|
},
|
|
72
|
-
|
|
71
|
+
|
|
73
72
|
|
|
74
73
|
routes: {
|
|
75
74
|
payload: {
|
|
76
75
|
maxBytes: maxBytes
|
|
77
76
|
},
|
|
78
77
|
cors: {
|
|
79
|
-
origin: ['*'],
|
|
78
|
+
origin : ['*'],
|
|
80
79
|
credentials: true,
|
|
81
|
-
|
|
80
|
+
|
|
82
81
|
"headers": ["Accept", "Authorization", "Content-Type", "If-None-Match", "Accept-language"]
|
|
83
82
|
/*
|
|
84
83
|
'Access-Control-Allow-Methods': ['GET', 'POST', 'OPTIONS'],
|
|
@@ -86,21 +85,21 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
|
|
|
86
85
|
additionalExposedHeaders : ['location'],
|
|
87
86
|
*/
|
|
88
87
|
}
|
|
89
|
-
|
|
88
|
+
|
|
90
89
|
},
|
|
91
90
|
};
|
|
92
91
|
if (process.env.HAPIDEBUG === 'YES') {
|
|
93
|
-
sConfig.debug = { request: '*'
|
|
92
|
+
sConfig.debug = { request: '*' };
|
|
94
93
|
}
|
|
95
|
-
debug(JSON.stringify(sConfig, null,
|
|
94
|
+
debug(JSON.stringify(sConfig, null,4));
|
|
96
95
|
if (process.env.HTTPS === 'true') {
|
|
97
|
-
sConfig.tls =
|
|
96
|
+
sConfig.tls = getCertificates();
|
|
98
97
|
debug('Setup of SSL certificates completed');
|
|
99
98
|
} else {
|
|
100
99
|
debug('Running with no SSL certificates');
|
|
101
100
|
}
|
|
102
101
|
if (asset !== null) {
|
|
103
|
-
sConfig.routes.files
|
|
102
|
+
sConfig.routes.files= { relativeTo: asset };
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
debug2(
|
|
@@ -118,10 +117,10 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
|
|
|
118
117
|
*/
|
|
119
118
|
|
|
120
119
|
let nodeCacheOptions = {
|
|
121
|
-
stdTTL: 24
|
|
122
|
-
checkPeriod: 3600,
|
|
120
|
+
stdTTL : 24*60*60*1000,
|
|
121
|
+
checkPeriod : 3600,
|
|
123
122
|
errorOnMissing: true,
|
|
124
|
-
useClones: false,
|
|
123
|
+
useClones : false,
|
|
125
124
|
deleteOnExpire: true,
|
|
126
125
|
};
|
|
127
126
|
let storeCache = new NodeCache(nodeCacheOptions);
|
|
@@ -129,9 +128,9 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
|
|
|
129
128
|
|
|
130
129
|
// common plugins
|
|
131
130
|
let visionOptions = {
|
|
132
|
-
engines: { html: require('handlebars') },
|
|
131
|
+
engines : { html: require('handlebars') },
|
|
133
132
|
relativeTo: __dirname,
|
|
134
|
-
path: '.',
|
|
133
|
+
path : '.',
|
|
135
134
|
};
|
|
136
135
|
await hapiServer.register(Vision);
|
|
137
136
|
hapiServer.views(visionOptions);
|
|
@@ -140,100 +139,56 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
|
|
|
140
139
|
await hapiServer.register({ plugin: require('hapi-require-https'), options: {} });
|
|
141
140
|
}
|
|
142
141
|
// register H202 for proxy handling
|
|
143
|
-
// https://hapi.dev/module/h2o2/api/?v=10.0.1
|
|
144
|
-
|
|
145
142
|
await hapiServer.register(H202);
|
|
146
|
-
/*
|
|
147
|
-
await hapiServer.register({
|
|
148
|
-
plugin : require('hapi-pino'),
|
|
149
|
-
options: {
|
|
150
|
-
prettyPrint: process.env.NODE_ENV !== 'production',
|
|
151
|
-
level : process.env.LOGLEVEL == null ? 'silent' : process.env.LOGLEVEL,
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
*/
|
|
155
143
|
|
|
156
|
-
|
|
144
|
+
|
|
157
145
|
// setup authentication related plugins
|
|
158
|
-
|
|
146
|
+
|
|
159
147
|
let options = {
|
|
160
|
-
serverMode: serverMode,
|
|
161
|
-
authFlow: process.env.AUTHFLOW,
|
|
162
|
-
host: process.env.VIYA_SERVER,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
appHost: process.env.APPHOST,
|
|
177
|
-
appPort: process.env.APPPORT,
|
|
148
|
+
serverMode : serverMode,
|
|
149
|
+
authFlow : process.env.AUTHFLOW,
|
|
150
|
+
host : process.env.VIYA_SERVER,
|
|
151
|
+
isSameSite : isSameSite,
|
|
152
|
+
isSecure : isSecure,
|
|
153
|
+
ns : (allAppEnv.LOGONPAYLOAD != null) ? allAppEnv.LOGONPAYLOAD.ns : null,
|
|
154
|
+
nsHost : (allAppEnv.LOGONPAYLOAD != null) ? allAppEnv.LOGONPAYLOAD.nsHost : null,
|
|
155
|
+
redirect : process.env.REDIRECT,
|
|
156
|
+
clientId : process.env.CLIENTID,
|
|
157
|
+
clientSecret : process.env.CLIENTSECRET,
|
|
158
|
+
redirectTo : `/${process.env.APPNAME}/logon`,
|
|
159
|
+
allAppEnv : allAppEnv,
|
|
160
|
+
useHapiCookie : true,
|
|
161
|
+
appName : process.env.APPNAME,
|
|
162
|
+
appHost : process.env.APPHOST,
|
|
163
|
+
appPort : process.env.APPPORT,
|
|
178
164
|
userRouteTable: userRouteTable,
|
|
179
|
-
useDefault: useDefault, /* not used - left here for potential reuse */
|
|
180
|
-
|
|
181
|
-
https: process.env.HTTPS,
|
|
182
|
-
authDefault: false, /* set later in setDefaultRoutes */
|
|
183
|
-
|
|
165
|
+
useDefault : useDefault, /* not used - left here for potential reuse */
|
|
166
|
+
userCache : userCache ||{},
|
|
167
|
+
https : process.env.HTTPS,
|
|
168
|
+
authDefault : false, /* set later in setDefaultRoutes */
|
|
169
|
+
authLogon : false /* set later in setDefaultRoutes */
|
|
184
170
|
|
|
185
171
|
};
|
|
186
|
-
|
|
187
|
-
debug2('Options',
|
|
172
|
+
|
|
173
|
+
debug2('Options',options);
|
|
188
174
|
if (process.env.AUTHFLOW != null) {
|
|
189
|
-
|
|
190
|
-
|
|
175
|
+
await setupAuth(hapiServer, options);
|
|
176
|
+
if (process.env.PREAUTH === 'YES') {
|
|
191
177
|
console.log('Preauth enabled');
|
|
192
178
|
hapiServer.ext('onPreAuth', (request, h) => {
|
|
193
179
|
debugger;
|
|
194
180
|
if (!request.auth.isAuthenticated && !request.path.startsWith(`/login`)) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
181
|
+
const redirectTo = `${request.path}?${new URLSearchParams(request.query).toString()}`;
|
|
182
|
+
console.log('Redirect to login', {redirectTo});
|
|
183
|
+
debugger;
|
|
184
|
+
return h.redirect(`/login`).takeover();
|
|
199
185
|
}
|
|
200
186
|
return h.continue;
|
|
201
187
|
});
|
|
202
188
|
}
|
|
203
189
|
}
|
|
204
190
|
console.log('Plugin', process.env.PLUGIN);
|
|
205
|
-
|
|
206
|
-
if (process.env.PLUGIN === 'hapi-swagger' && serverMode === 'api') {
|
|
207
|
-
let swaggerOptions = {
|
|
208
|
-
"info": {
|
|
209
|
-
"title": `API for ${process.env.APPNAME}`,
|
|
210
|
-
"version": "0.0.1",
|
|
211
|
-
"description": "This document was auto-generated at run time"
|
|
212
|
-
},
|
|
213
|
-
"schemes": ["http", "https"],
|
|
214
|
-
"cors": true,
|
|
215
|
-
"debug": true,
|
|
216
|
-
"jsonPath": `/${options.appName}/swagger.json`,
|
|
217
|
-
"jsonRoutePath": `/${options.appName}/swagger.json`,
|
|
218
|
-
"documentationPage": true,
|
|
219
|
-
"documentationPath": `/${options.appName}/documentation`,
|
|
220
|
-
"swaggerUI": true,
|
|
221
|
-
"swaggerUIPath": `/${options.appName}/swaggerui`,
|
|
222
|
-
auth: options.authDefault
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
if (userInfo != null) {
|
|
226
|
-
let override = userInfo(options, 'SWAGGEROPTIONS');
|
|
227
|
-
swaggerOptions = { ...swaggerOptions, ...override };
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
debug('Swagger Options:', swaggerOptions);
|
|
231
|
-
await hapiServer.register({ plugin: serverMode, options: swaggerOptions });
|
|
232
|
-
} else if (process.env.PLUGIN == 'hapi-openapi' && serverMode === 'api') {
|
|
233
|
-
console.log('hapi-openapi', 'coming soon');
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
191
|
+
|
|
237
192
|
//
|
|
238
193
|
// Start server
|
|
239
194
|
//
|
|
@@ -248,7 +203,7 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
|
|
|
248
203
|
options.serverMode === 'app'
|
|
249
204
|
? `Visit ${hh}/${process.env.APPNAME} to access application`
|
|
250
205
|
: `Visit ${hh}/${process.env.APPNAME}/api to access swagger`;
|
|
251
|
-
console.log('\x1b[1m%s\x1b[0m',
|
|
206
|
+
console.log('\x1b[1m%s\x1b[0m',msg);
|
|
252
207
|
console.log('NOTE: If running in container use the exported port');
|
|
253
208
|
process.env.APPSERVER = `${hh}/${process.env.APPNAME}`;
|
|
254
209
|
process.env.HEALTH = 'true';
|
|
@@ -262,121 +217,75 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
|
|
|
262
217
|
init();
|
|
263
218
|
}
|
|
264
219
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
let options = null;
|
|
220
|
+
function getCertificates () {
|
|
268
221
|
let tlsdir = process.env.SSLCERT;
|
|
269
|
-
|
|
270
|
-
if (
|
|
271
|
-
options = readTLS(tlsdir);
|
|
272
|
-
options.rejectUnauthorized = true;
|
|
273
|
-
} else {
|
|
222
|
+
let options = readCerts(tlsdir);
|
|
223
|
+
if (options === null){
|
|
274
224
|
console.log('No SSL certificates found, generating self-signed certificates');
|
|
275
|
-
options =
|
|
276
|
-
options.rejectUnauthorized
|
|
277
|
-
}
|
|
278
|
-
return options;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
function readTLS(tlsdir) {
|
|
282
|
-
console.log("[Note] Using TLS dir: " + tlsdir);
|
|
283
|
-
if (fs.existsSync(tlsdir) === false) {
|
|
284
|
-
console.log("[Warning] Specified TLS dir does not exist: " + tlsdir);
|
|
285
|
-
return null;
|
|
225
|
+
options = getTls();
|
|
226
|
+
options.rejectUnauthorized= false;
|
|
286
227
|
}
|
|
287
|
-
|
|
288
|
-
let listOfFiles = fs.readdirSync(tlsdir);
|
|
289
|
-
console.log("[Note] TLS/SSL files found: " + listOfFiles);
|
|
290
|
-
let options = {};
|
|
291
|
-
for (let i = 0; i < listOfFiles.length; i++) {
|
|
292
|
-
let fname = listOfFiles[i];
|
|
293
|
-
let name = tlsdir + '/' + listOfFiles[i];
|
|
294
|
-
let key = fname.split('.')[0];
|
|
295
|
-
options[key] = fs.readFileSync(name, { encoding: 'utf8' });
|
|
296
|
-
}
|
|
297
|
-
console.log('TLS FILES', Object.keys(options));
|
|
298
228
|
return options;
|
|
299
|
-
|
|
300
229
|
}
|
|
301
230
|
|
|
302
|
-
|
|
231
|
+
function getTls () {
|
|
303
232
|
let options = {
|
|
304
|
-
keySize: 2048,
|
|
305
|
-
days: 360,
|
|
306
|
-
algorithm: "sha256",
|
|
233
|
+
keySize : 2048,
|
|
234
|
+
days : 360,
|
|
235
|
+
algorithm : "sha256",
|
|
307
236
|
clientCertificate: true,
|
|
308
|
-
extensions: {},
|
|
237
|
+
extensions : {},
|
|
309
238
|
};
|
|
310
239
|
let subjt = process.env.TLS_CREATE.replaceAll('"', '').trim();
|
|
311
|
-
let subj
|
|
312
|
-
|
|
240
|
+
let subj = subjt.split(',');
|
|
241
|
+
|
|
313
242
|
let d = {};
|
|
314
243
|
subj.map(c => {
|
|
315
244
|
let r = c.split(':');
|
|
316
|
-
d[r[0]] = r[1];
|
|
317
|
-
return {
|
|
245
|
+
d[ r[ 0 ] ] = r[ 1 ];
|
|
246
|
+
return { value: r[ 1 ] };
|
|
318
247
|
});
|
|
319
248
|
|
|
320
249
|
// TLS_CREATE=C:US,ST:NC,L:Cary,O:SAS Institute,OU:STO,CN:localhost,ALT:na.sas.com
|
|
321
250
|
let attr = [
|
|
322
251
|
{
|
|
323
|
-
name: 'commonName',
|
|
252
|
+
name : 'commonName',
|
|
324
253
|
value: d.CN /*process.env.APPHOST*/,
|
|
325
254
|
},
|
|
326
255
|
{
|
|
327
|
-
name: 'countryName',
|
|
256
|
+
name : 'countryName',
|
|
328
257
|
value: d.C
|
|
329
258
|
}, {
|
|
330
259
|
shortName: 'ST',
|
|
331
|
-
value: d.ST
|
|
260
|
+
value : d.ST
|
|
332
261
|
}, {
|
|
333
|
-
name: 'localityName',
|
|
262
|
+
name : 'localityName',
|
|
334
263
|
value: d.L,
|
|
335
264
|
}, {
|
|
336
|
-
name: 'organizationName',
|
|
265
|
+
name : 'organizationName',
|
|
337
266
|
value: d.O
|
|
338
267
|
},
|
|
339
268
|
{
|
|
340
269
|
shortName: 'OU',
|
|
341
|
-
value: d.OU
|
|
270
|
+
value : d.OU
|
|
342
271
|
}
|
|
343
272
|
];
|
|
344
|
-
/*
|
|
345
|
-
options.extensions.altNames = [
|
|
346
|
-
// { type: 6, value: `http://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}` },
|
|
347
|
-
{ type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}` },
|
|
348
|
-
{ type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}/api` },
|
|
349
|
-
{ type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}/logon` },
|
|
350
|
-
{ type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}` },
|
|
351
|
-
{ type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}/api` },
|
|
352
|
-
{ type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}/logon` },
|
|
353
|
-
];
|
|
354
|
-
|
|
355
|
-
options.extensions.altNames = [
|
|
356
|
-
{ type: 2, value: 'localhost' }, // DNS
|
|
357
|
-
{ type: 7, ip: '127.0.0.1' }, // IPv4
|
|
358
|
-
{ type: 7, ip: '::1' } // IPv6
|
|
359
|
-
];
|
|
360
|
-
*/
|
|
361
|
-
options.extensions = [
|
|
362
|
-
{
|
|
363
|
-
name: 'subjectAltName',
|
|
364
|
-
altNames: [
|
|
365
|
-
{ type: 2, value: 'localhost' }, // DNS
|
|
366
|
-
{ type: 7, ip: '127.0.0.1' }, // IPv4
|
|
367
|
-
{ type: 7, ip: '::1' } // IPv6
|
|
368
|
-
|
|
369
|
-
]
|
|
370
|
-
}
|
|
371
273
|
|
|
274
|
+
options.extensions.altNames = [
|
|
275
|
+
// { type: 6, value: `http://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}` },
|
|
276
|
+
{ type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}` },
|
|
277
|
+
{ type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}/api` },
|
|
278
|
+
{ type: 6, value: `https://${process.env.APPHOST}:${process.env.APPPORT}/${process.env.APPNAME}/logon` },
|
|
279
|
+
{ type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}` },
|
|
280
|
+
{ type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}/api` },
|
|
281
|
+
{ type: 6, value: `https://${process.env.APPHOST}/${process.env.APPNAME}/logon` },
|
|
372
282
|
];
|
|
373
|
-
|
|
283
|
+
debug('tls options ', JSON.stringify(options, null,4));
|
|
374
284
|
let pems = selfsigned.generate(attr, options);
|
|
375
285
|
let tls = {
|
|
376
286
|
cert: pems.cert,
|
|
377
|
-
key: pems.private
|
|
287
|
+
key : pems.private
|
|
378
288
|
};
|
|
379
|
-
console.log('Self-signed certificates created', tls);
|
|
380
289
|
return tls;
|
|
381
290
|
|
|
382
291
|
|
package/src/index.js
CHANGED
|
@@ -21,6 +21,7 @@ import "regenerator-runtime/runtime";
|
|
|
21
21
|
import fs from "fs";
|
|
22
22
|
import iService from "./iService";
|
|
23
23
|
import config from "./config";
|
|
24
|
+
import readCerts from './readCerts';
|
|
24
25
|
import yargs from "yargs";
|
|
25
26
|
import { hideBin } from 'yargs/helpers';
|
|
26
27
|
let debug = require("debug")("startup");
|
|
@@ -30,10 +31,10 @@ module.exports = function core(
|
|
|
30
31
|
useDefault,
|
|
31
32
|
serverMode,
|
|
32
33
|
customize,
|
|
33
|
-
|
|
34
|
+
userCache
|
|
34
35
|
) {
|
|
35
36
|
let argv = yargs(hideBin(process.argv)).argv;
|
|
36
|
-
let env = argv.env == null ?
|
|
37
|
+
let env = argv.env == null ? null : argv.env;
|
|
37
38
|
let appenv = argv.appenv == null ? null : argv.appenv;
|
|
38
39
|
let docker = argv.docker == null ? null : argv.docker;
|
|
39
40
|
//process.env.SERVERMODE = serverMode !== null ? "api" : "app";
|
|
@@ -55,7 +56,7 @@ module.exports = function core(
|
|
|
55
56
|
`
|
|
56
57
|
);
|
|
57
58
|
|
|
58
|
-
iapp(null, env, docker, uTable, useDefault, serverMode, customize);
|
|
59
|
+
iapp(null, env, docker, uTable, useDefault, serverMode, customize,userCache);
|
|
59
60
|
};
|
|
60
61
|
|
|
61
62
|
function iapp(
|
|
@@ -65,7 +66,8 @@ function iapp(
|
|
|
65
66
|
uTable,
|
|
66
67
|
useDefault,
|
|
67
68
|
serverMode,
|
|
68
|
-
customize
|
|
69
|
+
customize,
|
|
70
|
+
userCache
|
|
69
71
|
) {
|
|
70
72
|
let asset = setup(rafEnv, dockerFile);
|
|
71
73
|
if (appSrc == null) {
|
|
@@ -79,12 +81,12 @@ function iapp(
|
|
|
79
81
|
console.log("createPayload failed");
|
|
80
82
|
process.exit(1);
|
|
81
83
|
} else {
|
|
82
|
-
iService(uTable, useDefault, asset, r, serverMode, customize);
|
|
84
|
+
iService(uTable, useDefault, asset, r, serverMode, customize, userCache);
|
|
83
85
|
}
|
|
84
86
|
});
|
|
85
87
|
} else {
|
|
86
88
|
let appEnv = getAllEnv({});
|
|
87
|
-
iService(uTable, useDefault, asset, appEnv, serverMode, customize);
|
|
89
|
+
iService(uTable, useDefault, asset, appEnv, serverMode, customize, userCache);
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
|
|
@@ -115,7 +117,7 @@ function createPayload(srcName, cb) {
|
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
119
|
|
|
118
|
-
function getAllEnv(
|
|
120
|
+
function getAllEnv(userInfo) {
|
|
119
121
|
let env;
|
|
120
122
|
let l = null;
|
|
121
123
|
let host = trimit("VIYA_SERVER");
|
|
@@ -124,15 +126,20 @@ function getAllEnv(userData) {
|
|
|
124
126
|
host = null;
|
|
125
127
|
}
|
|
126
128
|
|
|
129
|
+
/*
|
|
130
|
+
if (process.env.AUTHTYPE != null) {
|
|
131
|
+
process.env.AUTHFLOW = process.env.AUTHTYPE;
|
|
132
|
+
}
|
|
133
|
+
*/
|
|
127
134
|
|
|
128
135
|
let authflow = trimit("AUTHFLOW");
|
|
129
|
-
|
|
130
|
-
if (authflow === "authorization_code" || authflow === "code" || authflow === "server" ||
|
|
131
|
-
authflow === "null" || authflow === "pkce") {
|
|
136
|
+
if (authflow === "authorization_code" || authflow === "code") {
|
|
132
137
|
authflow = "server";
|
|
133
|
-
|
|
134
138
|
}
|
|
135
139
|
|
|
140
|
+
if (authflow === null) {
|
|
141
|
+
host = null;
|
|
142
|
+
}
|
|
136
143
|
|
|
137
144
|
if (host === null) {
|
|
138
145
|
authflow = null;
|
|
@@ -146,7 +153,7 @@ function getAllEnv(userData) {
|
|
|
146
153
|
let clientID = trimit("CLIENTID");
|
|
147
154
|
|
|
148
155
|
// eslint-disable-next-line no-unused-vars
|
|
149
|
-
|
|
156
|
+
let clientSecret = trimit("CLIENTSECRET");
|
|
150
157
|
let keepAlive = trimit("KEEPALIVE");
|
|
151
158
|
let appName = trimit("APPNAME");
|
|
152
159
|
let ns = trimit("NAMESPACE");
|
|
@@ -159,7 +166,6 @@ function getAllEnv(userData) {
|
|
|
159
166
|
host: host,
|
|
160
167
|
clientID: clientID,
|
|
161
168
|
appName: appName,
|
|
162
|
-
pkce: pkce,
|
|
163
169
|
|
|
164
170
|
keepAlive: null,
|
|
165
171
|
useToken: process.env.USETOKEN,
|
|
@@ -219,17 +225,18 @@ for (let key in process.env) {
|
|
|
219
225
|
if (v.startsWith('$')) {
|
|
220
226
|
v = process.env[v.substring(1)];
|
|
221
227
|
}
|
|
222
|
-
|
|
228
|
+
userInfo[k] = (v != null) ? v.trim() : null;
|
|
223
229
|
} else {
|
|
224
|
-
|
|
230
|
+
userInfo[k] = null;
|
|
225
231
|
|
|
226
232
|
}
|
|
227
233
|
}
|
|
228
234
|
}
|
|
229
|
-
|
|
235
|
+
userInfo.viyaCert = readCerts(process.env.VIYACERT);
|
|
236
|
+
userInfo.appName = appName;
|
|
230
237
|
env = {
|
|
231
238
|
LOGONPAYLOAD: l,
|
|
232
|
-
APPENV:
|
|
239
|
+
APPENV: userInfo,
|
|
233
240
|
};
|
|
234
241
|
console.log("Final APPENV configuration for the server");
|
|
235
242
|
console.log(JSON.stringify(env, null, 4));
|
|
@@ -245,3 +252,9 @@ function trimit(e) {
|
|
|
245
252
|
a = a.trim();
|
|
246
253
|
return a.length === 0 ? null : a;
|
|
247
254
|
}
|
|
255
|
+
|
|
256
|
+
function readVIYACERT(){
|
|
257
|
+
let certs = null;
|
|
258
|
+
let certfile = process.env.VIYACERT;
|
|
259
|
+
|
|
260
|
+
}
|
package/src/plugins/SASauth.js
CHANGED
|
@@ -65,15 +65,11 @@ async function iSASauth (server, options) {
|
|
|
65
65
|
provider : provider,
|
|
66
66
|
password : uuid.v4(),
|
|
67
67
|
clientId : options.clientId,
|
|
68
|
-
clientSecret:
|
|
68
|
+
clientSecret: options.clientSecret,
|
|
69
69
|
// isSameSite : options.isSameSite,
|
|
70
70
|
isSecure : options.isSecure
|
|
71
71
|
};
|
|
72
|
-
|
|
73
|
-
if (options.pkce === true) {
|
|
74
|
-
bellAuthOptions.pkce = 'S256';
|
|
75
|
-
}
|
|
76
|
-
|
|
72
|
+
// console.log('SASAuth options', bellAuthOptions);
|
|
77
73
|
debug('belloptions', bellAuthOptions);
|
|
78
74
|
server.log('SASAuth',bellAuthOptions);
|
|
79
75
|
await server.register(bell);
|
package/src/plugins/appCookie.js
CHANGED
|
@@ -7,7 +7,7 @@ module.exports = async function appCookie (server, options){
|
|
|
7
7
|
await server.register(require('@hapi/cookie'));
|
|
8
8
|
|
|
9
9
|
debug('in appCookie');
|
|
10
|
-
debug(
|
|
10
|
+
debug(options.redirectTo);
|
|
11
11
|
let cookieOptions = {
|
|
12
12
|
cookie: {
|
|
13
13
|
name : 'cookie',
|
|
@@ -17,9 +17,8 @@ module.exports = async function appCookie (server, options){
|
|
|
17
17
|
},
|
|
18
18
|
redirectTo : options.redirectTo,
|
|
19
19
|
appendNext : {name: 'next'},
|
|
20
|
-
validate: async (req, session) => {
|
|
21
|
-
|
|
22
|
-
debug('Cookie validate', `path - ${req.path}`);
|
|
20
|
+
validate : async (req, session) => {
|
|
21
|
+
debug('Cookie validateFunc', `path - ${req.path}`);
|
|
23
22
|
|
|
24
23
|
if (session == null) {
|
|
25
24
|
console.log('session is null');
|
|
@@ -39,7 +38,7 @@ module.exports = async function appCookie (server, options){
|
|
|
39
38
|
if (credentials == null) {
|
|
40
39
|
return {isValid: false};
|
|
41
40
|
}
|
|
42
|
-
debug('Cookie
|
|
41
|
+
debug('Cookie validateFunc', sid);
|
|
43
42
|
return {isValid: true, credentials: credentials};
|
|
44
43
|
}
|
|
45
44
|
};
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
|
|
20
20
|
async function setContext (req,h){
|
|
21
21
|
let credentials = req.auth.credentials;
|
|
22
|
-
console.log('
|
|
22
|
+
console.log('in setContext');
|
|
23
|
+
console.log('credentials=', credentials);
|
|
23
24
|
let context = {
|
|
24
25
|
path : req.path,
|
|
25
26
|
params : req.params,
|
|
@@ -27,9 +28,9 @@ async function setContext (req,h){
|
|
|
27
28
|
payload: req.payload,
|
|
28
29
|
queryOrig: (credentials != null) ? credentials.query : {},
|
|
29
30
|
token : (credentials != null) ? `bearer ${credentials.token}` : null,
|
|
31
|
+
credentials: credentials,
|
|
30
32
|
host : process.env.VIYA_SERVER
|
|
31
33
|
};
|
|
32
|
-
|
|
33
34
|
return context;
|
|
34
35
|
}
|
|
35
36
|
export default setContext;
|