mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-18 07:29:08 +00:00
158 lines
4.3 KiB
TypeScript
158 lines
4.3 KiB
TypeScript
import { OnModuleInit, Inject } from '@nestjs/common';
|
|
import { ClientGrpc } from '@nestjs/microservices';
|
|
import { DadosferaLogger } from 'dadosfera-logs';
|
|
|
|
import { ProtoServices } from 'protospack-v2/dist/lib/Duc';
|
|
import { AuthProtoService as AuthServiceInterface } from '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 'protospack-v2/dist/lib/Duc/interfaces/messages';
|
|
|
|
import grpcHandler from '../../utils/grpcHandler';
|
|
|
|
export class AuthClientService implements OnModuleInit {
|
|
logger: any;
|
|
|
|
private authService: AuthServiceInterface;
|
|
constructor(
|
|
@Inject(DadosferaLogger)
|
|
dadosferaLogger: DadosferaLogger,
|
|
@Inject('DUC_PACKAGE') private readonly grpcClient: ClientGrpc,
|
|
) {
|
|
this.logger = dadosferaLogger.logger;
|
|
}
|
|
|
|
onModuleInit() {
|
|
this.authService = this.grpcClient.getService<AuthServiceInterface>(
|
|
ProtoServices.AuthProtoService,
|
|
);
|
|
}
|
|
|
|
async getPublicKeys() {
|
|
this.logger.info('GetPublicKeys');
|
|
|
|
return grpcHandler<AuthGetPublicKeysResponse>(
|
|
this.authService.AuthGetPublicKeys({}),
|
|
);
|
|
}
|
|
|
|
async signIn({ username, password, totp }: AuthSignInRequest) {
|
|
this.logger.info('SignIn');
|
|
|
|
return grpcHandler<AuthSignInResponse>(
|
|
this.authService.AuthSignIn({ username, password, totp }),
|
|
);
|
|
}
|
|
|
|
async refreshAccessToken({ refreshToken }: AuthRefreshAccessTokenRequest) {
|
|
this.logger.info('RefreshAccessToken');
|
|
|
|
return grpcHandler<AuthRefreshAccessTokenResponse>(
|
|
this.authService.AuthRefreshAccessToken({ refreshToken }),
|
|
);
|
|
}
|
|
|
|
async changePassword({
|
|
accessToken,
|
|
oldPassword,
|
|
newPassword,
|
|
}: AuthChangePasswordRequest) {
|
|
this.logger.info('ChangePassword');
|
|
|
|
return grpcHandler<AuthChangePasswordResponse>(
|
|
this.authService.AuthChangePassword({
|
|
accessToken,
|
|
oldPassword,
|
|
newPassword,
|
|
}),
|
|
);
|
|
}
|
|
|
|
async resetPassword({ username }: AuthResetPasswordRequest) {
|
|
this.logger.info('resetPassword');
|
|
|
|
return grpcHandler<AuthResetPasswordResponse>(
|
|
this.authService.AuthResetPassword({ username }),
|
|
);
|
|
}
|
|
|
|
async verifyResetPasswordCode({
|
|
username,
|
|
code,
|
|
}: AuthVerifyResetPasswordCodeRequest) {
|
|
this.logger.info('verifyResetPasswordCode');
|
|
|
|
return grpcHandler<AuthVerifyResetPasswordCodeResponse>(
|
|
this.authService.AuthVerifyResetPasswordCode({ username, code }),
|
|
);
|
|
}
|
|
|
|
async confirmResetPassword({
|
|
username,
|
|
code,
|
|
newPassword,
|
|
}: AuthConfirmResetPasswordRequest) {
|
|
this.logger.info('confirmResetPassword');
|
|
|
|
return grpcHandler<AuthConfirmResetPasswordResponse>(
|
|
this.authService.AuthConfirmResetPassword({
|
|
username,
|
|
code,
|
|
newPassword,
|
|
}),
|
|
);
|
|
}
|
|
|
|
async enableTotpMFA({ accessToken, password }: AuthEnableTotpMfaRequest) {
|
|
this.logger.info('enableTotpMFA');
|
|
|
|
return grpcHandler<AuthEnableTotpMfaResponse>(
|
|
this.authService.AuthEnableTotpMfa({ accessToken, password }),
|
|
);
|
|
}
|
|
|
|
async disableTotpMFA({ accessToken, password }: AuthDisableTotpMfaRequest) {
|
|
this.logger.info('disableTotpMFA');
|
|
|
|
return grpcHandler<AuthDisableTotpMfaResponse>(
|
|
this.authService.AuthDisableTotpMfa({ accessToken, password }),
|
|
);
|
|
}
|
|
|
|
async dismissTotpMFA({ accessToken }: AuthDismissTotpMfaRequest) {
|
|
this.logger.info('dismissTotpMFA');
|
|
|
|
return grpcHandler<AuthDismissTotpMfaResponse>(
|
|
this.authService.AuthDismissTotpMfa({ accessToken }),
|
|
);
|
|
}
|
|
|
|
async verifyTotp({ accessToken, totp }: AuthVerifyTotpMfaRequest) {
|
|
this.logger.info('disableTotpMFA');
|
|
|
|
return grpcHandler<AuthVerifyTotpMfaResponse>(
|
|
this.authService.AuthVerifyTotpMfa({ accessToken, totp }),
|
|
);
|
|
}
|
|
}
|