Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

πŸ›‚ Header auth goes strait to dashboard

Alicia Sykesc750a6f34b2f
diff --git a/src/router.js b/src/router.js
index 2c9ca4e5..f47d232f 100644
--- a/src/router.js
+++ b/src/router.js
@@ -156,7 +156,8 @@ router.beforeEach(async (to, from, next) => {
await store.dispatch(Keys.INITIALIZE_CONFIG, store.state.currentConfigInfo.confId);
store.commit(Keys.SET_EDIT_MODE, false);
}
- if (to.name !== 'login' && !isAuthenticated() && !isOauthCallback()) {
+ if (to.name !== 'login'
+ && !isAuthenticated() && !isOauthCallback() && !isHeaderAuthEnabled()) {
next({ name: 'login' });
} else next();
} catch (e) {
diff --git a/src/utils/auth/HeaderAuth.js b/src/utils/auth/HeaderAuth.js
index 7013023b..19bae8c8 100644
--- a/src/utils/auth/HeaderAuth.js
+++ b/src/utils/auth/HeaderAuth.js
@@ -32,16 +32,19 @@ class HeaderAuth {
reject(response.data.errorMsg);
} else {
try {
- this.users.forEach((user) => {
- if (user.user.toLowerCase() === response.data.user.toLowerCase()) {
- const strAndUpper = (input) => input.toString().toUpperCase();
- const sha = strAndUpper(sha256(strAndUpper(user.user) + strAndUpper(user.hash)));
- document.cookie = `${cookieKeys.AUTH_TOKEN}=${sha};`;
- localStorage.setItem(localStorageKeys.USERNAME, user.user);
- InfoHandler(`Successfully signed in as ${response.data.user}`, InfoKeys.AUTH);
- resolve(response.data.user);
- }
- });
+ const match = this.users.find(
+ (user) => user.user.toLowerCase() === response.data.user.toLowerCase(),
+ );
+ if (!match) {
+ reject(Error(`User '${response.data.user}' from upstream proxy was not found in conf.yml. Add an entry under appConfig.auth.users.`));
+ return;
+ }
+ const strAndUpper = (input) => input.toString().toUpperCase();
+ const sha = strAndUpper(sha256(strAndUpper(match.user) + strAndUpper(match.hash)));
+ document.cookie = `${cookieKeys.AUTH_TOKEN}=${sha}; Path=/`;
+ localStorage.setItem(localStorageKeys.USERNAME, match.user);
+ InfoHandler(`Successfully signed in as ${response.data.user}`, InfoKeys.AUTH);
+ resolve(response.data.user);
} catch (e) {
ErrorHandler('Error while trying to login using header authentication', e);
reject(e);