initial
This commit is contained in:
27
apps/api/src/auth/auth.service.ts
Normal file
27
apps/api/src/auth/auth.service.ts
Normal 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 },
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user