Compare commits

...
3 Commits
Author SHA1 Message Date
Gabriel Amorim 692a9de0af FEAT: add refresh token - Merge pull request #90 from dadosfera/feat/refreshToken
FEATURE: add refresh token
2022-05-11 10:37:36 -03:00
Arthur Simas b366e786ba STYLE: styling conforming to ESLint 2022-05-10 10:23:55 -03:00
Arthur Simas 24d56c7a58 FEAT: add refresh token 2022-05-09 11:47:25 -03:00
6 changed files with 78 additions and 9273 deletions
+16 -9262
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -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.2",
"axios": "^0.25.0",
"dotenv": "^14.2.0",
"helmet": "^5.0.2",
+31 -2
View File
@@ -6,7 +6,7 @@ import {
DucServicesNames,
} from '@victorradael/protospack';
import { ILogin } from './interfaces';
import { ISignIn, IRefreshAccessToken } from './interfaces';
export class AuthClientService implements OnModuleInit {
private authService: AuthServiceInterface;
@@ -20,7 +20,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 +43,33 @@ export class AuthClientService implements OnModuleInit {
});
return tokens;
}
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;
}
}
+6 -1
View File
@@ -1,5 +1,10 @@
export interface ILogin {
export interface ISignIn {
username: string;
password: string;
totp: string;
}
export interface IRefreshAccessToken {
username: string;
refreshToken: string;
}
+23 -6
View File
@@ -1,18 +1,21 @@
import { Body, Controller, Post, UnauthorizedException } from '@nestjs/common';
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(@Body() { username, password, totp }: ISignIn) {
console.log(`/auth`, 'SignIn');
@@ -25,4 +28,18 @@ 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;
}
}
+1 -1
View File
File diff suppressed because one or more lines are too long