mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-27 16:54:49 +00:00
156 lines
4.1 KiB
TypeScript
156 lines
4.1 KiB
TypeScript
import { OnModuleInit, Inject, Injectable } from '@nestjs/common';
|
|
import { ClientGrpc } from '@nestjs/microservices';
|
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
|
import { lastValueFrom } from 'rxjs';
|
|
|
|
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
|
import { AuthProtoService as AuthServiceInterface } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/write-service';
|
|
import {
|
|
AuthSnowflakeSignInRequest,
|
|
AuthSignInRequest,
|
|
AuthRefreshAccessTokenRequest,
|
|
AuthEnableTotpMfaRequest,
|
|
AuthDisableTotpMfaRequest,
|
|
AuthDismissTotpMfaRequest,
|
|
AuthVerifyTotpMfaRequest,
|
|
AuthChangePasswordRequest,
|
|
AuthResetPasswordRequest,
|
|
AuthVerifyResetPasswordCodeRequest,
|
|
AuthConfirmResetPasswordRequest,
|
|
} from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
|
import { DucClient } from '../duc/client.config';
|
|
import { Metadata } from '@grpc/grpc-js';
|
|
|
|
@Injectable()
|
|
export class AuthClientService implements OnModuleInit {
|
|
logger: DadosferaLogger;
|
|
|
|
private authService: AuthServiceInterface;
|
|
constructor(
|
|
@Inject(DadosferaLogger)
|
|
dadosferaLogger: DadosferaLogger,
|
|
@Inject(DucClient.name) private readonly grpcClient: ClientGrpc,
|
|
) {
|
|
this.logger = dadosferaLogger.logger;
|
|
}
|
|
|
|
onModuleInit() {
|
|
this.authService = this.grpcClient.getService<AuthServiceInterface>(
|
|
ProtoServices.AuthProtoService,
|
|
);
|
|
}
|
|
|
|
async getPublicKeys() {
|
|
this.logger.info('GetPublicKeys');
|
|
|
|
return lastValueFrom(this.authService.AuthGetPublicKeys({}));
|
|
}
|
|
|
|
async snowflakeSignIn(input: AuthSnowflakeSignInRequest) {
|
|
this.logger.info('snowflakeSignIn');
|
|
|
|
return lastValueFrom(this.authService.AuthSnowflakeSignIn(input));
|
|
}
|
|
|
|
async signIn(
|
|
{ username, password, totp }: AuthSignInRequest,
|
|
metadata: Metadata,
|
|
) {
|
|
this.logger.info('SignIn');
|
|
|
|
return lastValueFrom(
|
|
this.authService.AuthSignIn({ username, password, totp }, metadata),
|
|
);
|
|
}
|
|
|
|
async refreshAccessToken(
|
|
{ refreshToken }: AuthRefreshAccessTokenRequest,
|
|
metadata: Metadata,
|
|
) {
|
|
this.logger.info('RefreshAccessToken');
|
|
|
|
return lastValueFrom(
|
|
this.authService.AuthRefreshAccessToken({ refreshToken }, metadata),
|
|
);
|
|
}
|
|
|
|
async changePassword({
|
|
accessToken,
|
|
oldPassword,
|
|
newPassword,
|
|
}: AuthChangePasswordRequest) {
|
|
this.logger.info('ChangePassword');
|
|
|
|
return lastValueFrom(
|
|
this.authService.AuthChangePassword({
|
|
accessToken,
|
|
oldPassword,
|
|
newPassword,
|
|
}),
|
|
);
|
|
}
|
|
|
|
async resetPassword({ username }: AuthResetPasswordRequest) {
|
|
this.logger.info('resetPassword');
|
|
|
|
return lastValueFrom(this.authService.AuthResetPassword({ username }));
|
|
}
|
|
|
|
async verifyResetPasswordCode({
|
|
username,
|
|
code,
|
|
}: AuthVerifyResetPasswordCodeRequest) {
|
|
this.logger.info('verifyResetPasswordCode');
|
|
|
|
return lastValueFrom(
|
|
this.authService.AuthVerifyResetPasswordCode({ username, code }),
|
|
);
|
|
}
|
|
|
|
async confirmResetPassword({
|
|
username,
|
|
code,
|
|
newPassword,
|
|
}: AuthConfirmResetPasswordRequest) {
|
|
this.logger.info('confirmResetPassword');
|
|
|
|
return lastValueFrom(
|
|
this.authService.AuthConfirmResetPassword({
|
|
username,
|
|
code,
|
|
newPassword,
|
|
}),
|
|
);
|
|
}
|
|
|
|
async enableTotpMFA({ accessToken, password }: AuthEnableTotpMfaRequest) {
|
|
this.logger.info('enableTotpMFA');
|
|
|
|
return lastValueFrom(
|
|
this.authService.AuthEnableTotpMfa({ accessToken, password }),
|
|
);
|
|
}
|
|
|
|
async disableTotpMFA({ accessToken, password }: AuthDisableTotpMfaRequest) {
|
|
this.logger.info('disableTotpMFA');
|
|
|
|
return lastValueFrom(
|
|
this.authService.AuthDisableTotpMfa({ accessToken, password }),
|
|
);
|
|
}
|
|
|
|
async dismissTotpMFA({ accessToken }: AuthDismissTotpMfaRequest) {
|
|
this.logger.info('dismissTotpMFA');
|
|
|
|
return lastValueFrom(this.authService.AuthDismissTotpMfa({ accessToken }));
|
|
}
|
|
|
|
async verifyTotp({ accessToken, totp }: AuthVerifyTotpMfaRequest) {
|
|
this.logger.info('disableTotpMFA');
|
|
|
|
return lastValueFrom(
|
|
this.authService.AuthVerifyTotpMfa({ accessToken, totp }),
|
|
);
|
|
}
|
|
}
|