mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-23 13:59:08 +00:00
nestjs access controll mock swagger implementation middleware changes and lib permissions file back to maestro FEAT: sending permissions to duc on startup FEAT: new permissions.enum format FEAT: permissions injection (maestro -> duc) FIX: changing method invocation order FEAT: refactored permission enum + duc permission injector + grpcHandler FEAT: auth guards FEAT: seq ids updated
151 lines
4.2 KiB
TypeScript
151 lines
4.2 KiB
TypeScript
import { Logger, OnModuleInit, Inject } from '@nestjs/common';
|
|
import { ClientGrpc } from '@nestjs/microservices';
|
|
|
|
import { ProtoServices } from '@victorradael/protospack-v2/dist/lib/Duc';
|
|
import { AuthProtoService as AuthServiceInterface } from '@victorradael/protospack-v2/dist/lib/Duc/interfaces/write-service';
|
|
import {
|
|
AuthGetPublicKeysResponse,
|
|
AuthSignInRequest,
|
|
AuthSignInResponse,
|
|
AuthRefreshAccessTokenRequest,
|
|
AuthRefreshAccessTokenResponse,
|
|
AuthEnableTotpMfaRequest,
|
|
AuthEnableTotpMfaResponse,
|
|
AuthDisableTotpMfaRequest,
|
|
AuthDisableTotpMfaResponse,
|
|
AuthDismissTotpMfaRequest,
|
|
AuthDismissTotpMfaResponse,
|
|
AuthVerifyTotpMfaRequest,
|
|
AuthVerifyTotpMfaResponse,
|
|
AuthChangePasswordRequest,
|
|
AuthChangePasswordResponse,
|
|
AuthResetPasswordRequest,
|
|
AuthResetPasswordResponse,
|
|
AuthVerifyResetPasswordCodeRequest,
|
|
AuthVerifyResetPasswordCodeResponse,
|
|
AuthConfirmResetPasswordRequest,
|
|
AuthConfirmResetPasswordResponse,
|
|
} from '@victorradael/protospack-v2/dist/lib/Duc/interfaces/messages';
|
|
|
|
import grpcHandler from '../../utils/grpcHandler';
|
|
|
|
export class AuthClientService implements OnModuleInit {
|
|
private readonly logger = new Logger(AuthClientService.name);
|
|
|
|
private authService: AuthServiceInterface;
|
|
constructor(@Inject('DUC_PACKAGE') private readonly grpcClient: ClientGrpc) {}
|
|
|
|
onModuleInit() {
|
|
this.authService = this.grpcClient.getService<AuthServiceInterface>(
|
|
ProtoServices.AuthProtoService,
|
|
);
|
|
}
|
|
|
|
async getPublicKeys() {
|
|
this.logger.log('GetPublicKeys');
|
|
|
|
return grpcHandler<AuthGetPublicKeysResponse>(
|
|
this.authService.AuthGetPublicKeys({}),
|
|
);
|
|
}
|
|
|
|
async signIn({ username, password, totp }: AuthSignInRequest) {
|
|
this.logger.log('SignIn');
|
|
|
|
return grpcHandler<AuthSignInResponse>(
|
|
this.authService.AuthSignIn({ username, password, totp }),
|
|
);
|
|
}
|
|
|
|
async refreshAccessToken({ refreshToken }: AuthRefreshAccessTokenRequest) {
|
|
this.logger.log('RefreshAccessToken');
|
|
|
|
return grpcHandler<AuthRefreshAccessTokenResponse>(
|
|
this.authService.AuthRefreshAccessToken({ refreshToken }),
|
|
);
|
|
}
|
|
|
|
async changePassword({
|
|
accessToken,
|
|
oldPassword,
|
|
newPassword,
|
|
}: AuthChangePasswordRequest) {
|
|
this.logger.log('ChangePassword');
|
|
|
|
return grpcHandler<AuthChangePasswordResponse>(
|
|
this.authService.AuthChangePassword({
|
|
accessToken,
|
|
oldPassword,
|
|
newPassword,
|
|
}),
|
|
);
|
|
}
|
|
|
|
async resetPassword({ username }: AuthResetPasswordRequest) {
|
|
this.logger.log('resetPassword');
|
|
|
|
return grpcHandler<AuthResetPasswordResponse>(
|
|
this.authService.AuthResetPassword({ username }),
|
|
);
|
|
}
|
|
|
|
async verifyResetPasswordCode({
|
|
username,
|
|
code,
|
|
}: AuthVerifyResetPasswordCodeRequest) {
|
|
this.logger.log('verifyResetPasswordCode');
|
|
|
|
return grpcHandler<AuthVerifyResetPasswordCodeResponse>(
|
|
this.authService.AuthVerifyResetPasswordCode({ username, code }),
|
|
);
|
|
}
|
|
|
|
async confirmResetPassword({
|
|
username,
|
|
code,
|
|
newPassword,
|
|
}: AuthConfirmResetPasswordRequest) {
|
|
this.logger.log('confirmResetPassword');
|
|
|
|
return grpcHandler<AuthConfirmResetPasswordResponse>(
|
|
this.authService.AuthConfirmResetPassword({
|
|
username,
|
|
code,
|
|
newPassword,
|
|
}),
|
|
);
|
|
}
|
|
|
|
async enableTotpMFA({ accessToken, password }: AuthEnableTotpMfaRequest) {
|
|
this.logger.log('enableTotpMFA');
|
|
|
|
return grpcHandler<AuthEnableTotpMfaResponse>(
|
|
this.authService.AuthEnableTotpMfa({ accessToken, password }),
|
|
);
|
|
}
|
|
|
|
async disableTotpMFA({ accessToken, password }: AuthDisableTotpMfaRequest) {
|
|
this.logger.log('disableTotpMFA');
|
|
|
|
return grpcHandler<AuthDisableTotpMfaResponse>(
|
|
this.authService.AuthDisableTotpMfa({ accessToken, password }),
|
|
);
|
|
}
|
|
|
|
async dismissTotpMFA({ accessToken }: AuthDismissTotpMfaRequest) {
|
|
this.logger.log('dismissTotpMFA');
|
|
|
|
return grpcHandler<AuthDismissTotpMfaResponse>(
|
|
this.authService.AuthDismissTotpMfa({ accessToken }),
|
|
);
|
|
}
|
|
|
|
async verifyTotp({ accessToken, totp }: AuthVerifyTotpMfaRequest) {
|
|
this.logger.log('disableTotpMFA');
|
|
|
|
return grpcHandler<AuthVerifyTotpMfaResponse>(
|
|
this.authService.AuthVerifyTotpMfa({ accessToken, totp }),
|
|
);
|
|
}
|
|
}
|