@sassoftware/viya-serverjs 0.3.0 → 0.5.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 +42 -28
- package/.env.server +32 -30
- package/.eslintignore +3 -3
- package/.eslintrc.json +42 -42
- package/Dockerfile +44 -44
- package/README.md +67 -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 +51 -53
- package/lib/iService.js +105 -103
- package/lib/index.js +25 -30
- package/lib/parseDocker.js +3 -3
- package/lib/plugins/SASauth.js +34 -34
- package/lib/plugins/appCookie.js +35 -38
- package/lib/plugins/setContext.js +22 -25
- package/lib/plugins/setDefaultRoutes.js +71 -59
- package/lib/plugins/setupAuth.js +35 -38
- package/lib/plugins/setupUserRoutes.js +17 -16
- package/lib/plugins/token.js +9 -10
- package/lib/schemes/SASTokenScheme.js +24 -27
- package/mcpServer.js +364 -0
- 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 +360 -350
- package/public/indexProxy.html +351 -351
- package/public/simplesubmit.html +233 -0
- package/server.js +363 -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 +80 -79
- package/src/iService.js +360 -345
- package/src/index.js +247 -249
- package/src/parseDocker.js +32 -32
- package/src/plugins/SASauth.js +82 -78
- package/src/plugins/appCookie.js +50 -49
- package/src/plugins/setContext.js +33 -33
- package/src/plugins/setDefaultRoutes.js +261 -253
- package/src/plugins/setupAuth.js +49 -49
- package/src/plugins/setupUserRoutes.js +48 -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/.env.proxy +0 -32
- package/tls/viyatls.sh +0 -3
|
@@ -1,253 +1,261 @@
|
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
let
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
+
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
getApp,
|
|
22
|
+
getApp2,
|
|
23
|
+
appCallback,
|
|
24
|
+
favicon,
|
|
25
|
+
keepAlive,
|
|
26
|
+
keepAlive2,
|
|
27
|
+
logout,
|
|
28
|
+
logon,
|
|
29
|
+
setupUserRoutes,
|
|
30
|
+
reactDev,
|
|
31
|
+
proxyMapUri,
|
|
32
|
+
} from "../handlers";
|
|
33
|
+
import setContext from './setContext';
|
|
34
|
+
let debug = require("debug")("routes");
|
|
35
|
+
module.exports = function setDefaultRoutes(server, options) {
|
|
36
|
+
debug("setDefaultRoutes");
|
|
37
|
+
let appName = "/" + options.appName;
|
|
38
|
+
let authDefault = false;
|
|
39
|
+
let authLogon = false;
|
|
40
|
+
if (options.authFlow === "server") {
|
|
41
|
+
authDefault =
|
|
42
|
+
options.serverMode === "app"
|
|
43
|
+
? false
|
|
44
|
+
: {
|
|
45
|
+
strategies: ["token", "session"],
|
|
46
|
+
mode: "required",
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
authLogon = {
|
|
50
|
+
mode: "required",
|
|
51
|
+
strategy: "sas",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
let getAppb = getApp.bind(
|
|
55
|
+
null,
|
|
56
|
+
(process.env.USETOKEN != null && process.env.USETOKEN.toUpperCase() === "TRUE") ? options : null
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
console.log("Default strategy", authDefault);
|
|
60
|
+
console.log("Logon strategy", authLogon);
|
|
61
|
+
options.authDefault = authDefault;
|
|
62
|
+
options.authLogon = authLogon;
|
|
63
|
+
|
|
64
|
+
debug(options.userRouteTable);
|
|
65
|
+
let uTable =
|
|
66
|
+
options.userRouteTable !== null
|
|
67
|
+
? setupUserRoutes(options.userRouteTable, options)
|
|
68
|
+
: null;
|
|
69
|
+
|
|
70
|
+
let defaultTable = [
|
|
71
|
+
{
|
|
72
|
+
method: ["GET"],
|
|
73
|
+
path: `${appName}/logon`,
|
|
74
|
+
options: {
|
|
75
|
+
|
|
76
|
+
auth: (options.authFlow === "server") ?
|
|
77
|
+
{ mode: "try", strategy: "sas" } : null,
|
|
78
|
+
//https://futurestud.io/tutorials/hapi-redirect-to-previous-page-after-login
|
|
79
|
+
// set auth to null on all protected routes
|
|
80
|
+
plugins: {
|
|
81
|
+
"hapi-auth-cookie": { redirectTo: false },
|
|
82
|
+
},
|
|
83
|
+
handler: async (req, h) => {
|
|
84
|
+
debug('logonhandler', req.auth.credentials);
|
|
85
|
+
return await logon(req, h);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
method: ["GET"],
|
|
91
|
+
path: `${appName}`,
|
|
92
|
+
|
|
93
|
+
options: {
|
|
94
|
+
auth: (process.env.USELOGON === 'YES') ? null : options.serverMode === "app" ? authLogon : authDefault,
|
|
95
|
+
handler: getAppb,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
{
|
|
100
|
+
method: ["GET"],
|
|
101
|
+
path: `${appName}/api`,
|
|
102
|
+
options: {
|
|
103
|
+
auth: authDefault,
|
|
104
|
+
handler: async (req, h) => {
|
|
105
|
+
return h.redirect(`${appName}/documentation`);
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
method: ["GET"],
|
|
111
|
+
path: `/develop`,
|
|
112
|
+
options: {
|
|
113
|
+
auth: false,
|
|
114
|
+
cors: true,
|
|
115
|
+
handler: reactDev,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
{
|
|
120
|
+
method: ["GET"],
|
|
121
|
+
path: `${appName}/callback`,
|
|
122
|
+
options: {
|
|
123
|
+
auth: authDefault,
|
|
124
|
+
handler: appCallback,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
method: ["GET"],
|
|
129
|
+
path: `${appName}/logout`,
|
|
130
|
+
options: {
|
|
131
|
+
auth: authDefault,
|
|
132
|
+
handler: logout,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
method: ["GET", "POST"],
|
|
137
|
+
path: `${appName}/keepAlive`,
|
|
138
|
+
|
|
139
|
+
options: {
|
|
140
|
+
auth: authDefault,
|
|
141
|
+
handler: keepAlive,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
method: ["GET"],
|
|
146
|
+
path: `${appName}/appenv`,
|
|
147
|
+
options: {
|
|
148
|
+
auth: /*authDefault*/ false,
|
|
149
|
+
handler: async (req, h) => {
|
|
150
|
+
let allAppEnv = options.allAppEnv;
|
|
151
|
+
if (options.userInfo != null) {
|
|
152
|
+
let uappenv = options.userInfo("APPENV", options);
|
|
153
|
+
if (uappenv != null) {
|
|
154
|
+
allAppEnv.APPENV = { ...allAppEnv.APPENV, ...uappenv };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
allAppEnv.credentials = options.credentials;
|
|
158
|
+
|
|
159
|
+
let s =
|
|
160
|
+
`let LOGONPAYLOAD = ${JSON.stringify(allAppEnv.LOGONPAYLOAD)};` +
|
|
161
|
+
`let APPENV = ${JSON.stringify(allAppEnv.APPENV)};`;
|
|
162
|
+
if (process.env.SHOWENV != null) {
|
|
163
|
+
console.log(s);
|
|
164
|
+
}
|
|
165
|
+
debug(s);
|
|
166
|
+
return s;
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
method: ["GET"],
|
|
172
|
+
path: `/appenv`,
|
|
173
|
+
options: {
|
|
174
|
+
auth: /*authDefault*/ false,
|
|
175
|
+
handler: async (req, h) => {
|
|
176
|
+
let allAppEnv = options.allAppEnv;
|
|
177
|
+
if (options.userInfo != null) {
|
|
178
|
+
let uappenv = options.userInfo("APPENV", options);
|
|
179
|
+
if (uappenv != null) {
|
|
180
|
+
allAppEnv.APPENV = { ...allAppEnv.APPENV, ...uappenv };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
allAppEnv.credentials = options.credentials;
|
|
184
|
+
|
|
185
|
+
let s =
|
|
186
|
+
`let LOGONPAYLOAD = ${JSON.stringify(allAppEnv.LOGONPAYLOAD)};` +
|
|
187
|
+
`let APPENV = ${JSON.stringify(allAppEnv.APPENV)};`;
|
|
188
|
+
if (process.env.SHOWENV != null) {
|
|
189
|
+
debug(options.allAppEnv);
|
|
190
|
+
|
|
191
|
+
}
|
|
192
|
+
debug(s)
|
|
193
|
+
return s;
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
/*
|
|
198
|
+
{
|
|
199
|
+
method: ["GET"],
|
|
200
|
+
path: `${appName}/{param*}`,
|
|
201
|
+
|
|
202
|
+
options: {
|
|
203
|
+
auth: authDefault,
|
|
204
|
+
handler: getApp2,
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
{
|
|
210
|
+
method: ["GET"],
|
|
211
|
+
path: `/{param*}`,
|
|
212
|
+
|
|
213
|
+
options: {
|
|
214
|
+
auth: authDefault,
|
|
215
|
+
handler: async (req, h) => {
|
|
216
|
+
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>in param');
|
|
217
|
+
return getApp2(req, h);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
method: ["GET"],
|
|
223
|
+
path: `/favicon.ico`,
|
|
224
|
+
options: {
|
|
225
|
+
auth: false,
|
|
226
|
+
handler: favicon,
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
method: ["GET", "POST"],
|
|
231
|
+
path: `${appName}/keepAlive2`,
|
|
232
|
+
options: {
|
|
233
|
+
auth: authDefault,
|
|
234
|
+
handler: keepAlive2,
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
];
|
|
238
|
+
|
|
239
|
+
let pr = {
|
|
240
|
+
method: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
241
|
+
path: `${appName}/proxy/{param*}`,
|
|
242
|
+
options: {
|
|
243
|
+
handler: {
|
|
244
|
+
proxy: {
|
|
245
|
+
mapUri: proxyMapUri,
|
|
246
|
+
xforward: true,
|
|
247
|
+
passThrough: true,
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
debug(pr);
|
|
253
|
+
defaultTable.push(pr);
|
|
254
|
+
// now set pre for all default routes
|
|
255
|
+
defaultTable.forEach((r) => {
|
|
256
|
+
r.options.pre = [{method: setContext, assign: 'context'}];
|
|
257
|
+
});
|
|
258
|
+
let routeTables =
|
|
259
|
+
uTable !== null ? defaultTable.concat(uTable) : defaultTable;
|
|
260
|
+
server.route(routeTables);
|
|
261
|
+
};
|
package/src/plugins/setupAuth.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
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
|
-
|
|
19
|
-
let SASauth = require('./SASauth');
|
|
20
|
-
let appCookie = require('./appCookie');
|
|
21
|
-
let token = require('./token');
|
|
22
|
-
let setDefaultRoutes = require('./setDefaultRoutes');
|
|
23
|
-
let log = require('debug')('auth');
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/** Notes:
|
|
27
|
-
* If api then register sasAuth and token - no cookies
|
|
28
|
-
* If app, then register sasAuth and cookie(session) but no token
|
|
29
|
-
*/
|
|
30
|
-
async function setupAuth (server, options){
|
|
31
|
-
|
|
32
|
-
if (options.authFlow === 'server') {
|
|
33
|
-
await server.register({plugin: SASauth, options: options});
|
|
34
|
-
// await server.register({plugin: appCookie, options: options});
|
|
35
|
-
await appCookie(server,options);
|
|
36
|
-
|
|
37
|
-
let def = 'session';
|
|
38
|
-
if (options.serverMode === 'api') {
|
|
39
|
-
await server.register({ plugin: token });
|
|
40
|
-
def = 'token';
|
|
41
|
-
}
|
|
42
|
-
log('***********************Default auth', def);
|
|
43
|
-
server.auth.default(def);
|
|
44
|
-
// console.log(server.registerations);
|
|
45
|
-
}
|
|
46
|
-
setDefaultRoutes(server, options);
|
|
47
|
-
return true;
|
|
48
|
-
};
|
|
49
|
-
|
|
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
|
+
|
|
19
|
+
let SASauth = require('./SASauth');
|
|
20
|
+
let appCookie = require('./appCookie');
|
|
21
|
+
let token = require('./token');
|
|
22
|
+
let setDefaultRoutes = require('./setDefaultRoutes');
|
|
23
|
+
let log = require('debug')('auth');
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/** Notes:
|
|
27
|
+
* If api then register sasAuth and token - no cookies
|
|
28
|
+
* If app, then register sasAuth and cookie(session) but no token
|
|
29
|
+
*/
|
|
30
|
+
async function setupAuth (server, options){
|
|
31
|
+
|
|
32
|
+
if (options.authFlow === 'server') {
|
|
33
|
+
await server.register({plugin: SASauth, options: options});
|
|
34
|
+
// await server.register({plugin: appCookie, options: options});
|
|
35
|
+
await appCookie(server,options);
|
|
36
|
+
|
|
37
|
+
let def = 'session';
|
|
38
|
+
if (options.serverMode === 'api') {
|
|
39
|
+
await server.register({ plugin: token });
|
|
40
|
+
def = 'token';
|
|
41
|
+
}
|
|
42
|
+
log('***********************Default auth', def);
|
|
43
|
+
server.auth.default(def);
|
|
44
|
+
// console.log(server.registerations);
|
|
45
|
+
}
|
|
46
|
+
setDefaultRoutes(server, options);
|
|
47
|
+
return true;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
50
|
export default setupAuth;
|