Skip to content

Commit

Permalink
Merge pull request #715 from openstad/fix/switch-auth-types
Browse files Browse the repository at this point in the history
fix: Remove check for e-mail
  • Loading branch information
iandebruin98 authored Jan 17, 2025
2 parents 43e6691 + 486c806 commit 2b62eb1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 26 deletions.
23 changes: 0 additions & 23 deletions apps/auth-server/middleware/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,29 +130,6 @@ exports.validate = (req, res, next) => {
next();
}

exports.checkIfEmailRequired = (req, res, next) => {
const requiredFields = req.client.requiredUserFields;
const authTypes = req.client.authTypes;

// the Local & email
const emailAuthTypesEnabled = authTypes.indexOf('Url') !== -1 ||authTypes.indexOf('Local') !== -1;
const emailRequired = requiredFields.indexOf('email') !== -1;
const fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;

// if UniqueCode isset
if (emailRequired && !req.user.email) {
if (emailAuthTypesEnabled) {
req.emailRequiredForAuth = true;
res.redirect(`/login?clientId=${req.client.clientId}&redirect_uri=${encodeURIComponent(req.query.redirect_uri)}`);
} else {
throw new Error('E-mail is required but no auth type enabled that is able to validate it properly');
}
} else {
next();
}
}


// this is an extra check to make sure a users has authenticated with an access token
// otherwise a user can access with another acces token
// not mega disaster since role is still checked
Expand Down
6 changes: 3 additions & 3 deletions apps/auth-server/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ module.exports = function (app) {
app.post('/password', clientMw.withOne, authMw.check, csrfProtection, addCsrfGlobal, userMw.validatePassword, userController.postAccount);

app.use('/auth/required-fields', [authMw.check, clientMw.withOne]);
app.get('/auth/required-fields', clientMw.withOne, csrfProtection, addCsrfGlobal, clientMw.checkIfEmailRequired, authRequiredFields.index);
app.get('/auth/required-fields', clientMw.withOne, csrfProtection, addCsrfGlobal, authRequiredFields.index);
app.post('/auth/required-fields', clientMw.withOne, csrfProtection, addCsrfGlobal, authRequiredFields.post);

app.use('/auth/two-factor', [authMw.check, clientMw.withOne]);
app.get('/auth/two-factor', clientMw.withOne, csrfProtection, addCsrfGlobal, clientMw.checkIfEmailRequired, authTwoFactor.index);
app.get('/auth/two-factor', clientMw.withOne, csrfProtection, addCsrfGlobal, authTwoFactor.index);
app.post('/auth/two-factor', clientMw.withOne, csrfProtection, addCsrfGlobal, authTwoFactor.post);
app.get('/auth/two-factor/configure', clientMw.withOne, csrfProtection, addCsrfGlobal, clientMw.checkIfEmailRequired, authTwoFactor.configure);
app.get('/auth/two-factor/configure', clientMw.withOne, csrfProtection, addCsrfGlobal, authTwoFactor.configure);
app.post('/auth/two-factor/configure', clientMw.withOne, csrfProtection, addCsrfGlobal, authTwoFactor.configurePost);

app.use('/dialog', [bruteForce.global]);
Expand Down

0 comments on commit 2b62eb1

Please sign in to comment.