diff --git a/docs/widgets/services/authentik.md b/docs/widgets/services/authentik.md index f4dafd40e..3b89e087f 100644 --- a/docs/widgets/services/authentik.md +++ b/docs/widgets/services/authentik.md @@ -17,9 +17,15 @@ The account you made the API token for also needs the following **Assigned globa Allowed fields: `["users", "loginsLast24H", "failedLoginsLast24H"]`. +| Authentik Version | Homepage Widget Version | +| ----------------- | ----------------------- | +| < 2025.8.0 | 1 (default) | +| >= 2025.8.0 | 2 | + ```yaml widget: type: authentik url: http://authentik.host.or.ip:port key: api_token + version: 2 # optional, default is 1 ``` diff --git a/src/utils/config/service-helpers.js b/src/utils/config/service-helpers.js index a55fff70b..18cbe23b6 100644 --- a/src/utils/config/service-helpers.js +++ b/src/utils/config/service-helpers.js @@ -308,7 +308,7 @@ export function cleanServiceGroups(groups) { // gamedig gameToken, - // beszel, glances, immich, komga, mealie, pihole, pfsense, speedtest + // authentik, beszel, glances, immich, komga, mealie, pihole, pfsense, speedtest version, // glances @@ -518,6 +518,7 @@ export function cleanServiceGroups(groups) { } if ( [ + "authentik", "beszel", "glances", "immich", diff --git a/src/widgets/authentik/component.jsx b/src/widgets/authentik/component.jsx index edf5ece19..e82b71443 100644 --- a/src/widgets/authentik/component.jsx +++ b/src/widgets/authentik/component.jsx @@ -10,8 +10,12 @@ export default function Component({ service }) { const { widget } = service; const { data: usersData, error: usersError } = useWidgetAPI(widget, "users"); - const { data: loginsData, error: loginsError } = useWidgetAPI(widget, "login"); - const { data: failedLoginsData, error: failedLoginsError } = useWidgetAPI(widget, "login_failed"); + + const loginsEndpoint = widget.version === 2 ? "loginv2" : "login"; + const { data: loginsData, error: loginsError } = useWidgetAPI(widget, loginsEndpoint); + + const failedLoginsEndpoint = widget.version === 2 ? "login_failedv2" : "login_failed"; + const { data: failedLoginsData, error: failedLoginsError } = useWidgetAPI(widget, failedLoginsEndpoint); if (usersError || loginsError || failedLoginsError) { const finalError = usersError ?? loginsError ?? failedLoginsError; @@ -28,15 +32,29 @@ export default function Component({ service }) { ); } - const yesterday = new Date(Date.now()).setHours(-24); - const loginsLast24H = loginsData.reduce( - (total, current) => (current.x_cord >= yesterday ? total + current.y_cord : total), - 0, - ); - const failedLoginsLast24H = failedLoginsData.reduce( - (total, current) => (current.x_cord >= yesterday ? total + current.y_cord : total), - 0, - ); + let loginsLast24H; + let failedLoginsLast24H; + switch (widget.version) { + case 1: + const yesterday = new Date(Date.now()).setHours(-24); + loginsLast24H = loginsData.reduce( + (total, current) => (current.x_cord >= yesterday ? total + current.y_cord : total), + 0, + ); + failedLoginsLast24H = failedLoginsData.reduce( + (total, current) => (current.x_cord >= yesterday ? total + current.y_cord : total), + 0, + ); + break; + case 2: + if (loginsData.length > 0) { + loginsLast24H = loginsData[0]?.count || 0; + } + if (failedLoginsData.length > 0) { + failedLoginsLast24H = failedLoginsData[0]?.count || 0; + } + break; + } return ( diff --git a/src/widgets/authentik/widget.js b/src/widgets/authentik/widget.js index 7733b07be..2cc3bf88c 100644 --- a/src/widgets/authentik/widget.js +++ b/src/widgets/authentik/widget.js @@ -11,9 +11,15 @@ const widget = { login: { endpoint: "events/events/per_month/?action=login", }, + loginv2: { + endpoint: "events/events/volume/?action=login&&history_days=1", + }, login_failed: { endpoint: "events/events/per_month/?action=login_failed", }, + login_failedv2: { + endpoint: "events/events/volume/?action=login_failed&&history_days=1", + }, }, };