mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-03 21:24:49 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc108d43e3 | ||
|
|
f4a5f91cbb | ||
|
|
65f6f03e55 | ||
|
|
a54300f600 | ||
|
|
5ef85f79d3 | ||
|
|
a8a429977f | ||
|
|
692a9de0af | ||
|
|
b366e786ba | ||
|
|
24d56c7a58 |
@@ -38,7 +38,6 @@ jobs:
|
||||
with:
|
||||
semantic_version: 16
|
||||
extra_plugins: |
|
||||
@saithodev/semantic-release-backmerge
|
||||
conventional-changelog-eslint
|
||||
branches: |
|
||||
[
|
||||
|
||||
@@ -26,18 +26,6 @@
|
||||
"preset": "eslint"
|
||||
}
|
||||
],
|
||||
[
|
||||
"@saithodev/semantic-release-backmerge",
|
||||
{
|
||||
"branches": [
|
||||
{ "from": "main", "to": "alpha" },
|
||||
{ "from": "main", "to": "beta" }
|
||||
],
|
||||
"backmergeStrategy": "merge",
|
||||
"clearWorkspace": true,
|
||||
"restoreWorkspace": true
|
||||
}
|
||||
],
|
||||
"@semantic-release/npm",
|
||||
"@semantic-release/github"
|
||||
]
|
||||
|
||||
Generated
+16
-9262
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -31,7 +31,7 @@
|
||||
"@nestjs/platform-express": "^8.4.3",
|
||||
"@nestjs/schedule": "^1.1.0",
|
||||
"@nestjs/swagger": "^5.2.1",
|
||||
"@victorradael/protospack": "^1.6.5",
|
||||
"@victorradael/protospack": "1.7.4",
|
||||
"axios": "^0.25.0",
|
||||
"dotenv": "^14.2.0",
|
||||
"helmet": "^5.0.2",
|
||||
|
||||
@@ -2,11 +2,16 @@ import { OnModuleInit, Inject } from '@nestjs/common';
|
||||
import { ClientGrpc } from '@nestjs/microservices';
|
||||
|
||||
import {
|
||||
AuthConfirmationRequest,
|
||||
AuthDisableTotpMfaRequest,
|
||||
AuthEnableTotpMfaRequest,
|
||||
AuthResendConfirmationCodeRequest,
|
||||
AuthServiceInterface,
|
||||
AuthVerifyTotpMfaRequest,
|
||||
DucServicesNames,
|
||||
} from '@victorradael/protospack';
|
||||
|
||||
import { ILogin } from './interfaces';
|
||||
import { ISignIn, IRefreshAccessToken } from './interfaces';
|
||||
|
||||
export class AuthClientService implements OnModuleInit {
|
||||
private authService: AuthServiceInterface;
|
||||
@@ -20,7 +25,7 @@ export class AuthClientService implements OnModuleInit {
|
||||
);
|
||||
}
|
||||
|
||||
async signIn({ username, password, totp }: ILogin): Promise<any> {
|
||||
async signIn({ username, password, totp }: ISignIn): Promise<any> {
|
||||
console.log('AuthClientService', 'SignIn');
|
||||
|
||||
const tokens = await new Promise((resolve, reject) => {
|
||||
@@ -43,4 +48,171 @@ export class AuthClientService implements OnModuleInit {
|
||||
});
|
||||
return tokens;
|
||||
}
|
||||
|
||||
async enableTotpMFA({
|
||||
username,
|
||||
password,
|
||||
}: AuthEnableTotpMfaRequest): Promise<any> {
|
||||
console.log('AuthClientService', 'enableTotpMFA');
|
||||
|
||||
const tokens = await new Promise((resolve, reject) => {
|
||||
this.authService.enableTotpMfa({ username, password }).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
return tokens;
|
||||
}
|
||||
|
||||
async disableTotpMFA({
|
||||
username,
|
||||
password,
|
||||
totp,
|
||||
}: AuthDisableTotpMfaRequest): Promise<any> {
|
||||
console.log('AuthClientService', 'disableTotpMFA');
|
||||
|
||||
const tokens = await new Promise((resolve, reject) => {
|
||||
this.authService.disableTotpMfa({ username, password, totp }).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
return tokens;
|
||||
}
|
||||
|
||||
async verifyTotp({
|
||||
username,
|
||||
accessToken,
|
||||
totp,
|
||||
}: AuthVerifyTotpMfaRequest): Promise<any> {
|
||||
console.log('AuthClientService', 'disableTotpMFA');
|
||||
|
||||
const tokens = await new Promise((resolve, reject) => {
|
||||
this.authService.verifyTotp({ username, accessToken, totp }).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
return tokens;
|
||||
}
|
||||
|
||||
async confirmRegister({
|
||||
username,
|
||||
code,
|
||||
}: AuthConfirmationRequest): Promise<any> {
|
||||
console.log('AuthClientService', 'confirmRegister');
|
||||
|
||||
const tokens = await new Promise((resolve, reject) => {
|
||||
this.authService.confirmRegister({ username, code }).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
return tokens;
|
||||
}
|
||||
|
||||
async resendeConfirmationCode({
|
||||
username,
|
||||
}: AuthResendConfirmationCodeRequest): Promise<any> {
|
||||
console.log('AuthClientService', 'resendeConfirmationCode');
|
||||
|
||||
const authResendConfirmationCodeRequestReturn = await new Promise(
|
||||
(resolve, reject) => {
|
||||
this.authService.resendeConfirmationCode({ username }).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
},
|
||||
)
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
return authResendConfirmationCodeRequestReturn;
|
||||
}
|
||||
|
||||
async refreshAccessToken({
|
||||
username,
|
||||
refreshToken,
|
||||
}: IRefreshAccessToken): Promise<any> {
|
||||
console.log('AuthClientService', 'RefreshAccessToken');
|
||||
|
||||
const tokens = await new Promise((resolve, reject) => {
|
||||
this.authService
|
||||
.refreshAccessToken({ username, refreshToken })
|
||||
.subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
return tokens;
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+6
-1
@@ -1,5 +1,10 @@
|
||||
export interface ILogin {
|
||||
export interface ISignIn {
|
||||
username: string;
|
||||
password: string;
|
||||
totp: string;
|
||||
}
|
||||
|
||||
export interface IRefreshAccessToken {
|
||||
username: string;
|
||||
refreshToken: string;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,38 @@
|
||||
import { Body, Controller, Post, UnauthorizedException } from '@nestjs/common';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Headers,
|
||||
Post,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
AuthEnableTotpMfaRequest,
|
||||
AuthVerifyTotpMfaRequest,
|
||||
} from '@victorradael/protospack';
|
||||
|
||||
import { AuthClientService } from 'src/clients/auth/client.service';
|
||||
|
||||
interface ISignIn {
|
||||
username: string;
|
||||
password: string;
|
||||
totp: string;
|
||||
}
|
||||
import { ISignIn, IRefreshAccessToken } from 'src/clients/auth/interfaces';
|
||||
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
constructor(private authClient: AuthClientService) {}
|
||||
|
||||
// DEPRECADO!
|
||||
@Post()
|
||||
async signIn_old(@Body() body: ISignIn) {
|
||||
console.log(`/auth`, 'SignIn_old');
|
||||
|
||||
return this.signIn(body);
|
||||
}
|
||||
|
||||
@Post('login')
|
||||
async signIn_login(@Body() body: ISignIn) {
|
||||
console.log(`/auth`, 'SignIn_login');
|
||||
|
||||
return this.signIn(body);
|
||||
}
|
||||
|
||||
@Post('sign-in')
|
||||
async signIn(@Body() { username, password, totp }: ISignIn) {
|
||||
console.log(`/auth`, 'SignIn');
|
||||
|
||||
@@ -25,4 +45,56 @@ export class AuthController {
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
@Post('refresh-access-token')
|
||||
async refreshAccessToken(
|
||||
@Body() { username, refreshToken }: IRefreshAccessToken,
|
||||
) {
|
||||
console.log(`/auth`, 'RefreshAccessToken');
|
||||
|
||||
const accessToken = await this.authClient
|
||||
.refreshAccessToken({ username, refreshToken })
|
||||
.then((result) => result)
|
||||
.catch((err) => {
|
||||
throw new UnauthorizedException(err.message);
|
||||
});
|
||||
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
@Post('enable-totp')
|
||||
async enableTotpMFA(
|
||||
@Body() { username, password }: AuthEnableTotpMfaRequest,
|
||||
) {
|
||||
console.log(`/auth`, 'enable-totp');
|
||||
|
||||
const enableTotpResponse = await this.authClient
|
||||
.enableTotpMFA({ username, password })
|
||||
.then((result) => result)
|
||||
.catch((err) => {
|
||||
throw new UnauthorizedException(err.message);
|
||||
});
|
||||
|
||||
return enableTotpResponse;
|
||||
}
|
||||
|
||||
@Post('verify-totp')
|
||||
async verifyTotp(
|
||||
@Body() body: AuthVerifyTotpMfaRequest,
|
||||
@Headers() headers,
|
||||
): Promise<any> {
|
||||
console.log(`/auth`, 'enable-totp');
|
||||
|
||||
const { username, totp } = body;
|
||||
const { Authorization } = headers;
|
||||
|
||||
const enableTotpResponse = await this.authClient
|
||||
.verifyTotp({ username, totp, accessToken: Authorization })
|
||||
.then((result) => result)
|
||||
.catch((err) => {
|
||||
throw new UnauthorizedException(err.message);
|
||||
});
|
||||
|
||||
return enableTotpResponse;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user