Skip to content

Commit a60f55c

Browse files
committed
multiple URIs supported
1 parent 964b221 commit a60f55c

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

app/app.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ const COS_SECRET_ACCESS_KEY = process.env.cos_secret_access_key;
4040
const APPID_OAUTH_SERVER_URL= process.env.appid_oauth_server_url;
4141
const APPID_CLIENT_ID= process.env.appid_client_id;
4242
const APPID_SECRET= process.env.appid_secret;
43-
const APPID_REDIRECT_URIS=process.env.appid_redirect_uris.split(',');;
43+
const APPID_REDIRECT_URIS=process.env.appid_redirect_uris.split(',');
44+
const DEBUG_FLAG=process.env.LOCAL_DEBUG;
45+
46+
console.log(DEBUG_FLAG);
4447

4548
// Express setup, including session and passport support
4649
var app = express();
@@ -141,15 +144,15 @@ app.use(configureOIDC);
141144
// default protected route /authtest
142145
app.get('/authtest', (req, res, next) => {
143146
passport.authenticate('oidc', {
144-
redirect_uri: req.secure ? 'https' : 'http'+`://${req.headers.host}/redirect_uri`,
147+
redirect_uri: `${DEBUG_FLAG ? 'http' : 'https'}` + `://${req.headers.host}/redirect_uri`,
145148
})(req, res, next);
146149
});
147150

148151
// callback for the OpenID Connect identity provider
149152
// in the case of an error go back to authentication
150153
app.get('/redirect_uri', (req, res, next) => {
151154
passport.authenticate('oidc', {
152-
redirect_uri: req.secure ? 'https' : 'http'+`://${req.headers.host}/redirect_uri`,
155+
redirect_uri: `${DEBUG_FLAG ? 'http' : 'https'}`+`://${req.headers.host}/redirect_uri`,
153156
successRedirect: '/',
154157
failureRedirect: '/authtest'
155158
})(req, res, next);
@@ -169,14 +172,24 @@ var checkAuthenticated = (req, res, next) => {
169172
//
170173

171174
// The index document already is protected
172-
app.use('/', checkAuthenticated, express.static(__dirname + '/public'));
175+
app.use('/secure', checkAuthenticated, express.static(__dirname + '/public'));
173176

174177

175178
// Makes sure that all requests to /api are authenticated
176179
app.use('/api/',checkAuthenticated , (req, res, next) => {
177180
next();
178181
});
179182

183+
// Returns all files associated to the current user
184+
app.get('/health', async function (req, res) {
185+
res.send(req.headers);
186+
});
187+
188+
app.get('/', async function (req, res) {
189+
res.redirect("/secure")
190+
});
191+
192+
180193

181194
// Returns all files associated to the current user
182195
app.get('/api/files', async function (req, res) {

app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "2.0.0",
44
"main": "app.js",
55
"scripts": {
6-
"start": "node app.js"
6+
"start": "node app.js",
7+
"dev": "LOCAL_DEBUG=true node app.js"
78
},
89
"engines": {
910
"node": ">=20"

0 commit comments

Comments
 (0)