auth: Diagnose-Log bei abgelehntem Authentik-Login
Loggt bei AccessDenied die empfangenen Gruppen + erwartete Admin-Gruppe; bei leerer Gruppenliste Hinweis auf fehlendes 'groups'-Scope-Mapping. Erleichtert die Diagnose der Authentik-Gruppensteuerung im Betrieb. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
17
src/auth.ts
17
src/auth.ts
@@ -91,9 +91,22 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
|
||||
async signIn({ user, account, profile }) {
|
||||
if (account?.provider === "authentik") {
|
||||
const email = user.email;
|
||||
if (!email) return false;
|
||||
if (!email) {
|
||||
console.warn("[auth] Authentik-Login ohne E-Mail abgelehnt.");
|
||||
return false;
|
||||
}
|
||||
const groups = extractGroups(profile);
|
||||
if (!isAdminGroupMember(groups, env.AUTHENTIK_ADMIN_GROUP)) return false;
|
||||
if (!isAdminGroupMember(groups, env.AUTHENTIK_ADMIN_GROUP)) {
|
||||
console.warn(
|
||||
`[auth] Authentik-Login abgelehnt: "${email}" ist nicht in Gruppe ` +
|
||||
`"${env.AUTHENTIK_ADMIN_GROUP}". Erhaltene Gruppen: ${JSON.stringify(groups)}` +
|
||||
(groups.length
|
||||
? ""
|
||||
: " — leer: vermutlich fehlt das 'groups'-Scope-Mapping im " +
|
||||
"Authentik-Provider (oder der 'groups'-Scope wird nicht angefragt)."),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
const u = await upsertAuthentikAdmin(email, user.name ?? null);
|
||||
user.id = u.id;
|
||||
user.role = u.rolle;
|
||||
|
||||
Reference in New Issue
Block a user