@sassoftware/viya-serverjs 0.5.3 → 0.5.5
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 +4 -3
- package/Dockerfile +37 -31
- package/lib/handlers/setCookies.js +4 -0
- package/lib/iService.js +3 -1
- package/lib/plugins/SASauth.js +7 -3
- package/lib/plugins/setDefaultRoutes.js +2 -2
- package/package.json +3 -2
- package/public/auth.html +5 -4
- package/src/handlers/setCookies.js +3 -0
- package/src/iService.js +2 -1
- package/src/plugins/SASauth.js +6 -3
- package/src/plugins/setDefaultRoutes.js +2 -2
package/.env
CHANGED
|
@@ -7,11 +7,12 @@ APPPORT=8080
|
|
|
7
7
|
APPNAME=mcpserver
|
|
8
8
|
AUTHFLOW=code
|
|
9
9
|
CLIENTID=mcpserver
|
|
10
|
-
CLIENTSECRET=jellico
|
|
11
|
-
USELOGON=
|
|
10
|
+
# CLIENTSECRET=jellico
|
|
11
|
+
USELOGON=FALSE
|
|
12
12
|
USETOKEN=TRUE
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
# REDIRECT=mcp
|
|
15
16
|
# APPDIR=./appDir
|
|
16
17
|
HTTPS=true
|
|
17
18
|
|
package/Dockerfile
CHANGED
|
@@ -8,37 +8,43 @@ RUN npm install
|
|
|
8
8
|
|
|
9
9
|
# will auto change to localhost in non-docker environments
|
|
10
10
|
ENV APPHOST=0.0.0.0
|
|
11
|
+
ENV APPLOC=./public
|
|
11
12
|
ENV PORT=8080
|
|
12
13
|
EXPOSE 8080
|
|
13
14
|
ENV HTTPS=true
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
ENV
|
|
24
|
-
ENV
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
#
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
15
|
+
|
|
16
|
+
ENV APPPORT=8080
|
|
17
|
+
ENV APPNAME=mcpserver
|
|
18
|
+
ENV AUTHFLOW=code
|
|
19
|
+
ENV CLIENTID=mcpserver
|
|
20
|
+
ENV CLIENTSECRET=jellico
|
|
21
|
+
ENV USELOGON=FALSE
|
|
22
|
+
ENV USETOKEN=TRUE
|
|
23
|
+
|
|
24
|
+
ENV SSLCERT=
|
|
25
|
+
ENV VIYACERT=
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# Most modern browsers do not accept self-signed certs from localhost
|
|
29
|
+
# Options:
|
|
30
|
+
|
|
31
|
+
# 1. provide signed certificates for localhost
|
|
32
|
+
# 2. Use libraries like mkcert to create temporary trusted certs for localhost
|
|
33
|
+
# 3. Use the app server as a proxy to the Viya server to avoid CORS issues.
|
|
34
|
+
# This requires that the app redirect all Viya API calls to the app server proxy endpoint
|
|
35
|
+
# Users of restaf can simply set the APPENV_PROXY env to TRUE to enable this behavior
|
|
36
|
+
# 4. set USETOKEN to TRUE and use the token in the APPENV object to make the calls
|
|
37
|
+
# either use the proper ssl/tsl certs or use the "proxy" method
|
|
38
|
+
# to avoid CORS issues with self-signed certs
|
|
39
|
+
# so run all apps thru the proxy and call Viya from there
|
|
40
|
+
|
|
41
|
+
ENV APPENV_PROXY=false
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# APPENV_PROXYSERVER=true
|
|
45
|
+
# USETOKEN=true
|
|
46
|
+
ENV SHOWENV=true
|
|
47
|
+
|
|
48
|
+
ENV APPENV_XYZ=AA
|
|
49
|
+
ENV APPENV_BAD=
|
|
50
|
+
CMD ["npm", "start"]
|
|
@@ -45,6 +45,9 @@ function _setCookies() {
|
|
|
45
45
|
_context.n = 1;
|
|
46
46
|
return req.server.app.cache.set(sid, credentials, 0);
|
|
47
47
|
case 1:
|
|
48
|
+
_context.n = 2;
|
|
49
|
+
return req.server.app.cache.set('credentials', credentials, 0);
|
|
50
|
+
case 2:
|
|
48
51
|
// Can we get away without setting cookie for this session?
|
|
49
52
|
// Need to also modify keepAlive
|
|
50
53
|
if (process.env.COOKIES !== 'NO') {
|
|
@@ -52,6 +55,7 @@ function _setCookies() {
|
|
|
52
55
|
req.cookieAuth.set({
|
|
53
56
|
sid: sid
|
|
54
57
|
});
|
|
58
|
+
// req.cookieAuth.set({auth: credentials});
|
|
55
59
|
}
|
|
56
60
|
;
|
|
57
61
|
debug('credentials query', credentials.query);
|
package/lib/iService.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = void 0;
|
|
8
|
+
var _console = require("console");
|
|
8
9
|
var _setupAuth = _interopRequireDefault(require("./plugins/setupAuth"));
|
|
9
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
10
11
|
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
@@ -104,7 +105,8 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
|
|
|
104
105
|
};
|
|
105
106
|
if (process.env.HAPIDEBUG === 'YES') {
|
|
106
107
|
sConfig.debug = {
|
|
107
|
-
request: '*'
|
|
108
|
+
request: '*',
|
|
109
|
+
log: '*'
|
|
108
110
|
};
|
|
109
111
|
}
|
|
110
112
|
debug(JSON.stringify(sConfig, null, 4));
|
package/lib/plugins/SASauth.js
CHANGED
|
@@ -75,6 +75,13 @@ function _iSASauth() {
|
|
|
75
75
|
return profile;
|
|
76
76
|
}()
|
|
77
77
|
};
|
|
78
|
+
// Reference: https://github.com/hapijs/bell/blob/master/lib/oauth.js
|
|
79
|
+
// for some reason the bell doc is out of date on pkce
|
|
80
|
+
|
|
81
|
+
console.log('pkce', options.pkce);
|
|
82
|
+
if (options.pkce === true) {
|
|
83
|
+
provider.pkce = 'S256';
|
|
84
|
+
}
|
|
78
85
|
bellAuthOptions = {
|
|
79
86
|
provider: provider,
|
|
80
87
|
password: uuid.v4(),
|
|
@@ -83,9 +90,6 @@ function _iSASauth() {
|
|
|
83
90
|
// isSameSite : options.isSameSite,
|
|
84
91
|
isSecure: options.isSecure
|
|
85
92
|
};
|
|
86
|
-
if (options.pkce === true) {
|
|
87
|
-
bellAuthOptions.pkce = 'S256';
|
|
88
|
-
}
|
|
89
93
|
debug('belloptions', bellAuthOptions);
|
|
90
94
|
server.log('SASAuth', bellAuthOptions);
|
|
91
95
|
_context2.n = 1;
|
|
@@ -90,8 +90,8 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
90
90
|
method: ["GET"],
|
|
91
91
|
path: "".concat(appName),
|
|
92
92
|
options: {
|
|
93
|
-
|
|
94
|
-
auth: null,
|
|
93
|
+
auth: process.env.USELOGON.toUpperCase() === 'TRUE' ? null : options.serverMode === "app" ? authLogon : authDefault,
|
|
94
|
+
// auth: null,
|
|
95
95
|
handler: function () {
|
|
96
96
|
var _handler2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(req, h) {
|
|
97
97
|
return _regenerator().w(function (_context2) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sassoftware/viya-serverjs",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "Easy to use app server for SAS Viya applications",
|
|
5
5
|
"author": "Deva Kumaraswamy <deva.kumar@sas.com>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"debug": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node --inspect-brk server.js --env=./.env.server --docker=./Dockerfile",
|
|
36
36
|
"proxy": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 node cli --env=./.env.proxy --docker=./Dockerfile",
|
|
37
37
|
"pub": "npm publish --tag alpha --access public",
|
|
38
|
-
"lint": "npx eslint --fix src/*.js"
|
|
38
|
+
"lint": "npx eslint --fix src/*.js",
|
|
39
|
+
"indocker": "npx @sassoftware/sas-score-mcp-serverjs@alpha"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"@hapi/bell": "^13.1.0",
|
package/public/auth.html
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
<!DOCTYPE html>
|
|
3
2
|
<html>
|
|
4
3
|
<body>
|
|
@@ -15,10 +14,12 @@
|
|
|
15
14
|
} catch (e) {
|
|
16
15
|
// ignore
|
|
17
16
|
}
|
|
18
|
-
// Attempt to close the popup.
|
|
19
|
-
|
|
17
|
+
// Attempt to close the popup after 5 seconds.
|
|
18
|
+
setTimeout(function() {
|
|
19
|
+
window.close();
|
|
20
|
+
}, 5000);
|
|
20
21
|
})();
|
|
21
22
|
</script>
|
|
22
23
|
<p>Server is active. You can close this window.</p>
|
|
23
24
|
</body>
|
|
24
|
-
</html
|
|
25
|
+
</html>
|
|
@@ -29,11 +29,14 @@ async function setCookies (req, h, options) {
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
await req.server.app.cache.set(sid, credentials, 0);
|
|
32
|
+
await req.server.app.cache.set('credentials', credentials, 0);
|
|
33
|
+
|
|
32
34
|
// Can we get away without setting cookie for this session?
|
|
33
35
|
// Need to also modify keepAlive
|
|
34
36
|
if (process.env.COOKIES !== 'NO') {
|
|
35
37
|
debugger;
|
|
36
38
|
req.cookieAuth.set({ sid });
|
|
39
|
+
// req.cookieAuth.set({auth: credentials});
|
|
37
40
|
};
|
|
38
41
|
debug('credentials query', credentials.query);
|
|
39
42
|
let redirect = (credentials.query != null && credentials.query.next != null) ? credentials.query.next : null;
|
package/src/iService.js
CHANGED
|
@@ -28,6 +28,7 @@ let Vision = require('@hapi/vision');
|
|
|
28
28
|
let inert = require('@hapi/inert');
|
|
29
29
|
let selfsigned = require('selfsigned');
|
|
30
30
|
|
|
31
|
+
import { log } from 'console';
|
|
31
32
|
import setupAuth from './plugins/setupAuth';
|
|
32
33
|
|
|
33
34
|
let os = require('os');
|
|
@@ -89,7 +90,7 @@ function iService(userRouteTable, useDefault, asset, allAppEnv, serverMode, user
|
|
|
89
90
|
},
|
|
90
91
|
};
|
|
91
92
|
if (process.env.HAPIDEBUG === 'YES') {
|
|
92
|
-
sConfig.debug = { request: '*' };
|
|
93
|
+
sConfig.debug = { request: '*' ,log: '*'};
|
|
93
94
|
}
|
|
94
95
|
debug(JSON.stringify(sConfig, null, 4));
|
|
95
96
|
if (process.env.HTTPS === 'true') {
|
package/src/plugins/SASauth.js
CHANGED
|
@@ -60,7 +60,13 @@ async function iSASauth (server, options) {
|
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
};
|
|
63
|
+
// Reference: https://github.com/hapijs/bell/blob/master/lib/oauth.js
|
|
64
|
+
// for some reason the bell doc is out of date on pkce
|
|
63
65
|
|
|
66
|
+
console.log('pkce', options.pkce);
|
|
67
|
+
if (options.pkce === true) {
|
|
68
|
+
provider.pkce = 'S256';
|
|
69
|
+
}
|
|
64
70
|
bellAuthOptions = {
|
|
65
71
|
provider : provider,
|
|
66
72
|
password : uuid.v4(),
|
|
@@ -70,9 +76,6 @@ async function iSASauth (server, options) {
|
|
|
70
76
|
isSecure : options.isSecure
|
|
71
77
|
};
|
|
72
78
|
|
|
73
|
-
if (options.pkce === true) {
|
|
74
|
-
bellAuthOptions.pkce = 'S256';
|
|
75
|
-
}
|
|
76
79
|
|
|
77
80
|
debug('belloptions', bellAuthOptions);
|
|
78
81
|
server.log('SASAuth',bellAuthOptions);
|
|
@@ -90,8 +90,8 @@ module.exports = function setDefaultRoutes(server, options) {
|
|
|
90
90
|
path: `${appName}`,
|
|
91
91
|
|
|
92
92
|
options: {
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
auth: (process.env.USELOGON.toUpperCase() === 'TRUE') ? null : options.serverMode === "app" ? authLogon : authDefault,
|
|
94
|
+
// auth: null,
|
|
95
95
|
handler: async (req,h) => {
|
|
96
96
|
console.log(`>>>>>>>>>>>>>>>>>>>>>>>in ${appName}`);
|
|
97
97
|
return getAppb(req, h);
|