This commit is contained in:
Bastian Wagner
2026-07-15 14:09:28 +02:00
commit 3e5348b7ec
104 changed files with 30367 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { AuditService } from '../audit/audit.service';
import { LdapAuthService } from '../lldap/ldap-auth.service';
@Injectable()
export class AuthService {
constructor(
private readonly ldapAuth: LdapAuthService,
private readonly jwt: JwtService,
private readonly audit: AuditService,
) {}
async login(username: string, password: string, ipAddress?: string, userAgent?: string) {
const valid = await this.ldapAuth.verifyPassword(username, password);
if (!valid) {
await this.audit.record({ type: 'auth.login_failed', username, ipAddress, userAgent });
throw new UnauthorizedException('Ungueltige Zugangsdaten.');
}
await this.audit.record({ type: 'auth.login_success', username, ipAddress, userAgent });
return {
accessToken: await this.jwt.signAsync({ sub: username, username }),
user: { username },
};
}
}