feat(auth): allow to disable OIDC user registration

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2024-12-03 01:22:11 +01:00
parent b24f8b0a76
commit fd1795f941
4 changed files with 80 additions and 16 deletions

View file

@ -73,29 +73,30 @@ export class OidcController {
this.logger.log('No OIDC user identifier in callback', 'callback');
throw new UnauthorizedException('No OIDC user identifier found');
}
request.session.authProviderType = ProviderType.OIDC;
const identity = await this.oidcService.getExistingOidcIdentity(
oidcIdentifier,
oidcUserIdentifier,
);
request.session.authProviderType = ProviderType.OIDC;
const mayUpdate = this.identityService.mayUpdateIdentity(oidcIdentifier);
if (identity !== null) {
const user = await identity.user;
if (mayUpdate) {
await this.usersService.updateUser(
user,
userInfo.displayName,
userInfo.email,
userInfo.photoUrl,
);
}
request.session.username = user.username;
return { url: '/' };
} else {
if (identity === null) {
request.session.newUserData = userInfo;
return { url: '/new-user' };
}
const user = await identity.user;
if (mayUpdate) {
await this.usersService.updateUser(
user,
userInfo.displayName,
userInfo.email,
userInfo.photoUrl,
);
}
request.session.username = user.username;
return { url: '/' };
} catch (error) {
if (error instanceof HttpException) {
throw error;