@sassoftware/viya-serverjs 0.5.5 → 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 +15 -32
- package/.env.proxy +24 -0
- package/.env.server +20 -35
- package/Dockerfile +24 -30
- 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 +22 -15
- package/lib/iService.js +98 -234
- package/lib/index.js +29 -15
- package/lib/plugins/SASauth.js +2 -8
- 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 +15 -21
- 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 -11
- package/src/iService.js +82 -173
- package/src/index.js +30 -17
- package/src/plugins/SASauth.js +2 -9
- 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 -25
- package/testca.js +0 -10
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<!--
|
|
3
|
+
~ /* ------------------------------------------------------------------------------------
|
|
4
|
+
~ * Copyright (c) SAS Institute Inc.
|
|
5
|
+
~ * Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
~ * you may not use this file except in compliance with the License.
|
|
7
|
+
~ * You may obtain a copy of the License at
|
|
8
|
+
~ *
|
|
9
|
+
~ * http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
~ *
|
|
11
|
+
~ * Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
~ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
~ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
~ * See the License for the specific language governing permissions and
|
|
15
|
+
~ * limitations under the License.
|
|
16
|
+
~ ----------------------------------------------------------------------------------------*/
|
|
17
|
+
~
|
|
18
|
+
-->
|
|
19
|
+
|
|
20
|
+
<html lang="en">
|
|
21
|
+
|
|
22
|
+
<head>
|
|
23
|
+
<meta charset="UTF-8" />
|
|
24
|
+
<title>index.html</title>
|
|
25
|
+
|
|
26
|
+
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
|
|
27
|
+
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
|
|
28
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
|
|
29
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.26.0/polyfill.min.js"></script>
|
|
30
|
+
<!--
|
|
31
|
+
<script src="https://unpkg.com/@sassoftware/restaf@5.2.4"></script>
|
|
32
|
+
<script src="https://unpkg.com/@sassoftware/restaflib@5.2.4"></script>
|
|
33
|
+
-->
|
|
34
|
+
<script src="https://unpkg.com/@sassoftware/restaf@5.7.0"></script>
|
|
35
|
+
<script src="https://unpkg.com/@sassoftware/restaflib@5.7.0"></script>
|
|
36
|
+
<script src="/appenv"></script>
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
<style>
|
|
40
|
+
.container {
|
|
41
|
+
display: flex;
|
|
42
|
+
flex-direction: column;
|
|
43
|
+
flex-wrap: nowrap;
|
|
44
|
+
min-height: 800px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.elabel {
|
|
48
|
+
display: inline-block;
|
|
49
|
+
|
|
50
|
+
clear: left;
|
|
51
|
+
width: 250px;
|
|
52
|
+
text-align: right;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.einput {
|
|
56
|
+
display: inline-block;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.div1 {
|
|
60
|
+
border: 1px solid black;
|
|
61
|
+
background: lightskyblue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.div2 {
|
|
65
|
+
border: 1px solid black;
|
|
66
|
+
background: lightskyblue;
|
|
67
|
+
height: 200px;
|
|
68
|
+
}
|
|
69
|
+
</style>
|
|
70
|
+
|
|
71
|
+
<script>
|
|
72
|
+
debugger;
|
|
73
|
+
console.log(JSON.stringify(APPENV, null, 4));
|
|
74
|
+
let store = restaf.initStore({
|
|
75
|
+
casProxy: true,
|
|
76
|
+
options: {
|
|
77
|
+
proxyServer: null,
|
|
78
|
+
httpOptions: (APPENV.viyaCert === null) ? null : {...APPENV.viyaCert, rejectUnauthorized: false}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
debugger; console.log(store.config);
|
|
82
|
+
|
|
83
|
+
let session = null;
|
|
84
|
+
let servers = null;
|
|
85
|
+
let services = null;
|
|
86
|
+
let files = null;
|
|
87
|
+
let reports = null;
|
|
88
|
+
let compute = null;
|
|
89
|
+
|
|
90
|
+
function setup() {
|
|
91
|
+
debugger;
|
|
92
|
+
document.getElementById('output').innerHTML = '...initializing';
|
|
93
|
+
|
|
94
|
+
initSession()
|
|
95
|
+
.then(r => {
|
|
96
|
+
document.getElementById('output').innerHTML = 'ready';
|
|
97
|
+
keepAlive();
|
|
98
|
+
})
|
|
99
|
+
.catch(e => {
|
|
100
|
+
|
|
101
|
+
console.log(e);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function keepAlive() {
|
|
105
|
+
if (LOGONPAYLOAD.keepAlive != null) {
|
|
106
|
+
let interval = 120;
|
|
107
|
+
let timeout = 14400;
|
|
108
|
+
if (LOGONPAYLOAD.timers != null) {
|
|
109
|
+
let opts = LOGONPAYLOAD.timers.split(',');
|
|
110
|
+
interval = parseInt(opts[0]);
|
|
111
|
+
timeout = parseInt(opts[1]);
|
|
112
|
+
}
|
|
113
|
+
console.log(`Keepalive is active`);
|
|
114
|
+
store.keepViyaAlive(LOGONPAYLOAD.keepAlive, interval, timeout, () => {
|
|
115
|
+
console.log('timed out at', Date());
|
|
116
|
+
let params = `scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=0,height=0,left=-1000,top=-1000`;
|
|
117
|
+
window.open(`${appOptions.logonPayload.host}/SASLogon/timedout`, 'Timed Out', params);
|
|
118
|
+
return true;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
function logoff() {
|
|
124
|
+
let url = `${window.location.protocol}//${window.location.host}/${LOGONPAYLOAD.appName}/logout?callbackUrl=onlogoff.html`;
|
|
125
|
+
window.location.replace(url);
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
async function initSession() {
|
|
130
|
+
debugger;
|
|
131
|
+
console.log(APPENV);
|
|
132
|
+
console.log(LOGONPAYLOAD);
|
|
133
|
+
debugger;
|
|
134
|
+
if (LOGONPAYLOAD.host == null) {
|
|
135
|
+
return 'done';
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
let msg = await store.logon(LOGONPAYLOAD);
|
|
139
|
+
console.log(store.connection());
|
|
140
|
+
console.log(msg);
|
|
141
|
+
} catch (err) {
|
|
142
|
+
console.log('Error logging in', JSON.stringify(err, null, 4));
|
|
143
|
+
throw err;
|
|
144
|
+
}
|
|
145
|
+
let name = 'user';
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
//document.getElementById('output').innerHTML = '...running';
|
|
149
|
+
return 'done';
|
|
150
|
+
}
|
|
151
|
+
function runit(type) {
|
|
152
|
+
let testcase;
|
|
153
|
+
switch (type) {
|
|
154
|
+
case 'files': {
|
|
155
|
+
testcase = SASfileService;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case 'compute': {
|
|
159
|
+
testcase = dsCompute;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
case 'cas': {
|
|
163
|
+
testcase = runCas;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case 'timedout': {
|
|
167
|
+
testcase = timedout;
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
case 'redir': {
|
|
171
|
+
testcase = noaction;
|
|
172
|
+
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
case 'spre': {
|
|
176
|
+
testcase = spre;
|
|
177
|
+
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
default: {
|
|
181
|
+
testcase = SASfileService;
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
testcase(store)
|
|
187
|
+
.then(r => {
|
|
188
|
+
document.getElementById(
|
|
189
|
+
'output'
|
|
190
|
+
).innerHTML = JSON.stringify(r, null, 4);
|
|
191
|
+
})
|
|
192
|
+
.catch(err => {
|
|
193
|
+
|
|
194
|
+
document.getElementById(
|
|
195
|
+
'output'
|
|
196
|
+
).innerHTML = JSON.stringify(err, null, 4);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
async function noaction() {
|
|
200
|
+
r = { msg: 'redirects completed' };
|
|
201
|
+
return r;
|
|
202
|
+
}
|
|
203
|
+
async function spre(store) {
|
|
204
|
+
let p = {
|
|
205
|
+
method: 'GET',
|
|
206
|
+
url: 'http://localhost:3000/api/test',
|
|
207
|
+
withCredentials: true
|
|
208
|
+
}
|
|
209
|
+
let r = await store.request(p);
|
|
210
|
+
return r.data;
|
|
211
|
+
}
|
|
212
|
+
async function timedout(store) {
|
|
213
|
+
console.log('timed out at', Date());
|
|
214
|
+
let params = `scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=0,height=0,left=-1000,top=-1000`;
|
|
215
|
+
window.open(`${LOGONPAYLOAD.host}/SASLogon/timedout`, 'Timed Out', params);
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
async function runCas(store) {
|
|
219
|
+
debugger;
|
|
220
|
+
let { casManagement } = await store.addServices('casManagement');
|
|
221
|
+
let servers = await store.apiCall(
|
|
222
|
+
casManagement.links('servers')
|
|
223
|
+
);
|
|
224
|
+
let serverName = servers.itemsList(0);
|
|
225
|
+
let session = await store.apiCall(
|
|
226
|
+
servers.itemsCmd(serverName, 'createSession')
|
|
227
|
+
);
|
|
228
|
+
let payload = {
|
|
229
|
+
action: 'builtins.echo',
|
|
230
|
+
data: { code: { x: 1 } }
|
|
231
|
+
};
|
|
232
|
+
console.log(JSON.stringify(session.links("execute"), null, 4));
|
|
233
|
+
let r = await store.runAction(session, payload);
|
|
234
|
+
console.log('echo completed');
|
|
235
|
+
await store.apiCall(session.links('delete'));
|
|
236
|
+
return r.items();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async function SASfileService(store) {
|
|
240
|
+
debugger;
|
|
241
|
+
let content;
|
|
242
|
+
try {
|
|
243
|
+
debugger;
|
|
244
|
+
let { files } = await store.addServices('files');
|
|
245
|
+
debugger;
|
|
246
|
+
console.log(JSON.stringify(files.links(), null, 4));
|
|
247
|
+
//console.log('items - should be an array of files(empty array is ok)')
|
|
248
|
+
// console.log(files.items().toJS());
|
|
249
|
+
let payload = {
|
|
250
|
+
data: { x: 1, y: 'This was saved earlier in the step' },
|
|
251
|
+
headers: { 'content-type': 'application/json' }
|
|
252
|
+
};
|
|
253
|
+
let createCmd = files.links('create');
|
|
254
|
+
let newFile = await store.apiCall(createCmd, payload);
|
|
255
|
+
debugger;
|
|
256
|
+
console.log(JSON.stringify(newFile.links('content'), null, 4));
|
|
257
|
+
content = await store.apiCall(newFile.links('content'));
|
|
258
|
+
|
|
259
|
+
} catch (err) {
|
|
260
|
+
console.log(JSON.stringify(err, null, 4));
|
|
261
|
+
debugger;
|
|
262
|
+
}
|
|
263
|
+
console.log(content);
|
|
264
|
+
return content.items();
|
|
265
|
+
}
|
|
266
|
+
async function dsCompute(store) {
|
|
267
|
+
let log = null;
|
|
268
|
+
debugger;
|
|
269
|
+
let { compute } = await store.addServices('compute');
|
|
270
|
+
let servers = await store.apiCall(compute.links('servers'));
|
|
271
|
+
|
|
272
|
+
let contexts = await store.apiCall(compute.links('contexts'));
|
|
273
|
+
|
|
274
|
+
// lookup the name of the first context and then use it to get the associated createSession restafLink
|
|
275
|
+
let createSession = contexts.itemsCmd(
|
|
276
|
+
contexts.itemsList(0),
|
|
277
|
+
'createSession'
|
|
278
|
+
);
|
|
279
|
+
let session = await store.apiCall(createSession);
|
|
280
|
+
|
|
281
|
+
// Now run a simple data step in that session
|
|
282
|
+
let payload = {
|
|
283
|
+
data: {
|
|
284
|
+
code: [`data _null_; do i = 1 to 100; x=1; end; run; `]
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// Now execute the data step and wait for completion
|
|
289
|
+
let job = await store.apiCall(
|
|
290
|
+
session.links('execute'),
|
|
291
|
+
payload
|
|
292
|
+
);
|
|
293
|
+
let status = await store.jobState(job, null, 5, 2);
|
|
294
|
+
|
|
295
|
+
if (status.data === 'running') {
|
|
296
|
+
throw `ERROR: Job did not complete in allotted time`;
|
|
297
|
+
} else {
|
|
298
|
+
switch (status.data) {
|
|
299
|
+
case 'warning':
|
|
300
|
+
console.log(`Warning: check your log for warnings`);
|
|
301
|
+
break;
|
|
302
|
+
case 'error':
|
|
303
|
+
throw `Please correct errors and rerun program`;
|
|
304
|
+
default:
|
|
305
|
+
log = await store.apiCall(status.job.links('log'));
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return log === null ? status : log.items();
|
|
310
|
+
}
|
|
311
|
+
</script>
|
|
312
|
+
</head>
|
|
313
|
+
|
|
314
|
+
<body onload="setup()">
|
|
315
|
+
<h1 id="head">Hi</h1>
|
|
316
|
+
<div>
|
|
317
|
+
<button onclick="runit('redir')">
|
|
318
|
+
Press to do some redirs
|
|
319
|
+
</button>
|
|
320
|
+
<button onclick="runit('files')">
|
|
321
|
+
Press to make a call to file service
|
|
322
|
+
</button>
|
|
323
|
+
<br />
|
|
324
|
+
<br />
|
|
325
|
+
<button onclick="runit('compute')">
|
|
326
|
+
Press to make a call compute service
|
|
327
|
+
</button>
|
|
328
|
+
<br />
|
|
329
|
+
<br />
|
|
330
|
+
<button onclick="runit('cas')">
|
|
331
|
+
Press to make a call to cas echo
|
|
332
|
+
</button>
|
|
333
|
+
<br />
|
|
334
|
+
<br />
|
|
335
|
+
<button onclick="runit('spre')">
|
|
336
|
+
REST call
|
|
337
|
+
</button>
|
|
338
|
+
<br />
|
|
339
|
+
<br />
|
|
340
|
+
<input id='filename'> </input>
|
|
341
|
+
<button onclick="runit('timedout')">
|
|
342
|
+
Press to test timedout
|
|
343
|
+
</button>
|
|
344
|
+
<br />
|
|
345
|
+
<br />
|
|
346
|
+
<button onclick="logoff()">
|
|
347
|
+
logoff
|
|
348
|
+
</button>
|
|
349
|
+
<br />
|
|
350
|
+
</div>
|
|
351
|
+
<div>
|
|
352
|
+
<pre id="output"></pre>
|
|
353
|
+
</div>
|
|
354
|
+
</body>
|
|
355
|
+
|
|
356
|
+
</html>
|
package/server.js
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
*/
|
|
5
5
|
let core = require('./lib/index.js');
|
|
6
6
|
debugger;
|
|
7
|
-
|
|
7
|
+
let userCache = {};
|
|
8
|
+
core(getCustomHandler, true, 'app', null, userCache);
|
|
9
|
+
console.log('Finished cli setup', userCache);
|
|
8
10
|
|
|
9
11
|
function getCustomHandler() {
|
|
10
12
|
let appName = `/${process.env.APPNAME}`; /* does not have to be this - your choice */
|
|
11
13
|
debugger;
|
|
12
|
-
console.log('getCustomHandler called for appName', appName);
|
|
13
14
|
let routes = [
|
|
14
15
|
{
|
|
15
16
|
method: ["GET"],
|
|
@@ -23,33 +24,31 @@ function getCustomHandler() {
|
|
|
23
24
|
let hf = 'help.html';
|
|
24
25
|
return h.file(hf);
|
|
25
26
|
},
|
|
26
|
-
auth:
|
|
27
|
+
auth: false,
|
|
27
28
|
description: "Help",
|
|
28
29
|
notes: "Help",
|
|
29
30
|
tags: ["app"],
|
|
30
31
|
},
|
|
31
32
|
},
|
|
32
33
|
{
|
|
33
|
-
method: ["
|
|
34
|
-
path:
|
|
34
|
+
method: ["GET"],
|
|
35
|
+
path: `${appName}/new`,
|
|
35
36
|
options: {
|
|
36
37
|
files: {
|
|
37
38
|
relativeTo: "./public",
|
|
38
39
|
},
|
|
39
40
|
handler: async (req, h) => {
|
|
40
|
-
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>in imcp');
|
|
41
|
-
console.log('credentials', req.auth.credentials);
|
|
42
41
|
debugger;
|
|
43
|
-
console.log('
|
|
44
|
-
|
|
42
|
+
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>in new');
|
|
43
|
+
console.log({userCache});
|
|
44
|
+
console.log(req.pre.context);
|
|
45
|
+
return h.file('index.html');
|
|
45
46
|
},
|
|
46
|
-
auth: 'logon',
|
|
47
47
|
description: "Create new application",
|
|
48
48
|
notes: "Index file created from env data",
|
|
49
49
|
tags: ["app"],
|
|
50
50
|
},
|
|
51
51
|
}
|
|
52
|
-
|
|
53
52
|
];
|
|
54
53
|
return routes;
|
|
55
54
|
}
|
package/src/handlers/codeAuth.js
CHANGED
|
@@ -10,19 +10,19 @@ async function codeAuth (req, h, options) {
|
|
|
10
10
|
debug('in codeauth');
|
|
11
11
|
await setCookies(req, h, options);
|
|
12
12
|
debug(options);
|
|
13
|
-
// add support for REDIRECT env variable
|
|
14
13
|
let indexHTML = process.env.APPENTRY == null ? 'index.html' : process.env.APPENTRY;
|
|
15
|
-
let redirectPath = null;
|
|
16
14
|
if (process.env.REDIRECT != null) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
: `/${process.env.REDIRECT}`);
|
|
15
|
+
debug('using REDIRECT env variable', process.env.REDIRECT);
|
|
16
|
+
indexHTML = process.env.REDIRECT;
|
|
20
17
|
}
|
|
21
|
-
debug(indexHTML);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
debug('..................', indexHTML);
|
|
19
|
+
if (indexHTML.indexOf('/') === 0) {
|
|
20
|
+
// added to support create-react-restaf-viya-app cli
|
|
21
|
+
if (indexHTML !== '/develop') {
|
|
22
|
+
indexHTML = `/${process.env.APPNAME}${indexHTML}`;
|
|
23
|
+
}
|
|
24
|
+
console.log(`Redirecting to ${indexHTML}`);
|
|
25
|
+
return h.redirect(indexHTML);
|
|
26
26
|
} else {
|
|
27
27
|
console.log(`Visiting ${indexHTML}`);
|
|
28
28
|
return h.file(indexHTML);
|
package/src/handlers/getApp.js
CHANGED
|
@@ -7,6 +7,7 @@ import codeAuth from './codeAuth';
|
|
|
7
7
|
let debug = require('debug')('getapp');
|
|
8
8
|
|
|
9
9
|
async function getApp (options, req, h) {
|
|
10
|
+
console.log('In getApp handler', options);
|
|
10
11
|
if (process.env.AUTHFLOW === 'implicit') {
|
|
11
12
|
let x = `${process.env.VIYA_SERVER}/SASLogon/oauth/authorize?response_type=token&client_id=${process.env.CLIENTID}`;
|
|
12
13
|
let redirect = `${process.env.APPNAME}/callback`;
|
|
@@ -28,7 +29,9 @@ async function getApp (options, req, h) {
|
|
|
28
29
|
} else if (process.env.AUTHFLOW === 'server') {
|
|
29
30
|
|
|
30
31
|
debug('calling codeauth');
|
|
31
|
-
|
|
32
|
+
let r = codeAuth(req, h, options);
|
|
33
|
+
console.log(options.userCache);
|
|
34
|
+
return r;
|
|
32
35
|
|
|
33
36
|
} else {
|
|
34
37
|
debug('default processing in getapp');
|
package/src/handlers/logon.js
CHANGED
|
@@ -5,15 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
import setCookies from './setCookies';
|
|
7
7
|
let debug = require('debug')('logon');
|
|
8
|
-
async function logon (req, h) {
|
|
8
|
+
async function logon (req, h, options) {
|
|
9
9
|
debugger;
|
|
10
10
|
debug('.................................................in logon');
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
let r = await setCookies(req, h,
|
|
14
|
-
console.log('logon setcookie result:', r);
|
|
13
|
+
let r = await setCookies(req, h, options);
|
|
15
14
|
debug(r.redirect);
|
|
16
|
-
|
|
15
|
+
debug('in logon after setcookie', r.redirect);
|
|
17
16
|
return h.redirect(r.redirect);
|
|
18
17
|
}
|
|
19
18
|
|
|
@@ -5,9 +5,9 @@ async function proxyMapUri (req) {
|
|
|
5
5
|
let sid = credentials.sid;
|
|
6
6
|
console.log('sid=', sid);
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let path = (process.env.PROXYSERVER == null) ? process.env.VIYA_SERVER : process.env.PROXYSERVER;
|
|
8
|
+
|
|
9
|
+
let path = process.env.VIYA_SERVER;
|
|
10
|
+
//let path = (process.env.PROXYSERVER == null) ? process.env.VIYA_SERVER : process.env.PROXYSERVER;
|
|
11
11
|
console.log('proxying to= ', path);
|
|
12
12
|
let params = req.params;
|
|
13
13
|
console.log('params=', params);
|
|
@@ -6,16 +6,15 @@ let uuid = require('uuid');
|
|
|
6
6
|
let debug = require('debug')('setcookies');
|
|
7
7
|
|
|
8
8
|
async function setCookies (req, h, options) {
|
|
9
|
-
debugger;
|
|
10
9
|
let credentials = req.auth.credentials;
|
|
11
|
-
|
|
10
|
+
|
|
11
|
+
debug('setcookie', credentials);
|
|
12
12
|
|
|
13
13
|
if (credentials != null && req.auth.error != null) {
|
|
14
|
-
|
|
14
|
+
debug('setcookie credentials', credentials);
|
|
15
15
|
debug('setcookie error', req.auth.error);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// return { status: false, error: req.auth.error, redirect: '/error' };
|
|
16
|
+
debug('logon failed');
|
|
17
|
+
return { status: false, error: req.auth.error };
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
// create a cookie(sid) and save credentials in cache
|
|
@@ -24,19 +23,17 @@ async function setCookies (req, h, options) {
|
|
|
24
23
|
if (options != null) {
|
|
25
24
|
options.allAppEnv.LOGONPAYLOAD.token = credentials.token;
|
|
26
25
|
options.allAppEnv.LOGONPAYLOAD.tokenType = 'bearer';
|
|
27
|
-
|
|
26
|
+
options.userCache = {...credentials};
|
|
27
|
+
debug(options.allAppEnv.LOGONPAYLOAD);
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
console.log('userCache', options.userCache);
|
|
30
30
|
|
|
31
31
|
await req.server.app.cache.set(sid, credentials, 0);
|
|
32
|
-
await req.server.app.cache.set('credentials', credentials, 0);
|
|
33
|
-
|
|
34
32
|
// Can we get away without setting cookie for this session?
|
|
35
33
|
// Need to also modify keepAlive
|
|
36
34
|
if (process.env.COOKIES !== 'NO') {
|
|
37
35
|
debugger;
|
|
38
36
|
req.cookieAuth.set({ sid });
|
|
39
|
-
// req.cookieAuth.set({auth: credentials});
|
|
40
37
|
};
|
|
41
38
|
debug('credentials query', credentials.query);
|
|
42
39
|
let redirect = (credentials.query != null && credentials.query.next != null) ? credentials.query.next : null;
|