Skip to content

Commit

Permalink
multiple URIs supported
Browse files Browse the repository at this point in the history
  • Loading branch information
data-henrik committed Jan 15, 2024
1 parent 964b221 commit a60f55c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 17 additions & 4 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ const COS_SECRET_ACCESS_KEY = process.env.cos_secret_access_key;
const APPID_OAUTH_SERVER_URL= process.env.appid_oauth_server_url;
const APPID_CLIENT_ID= process.env.appid_client_id;
const APPID_SECRET= process.env.appid_secret;
const APPID_REDIRECT_URIS=process.env.appid_redirect_uris.split(',');;
const APPID_REDIRECT_URIS=process.env.appid_redirect_uris.split(',');
const DEBUG_FLAG=process.env.LOCAL_DEBUG;

console.log(DEBUG_FLAG);

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

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

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


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

// Returns all files associated to the current user
app.get('/health', async function (req, res) {
res.send(req.headers);
});

app.get('/', async function (req, res) {
res.redirect("/secure")
});



// Returns all files associated to the current user
app.get('/api/files', async function (req, res) {
Expand Down
3 changes: 2 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "2.0.0",
"main": "app.js",
"scripts": {
"start": "node app.js"
"start": "node app.js",
"dev": "LOCAL_DEBUG=true node app.js"
},
"engines": {
"node": ">=20"
Expand Down

0 comments on commit a60f55c

Please sign in to comment.