@sassoftware/viya-serverjs 0.3.0 → 0.4.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/.babelrc +6 -6
- package/.dockerignore +2 -2
- package/.env +29 -28
- package/.env.proxy +32 -32
- package/.env.server +30 -30
- package/.eslintignore +3 -3
- package/.eslintrc.json +42 -42
- package/Dockerfile +44 -44
- package/README.md +99 -99
- package/cli.js +9 -9
- package/lib/config.js +16 -16
- package/lib/handlers/appCallback.js +23 -24
- package/lib/handlers/codeAuth.js +17 -18
- package/lib/handlers/decodeJwt.js +3 -3
- package/lib/handlers/favicon.js +22 -25
- package/lib/handlers/getApp.js +20 -21
- package/lib/handlers/getApp2.js +22 -25
- package/lib/handlers/getUser.js +14 -17
- package/lib/handlers/index.js +3 -3
- package/lib/handlers/keepAlive.js +28 -31
- package/lib/handlers/keepAlive2.js +9 -12
- package/lib/handlers/logon.js +12 -15
- package/lib/handlers/logout.js +24 -28
- package/lib/handlers/proxyMapUri.js +6 -11
- package/lib/handlers/proxyOnResponse.js +6 -7
- package/lib/handlers/reactDev.js +22 -25
- package/lib/handlers/setCookies.js +52 -53
- package/lib/iService.js +82 -87
- package/lib/index.js +23 -21
- package/lib/parseDocker.js +3 -3
- package/lib/plugins/SASauth.js +30 -32
- package/lib/plugins/appCookie.js +36 -38
- package/lib/plugins/setContext.js +22 -25
- package/lib/plugins/setDefaultRoutes.js +61 -58
- package/lib/plugins/setupAuth.js +35 -38
- package/lib/plugins/setupUserRoutes.js +16 -16
- package/lib/plugins/token.js +9 -10
- package/lib/schemes/SASTokenScheme.js +24 -27
- package/package.json +85 -79
- package/public/data/Cluster_SDOH1.sas +181 -181
- package/public/data/Cluster_SDOH6.sas +179 -179
- package/public/data/NeuralNetwork_High_med.sas +2408 -2408
- package/public/data/NeuralNetwork_high_med1.sas +2408 -2408
- package/public/data/cars.csv +429 -429
- package/public/data/cmdList.txt +15 -15
- package/public/data/iris.csv +151 -151
- package/public/index.html +354 -350
- package/public/indexProxy.html +351 -351
- package/public/simplesubmit.html +233 -0
- package/server.js +362 -362
- package/src/config.js +90 -90
- package/src/handlers/appCallback.js +40 -40
- package/src/handlers/codeAuth.js +31 -31
- package/src/handlers/decodeJwt.js +10 -10
- package/src/handlers/favicon.js +23 -23
- package/src/handlers/getApp.js +52 -52
- package/src/handlers/getApp2.js +25 -25
- package/src/handlers/getUser.js +20 -20
- package/src/handlers/index.js +36 -36
- package/src/handlers/keepAlive.js +53 -53
- package/src/handlers/keepAlive2.js +12 -12
- package/src/handlers/logon.js +23 -23
- package/src/handlers/logout.js +42 -42
- package/src/handlers/proxyMapUri.js +25 -25
- package/src/handlers/proxyOnResponse.js +11 -11
- package/src/handlers/reactDev.js +29 -29
- package/src/handlers/setCookies.js +81 -79
- package/src/iService.js +346 -345
- package/src/index.js +251 -249
- package/src/parseDocker.js +32 -32
- package/src/plugins/SASauth.js +78 -78
- package/src/plugins/appCookie.js +51 -49
- package/src/plugins/setContext.js +33 -33
- package/src/plugins/setDefaultRoutes.js +256 -253
- package/src/plugins/setupAuth.js +49 -49
- package/src/plugins/setupUserRoutes.js +47 -47
- package/src/plugins/token.js +10 -10
- package/src/schemes/SASTokenScheme.js +43 -43
- package/src/visionIndex.html +23 -23
- package/start.sh +14 -14
- package/tls/viyatls.sh +2 -2
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
'use strict';
|
|
6
|
-
|
|
7
|
-
import axios from 'axios';
|
|
8
|
-
let Boom = require('@hapi/boom');
|
|
9
|
-
let debug= require('debug')('keepAlive');
|
|
10
|
-
|
|
11
|
-
// primarly to do a keepAlive of sasLogon
|
|
12
|
-
let qs = require('qs');
|
|
13
|
-
async function keepAlive (req, h) {
|
|
14
|
-
refreshToken(req, h);
|
|
15
|
-
let SASLogon = `${process.env.VIYA_SERVER}/SASLogon/`;
|
|
16
|
-
return h.redirect(SASLogon).code(302);
|
|
17
|
-
}
|
|
18
|
-
// let SASLogon = `${process.env.VIYA_SERVER}/SASLogon/oauth/authorize?client_id=${process.env.CLIENTID}&redirect_uri=${process.env.APPSERVER}/keepAlive2&response_type=code`;
|
|
19
|
-
|
|
20
|
-
async function refreshToken (req, h) {
|
|
21
|
-
let credentials = req.auth.credentials;
|
|
22
|
-
debug('refreshToken', credentials);
|
|
23
|
-
let sid = credentials.sid;
|
|
24
|
-
let config = {
|
|
25
|
-
url : `${process.env.VIYA_SERVER}/SASLogon/oauth/token`,
|
|
26
|
-
method: 'POST',
|
|
27
|
-
|
|
28
|
-
headers: {
|
|
29
|
-
'Accept' : 'application/json',
|
|
30
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
31
|
-
},
|
|
32
|
-
data: qs.stringify({
|
|
33
|
-
grant_type : 'refresh_token',
|
|
34
|
-
refresh_token: credentials.refreshToken,
|
|
35
|
-
client_id : process.env.CLIENTID,
|
|
36
|
-
client_secret: process.env.CLIENTSECRET
|
|
37
|
-
})
|
|
38
|
-
};
|
|
39
|
-
try {
|
|
40
|
-
let r = await axios(config);
|
|
41
|
-
let newcred = {...credentials};
|
|
42
|
-
newcred.token = r.data.access_token;
|
|
43
|
-
newcred.refreshToken = r.data.refresh_token;
|
|
44
|
-
debug('newcred', newcred);
|
|
45
|
-
await req.server.app.cache.set(sid, credentials);
|
|
46
|
-
return credentials;
|
|
47
|
-
}
|
|
48
|
-
catch(err) {
|
|
49
|
-
let error = Boom.badRequest('Unable to refresh tokens in KeepAlive', JSON.stringify(err, null,4));
|
|
50
|
-
throw error;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
import axios from 'axios';
|
|
8
|
+
let Boom = require('@hapi/boom');
|
|
9
|
+
let debug= require('debug')('keepAlive');
|
|
10
|
+
|
|
11
|
+
// primarly to do a keepAlive of sasLogon
|
|
12
|
+
let qs = require('qs');
|
|
13
|
+
async function keepAlive (req, h) {
|
|
14
|
+
refreshToken(req, h);
|
|
15
|
+
let SASLogon = `${process.env.VIYA_SERVER}/SASLogon/`;
|
|
16
|
+
return h.redirect(SASLogon).code(302);
|
|
17
|
+
}
|
|
18
|
+
// let SASLogon = `${process.env.VIYA_SERVER}/SASLogon/oauth/authorize?client_id=${process.env.CLIENTID}&redirect_uri=${process.env.APPSERVER}/keepAlive2&response_type=code`;
|
|
19
|
+
|
|
20
|
+
async function refreshToken (req, h) {
|
|
21
|
+
let credentials = req.auth.credentials;
|
|
22
|
+
debug('refreshToken', credentials);
|
|
23
|
+
let sid = credentials.sid;
|
|
24
|
+
let config = {
|
|
25
|
+
url : `${process.env.VIYA_SERVER}/SASLogon/oauth/token`,
|
|
26
|
+
method: 'POST',
|
|
27
|
+
|
|
28
|
+
headers: {
|
|
29
|
+
'Accept' : 'application/json',
|
|
30
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
31
|
+
},
|
|
32
|
+
data: qs.stringify({
|
|
33
|
+
grant_type : 'refresh_token',
|
|
34
|
+
refresh_token: credentials.refreshToken,
|
|
35
|
+
client_id : process.env.CLIENTID,
|
|
36
|
+
client_secret: process.env.CLIENTSECRET
|
|
37
|
+
})
|
|
38
|
+
};
|
|
39
|
+
try {
|
|
40
|
+
let r = await axios(config);
|
|
41
|
+
let newcred = {...credentials};
|
|
42
|
+
newcred.token = r.data.access_token;
|
|
43
|
+
newcred.refreshToken = r.data.refresh_token;
|
|
44
|
+
debug('newcred', newcred);
|
|
45
|
+
await req.server.app.cache.set(sid, credentials);
|
|
46
|
+
return credentials;
|
|
47
|
+
}
|
|
48
|
+
catch(err) {
|
|
49
|
+
let error = Boom.badRequest('Unable to refresh tokens in KeepAlive', JSON.stringify(err, null,4));
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|
|
54
54
|
export default keepAlive;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
'use strict';
|
|
6
|
-
|
|
7
|
-
// primarly to do a keepAlive of sasLogon
|
|
8
|
-
|
|
9
|
-
async function keepAlive2 (req, h) {
|
|
10
|
-
|
|
11
|
-
return '<h2> Token refresh failed. Contact you admin </h2>';
|
|
12
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
// primarly to do a keepAlive of sasLogon
|
|
8
|
+
|
|
9
|
+
async function keepAlive2 (req, h) {
|
|
10
|
+
|
|
11
|
+
return '<h2> Token refresh failed. Contact you admin </h2>';
|
|
12
|
+
}
|
|
13
13
|
export default keepAlive2;
|
package/src/handlers/logon.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import setCookies from './setCookies';
|
|
7
|
-
let debug = require('debug')('logon');
|
|
8
|
-
async function logon (req, h) {
|
|
9
|
-
debugger;
|
|
10
|
-
debug('.................................................in logon');
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
let r = await setCookies(req, h, null);
|
|
14
|
-
debug(r.redirect);
|
|
15
|
-
debug('in logon after setcookie', r.redirect);
|
|
16
|
-
return h.redirect(r.redirect);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import setCookies from './setCookies';
|
|
7
|
+
let debug = require('debug')('logon');
|
|
8
|
+
async function logon (req, h) {
|
|
9
|
+
debugger;
|
|
10
|
+
debug('.................................................in logon');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
let r = await setCookies(req, h, null);
|
|
14
|
+
debug(r.redirect);
|
|
15
|
+
debug('in logon after setcookie', r.redirect);
|
|
16
|
+
return h.redirect(r.redirect);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
24
|
export default logon;
|
package/src/handlers/logout.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
'use strict';
|
|
6
|
-
|
|
7
|
-
import axios from 'axios';
|
|
8
|
-
|
|
9
|
-
let debug = require('debug')('logout');
|
|
10
|
-
|
|
11
|
-
async function logout (req, h) {
|
|
12
|
-
let q = req.query;
|
|
13
|
-
debug(req.state);
|
|
14
|
-
|
|
15
|
-
let hh = req.server.info.uri.replace(/0.0.0.0/, 'localhost');
|
|
16
|
-
let callbackUrl = `${hh}/${process.env.APPNAME}`;
|
|
17
|
-
if (q.callbackUrl != null) {
|
|
18
|
-
callbackUrl = `${callbackUrl}/${q.callbackUrl}`;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
let url = `${process.env.VIYA_SERVER}/SASLogon/logout.do?callbackUrl=${callbackUrl}`;
|
|
22
|
-
if (process.env.AUTHFLOW === 'server') {
|
|
23
|
-
if (req.state.ocookie != null) {
|
|
24
|
-
let sid = req.state.ocookie.sid;
|
|
25
|
-
|
|
26
|
-
await req.server.app.cache.del(sid);
|
|
27
|
-
} else {
|
|
28
|
-
console.log('Warning: No cookie returned by the browser');
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return h.redirect(url).unstate('ocookie');
|
|
32
|
-
}
|
|
33
|
-
// eslint-disable-next-line no-unused-vars
|
|
34
|
-
async function ViyaLogout () {
|
|
35
|
-
let p = {
|
|
36
|
-
method: 'GET',
|
|
37
|
-
url : `${process.env.VIYA_SERVER}/SASLogon/logout`
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
let r = await axios(p);
|
|
41
|
-
debug(r);
|
|
42
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
import axios from 'axios';
|
|
8
|
+
|
|
9
|
+
let debug = require('debug')('logout');
|
|
10
|
+
|
|
11
|
+
async function logout (req, h) {
|
|
12
|
+
let q = req.query;
|
|
13
|
+
debug(req.state);
|
|
14
|
+
|
|
15
|
+
let hh = req.server.info.uri.replace(/0.0.0.0/, 'localhost');
|
|
16
|
+
let callbackUrl = `${hh}/${process.env.APPNAME}`;
|
|
17
|
+
if (q.callbackUrl != null) {
|
|
18
|
+
callbackUrl = `${callbackUrl}/${q.callbackUrl}`;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
let url = `${process.env.VIYA_SERVER}/SASLogon/logout.do?callbackUrl=${callbackUrl}`;
|
|
22
|
+
if (process.env.AUTHFLOW === 'server') {
|
|
23
|
+
if (req.state.ocookie != null) {
|
|
24
|
+
let sid = req.state.ocookie.sid;
|
|
25
|
+
|
|
26
|
+
await req.server.app.cache.del(sid);
|
|
27
|
+
} else {
|
|
28
|
+
console.log('Warning: No cookie returned by the browser');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return h.redirect(url).unstate('ocookie');
|
|
32
|
+
}
|
|
33
|
+
// eslint-disable-next-line no-unused-vars
|
|
34
|
+
async function ViyaLogout () {
|
|
35
|
+
let p = {
|
|
36
|
+
method: 'GET',
|
|
37
|
+
url : `${process.env.VIYA_SERVER}/SASLogon/logout`
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
let r = await axios(p);
|
|
41
|
+
debug(r);
|
|
42
|
+
}
|
|
43
43
|
export default logout;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
async function proxyMapUri (req) {
|
|
2
|
-
let credentials = req.auth.credentials;
|
|
3
|
-
console.log('------------------------------------------');
|
|
4
|
-
if (credentials != null) {
|
|
5
|
-
let sid = credentials.sid;
|
|
6
|
-
console.log('sid=', sid);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let path = (process.env.PROXYSERVER == null) ? process.env.VIYA_SERVER : process.env.PROXYSERVER;
|
|
11
|
-
console.log('proxying to= ', path);
|
|
12
|
-
let params = req.params;
|
|
13
|
-
console.log('params=', params);
|
|
14
|
-
let search = req.url.search;
|
|
15
|
-
console.log('query=', search);
|
|
16
|
-
let uri = path + '/' + params.param;
|
|
17
|
-
if (search != null && search.trim().length > 0) {
|
|
18
|
-
uri = uri + search;
|
|
19
|
-
}
|
|
20
|
-
console.log('destination= ',uri);
|
|
21
|
-
return {
|
|
22
|
-
uri: uri
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
export default proxyMapUri;
|
|
1
|
+
async function proxyMapUri (req) {
|
|
2
|
+
let credentials = req.auth.credentials;
|
|
3
|
+
console.log('------------------------------------------');
|
|
4
|
+
if (credentials != null) {
|
|
5
|
+
let sid = credentials.sid;
|
|
6
|
+
console.log('sid=', sid);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
let path = (process.env.PROXYSERVER == null) ? process.env.VIYA_SERVER : process.env.PROXYSERVER;
|
|
11
|
+
console.log('proxying to= ', path);
|
|
12
|
+
let params = req.params;
|
|
13
|
+
console.log('params=', params);
|
|
14
|
+
let search = req.url.search;
|
|
15
|
+
console.log('query=', search);
|
|
16
|
+
let uri = path + '/' + params.param;
|
|
17
|
+
if (search != null && search.trim().length > 0) {
|
|
18
|
+
uri = uri + search;
|
|
19
|
+
}
|
|
20
|
+
console.log('destination= ',uri);
|
|
21
|
+
return {
|
|
22
|
+
uri: uri
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export default proxyMapUri;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
async function proxyOnResponse (err, res, request, h, settings, ttl) {
|
|
3
|
-
/*
|
|
4
|
-
console.log('receiving the response from the upstream.');
|
|
5
|
-
const payload = await Wreck.read(res, { json: true });
|
|
6
|
-
console.log('some payload manipulation if you want to.');
|
|
7
|
-
const response = h.response(payload);
|
|
8
|
-
response.headers = res.headers;
|
|
9
|
-
return response;
|
|
10
|
-
*/
|
|
11
|
-
}
|
|
1
|
+
|
|
2
|
+
async function proxyOnResponse (err, res, request, h, settings, ttl) {
|
|
3
|
+
/*
|
|
4
|
+
console.log('receiving the response from the upstream.');
|
|
5
|
+
const payload = await Wreck.read(res, { json: true });
|
|
6
|
+
console.log('some payload manipulation if you want to.');
|
|
7
|
+
const response = h.response(payload);
|
|
8
|
+
response.headers = res.headers;
|
|
9
|
+
return response;
|
|
10
|
+
*/
|
|
11
|
+
}
|
|
12
12
|
export default proxyOnResponse;
|
package/src/handlers/reactDev.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* ------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) SAS Institute Inc.
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
* ---------------------------------------------------------------------------------------
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
let spawn = require('cross-spawn');
|
|
19
|
-
async function reactDev (req, h) {
|
|
20
|
-
console.log('Spawning the dev server');
|
|
21
|
-
spawn('yarn', ['start'], { stdio: 'inherit' });
|
|
22
|
-
let h2 = '<h2>Viya Server: ' + process.env.VIYA_SERVER + '<h2>';
|
|
23
|
-
return (
|
|
24
|
-
h2 +
|
|
25
|
-
'<h3>Your session is authenticated</h3>' +
|
|
26
|
-
'<h3>Your application is starting in another tab </h3>' +
|
|
27
|
-
'<h4> HMR is active</h4>'
|
|
28
|
-
);
|
|
29
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* ------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) SAS Institute Inc.
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
* ---------------------------------------------------------------------------------------
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
let spawn = require('cross-spawn');
|
|
19
|
+
async function reactDev (req, h) {
|
|
20
|
+
console.log('Spawning the dev server');
|
|
21
|
+
spawn('yarn', ['start'], { stdio: 'inherit' });
|
|
22
|
+
let h2 = '<h2>Viya Server: ' + process.env.VIYA_SERVER + '<h2>';
|
|
23
|
+
return (
|
|
24
|
+
h2 +
|
|
25
|
+
'<h3>Your session is authenticated</h3>' +
|
|
26
|
+
'<h3>Your application is starting in another tab </h3>' +
|
|
27
|
+
'<h4> HMR is active</h4>'
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
30
|
export default reactDev;
|
|
@@ -1,80 +1,82 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
let uuid = require('uuid');
|
|
6
|
-
let debug = require('debug')('setcookies');
|
|
7
|
-
|
|
8
|
-
async function setCookies (req, h, options) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
debug('
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
debug('
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
'
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
let uuid = require('uuid');
|
|
6
|
+
let debug = require('debug')('setcookies');
|
|
7
|
+
|
|
8
|
+
async function setCookies (req, h, options) {
|
|
9
|
+
debugger;
|
|
10
|
+
let credentials = req.auth.credentials;
|
|
11
|
+
console.log('setcookies credentials', credentials);
|
|
12
|
+
debug('setcookie', credentials);
|
|
13
|
+
|
|
14
|
+
if (credentials != null && req.auth.error != null) {
|
|
15
|
+
debug('setcookie credentials', credentials);
|
|
16
|
+
debug('setcookie error', req.auth.error);
|
|
17
|
+
debug('logon failed');
|
|
18
|
+
return { status: false, error: req.auth.error };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// create a cookie(sid) and save credentials in cache
|
|
22
|
+
const sid = uuid.v4();
|
|
23
|
+
credentials.sid = sid;
|
|
24
|
+
if (options != null) {
|
|
25
|
+
options.allAppEnv.LOGONPAYLOAD.token = credentials.token;
|
|
26
|
+
options.allAppEnv.LOGONPAYLOAD.tokenType = 'bearer';
|
|
27
|
+
debug(options.allAppEnv.LOGONPAYLOAD);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
await req.server.app.cache.set(sid, credentials, 0);
|
|
32
|
+
// Can we get away without setting cookie for this session?
|
|
33
|
+
// Need to also modify keepAlive
|
|
34
|
+
if (process.env.COOKIES !== 'NO') {
|
|
35
|
+
debugger;
|
|
36
|
+
req.cookieAuth.set({ sid });
|
|
37
|
+
};
|
|
38
|
+
debug('credentials query', credentials.query);
|
|
39
|
+
let redirect = (credentials.query != null && credentials.query.next != null) ? credentials.query.next : null;
|
|
40
|
+
debug('setcookie-redirect', redirect);
|
|
41
|
+
return { status: true, error: null , redirect: redirect};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default setCookies;
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
save for future reference - not used at this time
|
|
48
|
+
async function getCredentials (req) {
|
|
49
|
+
let route = process.env.REDIRECT == null ? `/callback` : '/' + process.env.REDIRECT;
|
|
50
|
+
let info = req.server.info;
|
|
51
|
+
let location = info.uri + route;
|
|
52
|
+
if (info.host === '0.0.0.0') {
|
|
53
|
+
location = `${info.protocol}://${process.env.APPHOST}:${info.port}${route}`;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
let payload = {
|
|
57
|
+
url : `${process.env.VIYA_SERVER}/SASLogon/oauth/token`,
|
|
58
|
+
method: 'POST',
|
|
59
|
+
|
|
60
|
+
headers: {
|
|
61
|
+
// 'Authorization': 'Basic ' + Buffer.from(`${process.env.CLIENTID}:${process.env.CLIENTSECRET}`).toString('base64'),
|
|
62
|
+
'Accept' : 'application/json',
|
|
63
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
64
|
+
},
|
|
65
|
+
data: qs.stringify({
|
|
66
|
+
client_id : `${process.env.CLIENTID}`,
|
|
67
|
+
client_secret: `${process.env.CLIENTSECRET}`,
|
|
68
|
+
redirect_uri : `${location}`,
|
|
69
|
+
|
|
70
|
+
'grant_type': 'authorization_code',
|
|
71
|
+
code : req.query.code
|
|
72
|
+
})
|
|
73
|
+
};
|
|
74
|
+
try {
|
|
75
|
+
let r = await axios(payload);
|
|
76
|
+
return r.data;
|
|
77
|
+
} catch (err) {
|
|
78
|
+
console.log(err);
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
}
|
|
80
82
|
*/
|