Enhancement: handle authentik v2025.8.0 breaking API changes (#5687)

This commit is contained in:
shamoon
2025-08-20 13:27:21 -07:00
committed by GitHub
parent 6d7be1c7f2
commit 9a085bcb17
4 changed files with 43 additions and 12 deletions

View File

@@ -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
```

View File

@@ -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",

View File

@@ -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 (
<Container service={service}>

View File

@@ -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",
},
},
};