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!

fix: allow guest access when OIDC or Keycloak authentication is enabled

Pavel Diptand106e97b5d67
diff --git a/src/components/Settings/AuthButtons.vue b/src/components/Settings/AuthButtons.vue
index 37a9f166..8d573390 100644
--- a/src/components/Settings/AuthButtons.vue
+++ b/src/components/Settings/AuthButtons.vue
@@ -38,8 +38,8 @@
<script>
import router from '@/router';
import { logout as registerLogout } from '@/utils/Auth';
-import { getKeycloakAuth } from '@/utils/KeycloakAuth';
-import { getOidcAuth } from '@/utils/OidcAuth';
+import { getKeycloakAuth, isKeycloakEnabled } from '@/utils/KeycloakAuth';
+import { getOidcAuth, isOidcEnabled } from '@/utils/OidcAuth';
import { localStorageKeys, userStateEnum } from '@/utils/defaults';
import IconLogout from '@/assets/interface-icons/user-logout.svg';
@@ -79,7 +79,15 @@ export default {
}, 500);
},
goToLogin() {
- router.push({ path: '/login' });
+ if (isOidcEnabled()) {
+ const oidc = getOidcAuth();
+ oidc.userManager.signinRedirect();
+ } else if (isKeycloakEnabled()) {
+ const keycloak = getKeycloakAuth();
+ keycloak.keycloakClient.login(keycloak.loginOptions);
+ } else {
+ router.push({ path: '/login' });
+ }
},
tooltip(content) {
return { content, trigger: 'hover focus', delay: 250 };
diff --git a/src/utils/Auth.js b/src/utils/Auth.js
index 705da8b4..bc5476e3 100644
--- a/src/utils/Auth.js
+++ b/src/utils/Auth.js
@@ -120,7 +120,7 @@ export const isAuthEnabled = () => {
/* Returns true if guest access is enabled */
export const isGuestAccessEnabled = () => {
const appConfig = getAppConfig();
- if (appConfig.auth && typeof appConfig.auth === 'object' && !isKeycloakEnabled() && !isOidcEnabled()) {
+ if (appConfig.auth && typeof appConfig.auth === 'object') {
return appConfig.auth.enableGuestAccess || false;
}
return false;
@@ -255,8 +255,16 @@ export const getUserState = () => {
keycloakEnabled,
oidcEnabled,
} = userStateEnum; // Numeric enum options
- if (isKeycloakEnabled()) return keycloakEnabled; // Keycloak auth configured
- if (isOidcEnabled()) return oidcEnabled;
+ if (isKeycloakEnabled()) {
+ if (isLoggedIn()) return keycloakEnabled;
+ if (isGuestAccessEnabled()) return guestAccess;
+ return keycloakEnabled; // not logged in, no guest β€” preserve login button
+ }
+ if (isOidcEnabled()) {
+ if (isLoggedIn()) return oidcEnabled; // OIDC user logged in (show OIDC logout button)
+ if (isGuestAccessEnabled()) return guestAccess; // Guest viewing with OIDC enabled
+ return oidcEnabled; // OIDC enabled, not logged in, no guest access
+ }
if (!isAuthEnabled()) return notConfigured; // No auth enabled
if (isLoggedIn()) return loggedIn; // User is logged in
if (isGuestAccessEnabled()) return guestAccess; // Guest is viewing
diff --git a/src/utils/KeycloakAuth.js b/src/utils/KeycloakAuth.js
index 05b6f7a6..58af0031 100644
--- a/src/utils/KeycloakAuth.js
+++ b/src/utils/KeycloakAuth.js
@@ -9,6 +9,11 @@ const getAppConfig = () => {
return config.appConfig || {};
};
+const isKeycloakGuestAccessEnabled = () => {
+ const { auth } = getAppConfig();
+ return auth && auth.enableGuestAccess;
+};
+
class KeycloakAuth {
constructor() {
const { auth } = getAppConfig();
@@ -30,6 +35,9 @@ class KeycloakAuth {
if (auth) {
this.storeKeycloakInfo();
return resolve();
+ } else if (isKeycloakGuestAccessEnabled()) {
+ // Don't redirect, allow guest access
+ return resolve();
} else {
return this.keycloakClient.login(this.loginOptions);
}
diff --git a/src/utils/OidcAuth.js b/src/utils/OidcAuth.js
index 23d0fefd..f001ba5f 100644
--- a/src/utils/OidcAuth.js
+++ b/src/utils/OidcAuth.js
@@ -10,6 +10,11 @@ const getAppConfig = () => {
return config.appConfig || {};
};
+const isOidcGuestAccessEnabled = () => {
+ const { auth } = getAppConfig();
+ return auth && auth.enableGuestAccess;
+};
+
class OidcAuth {
constructor() {
const { auth } = getAppConfig();
@@ -50,7 +55,9 @@ class OidcAuth {
const user = await this.userManager.getUser();
if (user === null) {
- await this.userManager.signinRedirect();
+ if (!isOidcGuestAccessEnabled()) {
+ await this.userManager.signinRedirect();
+ }
} else {
const { roles = [], groups = [] } = user.profile;
const info = {