From fdcc9fda3f627e3abf93e95e6827f66647d89612 Mon Sep 17 00:00:00 2001 From: wodka Date: Tue, 30 Jul 2019 13:03:20 +0200 Subject: [PATCH] fix api doc for auth endpoints --- api/src/auth/controllers/auth.controller.ts | 16 +++++++++++++--- api/src/auth/dto/auth.jwt.dto.ts | 9 +++++++++ api/src/auth/interfaces/auth.jwt.interface.ts | 4 ---- api/src/auth/services/auth.service.ts | 4 ++-- 4 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 api/src/auth/dto/auth.jwt.dto.ts delete mode 100644 api/src/auth/interfaces/auth.jwt.interface.ts diff --git a/api/src/auth/controllers/auth.controller.ts b/api/src/auth/controllers/auth.controller.ts index 7826dd85..64f5be1e 100644 --- a/api/src/auth/controllers/auth.controller.ts +++ b/api/src/auth/controllers/auth.controller.ts @@ -1,20 +1,30 @@ import { Controller, Request, Post, UseGuards } from '@nestjs/common'; import { AuthGuard } from '@nestjs/passport'; -import {AuthService} from "../services/auth.service" +import { AuthService } from "../services/auth.service" +import { AuthJwtDto } from "../dto/auth.jwt.dto" +import {ApiBearerAuth, ApiImplicitBody, ApiImplicitQuery, ApiResponse, ApiUseTags} from "@nestjs/swagger" +@ApiUseTags('authentication') @Controller('auth') export class AuthController { constructor(private readonly authService: AuthService) {} + @ApiResponse({ status: 201, description: 'Successful login.', type: AuthJwtDto}) + @ApiResponse({ status: 401, description: 'Invalid Credentials.'}) + @ApiImplicitQuery({name: 'username', type: String}) + @ApiImplicitQuery({name: 'password', type: String}) @UseGuards(AuthGuard('password')) @Post('login') - async login(@Request() req) { + async login(@Request() req): Promise { return this.authService.createToken(req.user); } + @ApiBearerAuth() + @ApiResponse({ status: 201, description: 'Consumed Refresh Token.', type: AuthJwtDto}) + @ApiResponse({ status: 401, description: 'Invalid Token.'}) @UseGuards(AuthGuard('jwt.refresh')) @Post('refresh') - async refresh(@Request() req) { + async refresh(@Request() req): Promise { return this.authService.createToken(req.user); } } diff --git a/api/src/auth/dto/auth.jwt.dto.ts b/api/src/auth/dto/auth.jwt.dto.ts new file mode 100644 index 00000000..7ae87476 --- /dev/null +++ b/api/src/auth/dto/auth.jwt.dto.ts @@ -0,0 +1,9 @@ +import { ApiModelProperty } from '@nestjs/swagger'; + +export class AuthJwtDto { + @ApiModelProperty() + access_token: string; + + @ApiModelProperty() + refresh_token: string; +} diff --git a/api/src/auth/interfaces/auth.jwt.interface.ts b/api/src/auth/interfaces/auth.jwt.interface.ts deleted file mode 100644 index cac955f3..00000000 --- a/api/src/auth/interfaces/auth.jwt.interface.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface AuthJwt { - access_token: string; - refresh_token: string; -} diff --git a/api/src/auth/services/auth.service.ts b/api/src/auth/services/auth.service.ts index e607da5a..4803c7e5 100644 --- a/api/src/auth/services/auth.service.ts +++ b/api/src/auth/services/auth.service.ts @@ -4,7 +4,7 @@ import { PasswordService } from "./password.service" import { JwtService } from '@nestjs/jwt'; import { AuthUser } from "../interfaces/auth.user.interface" import { User } from "../../users/interfaces/user.interface" -import {AuthJwt} from "../interfaces/auth.jwt.interface" +import {AuthJwtDto} from "../dto/auth.jwt.dto" @Injectable() export class AuthService { @@ -47,7 +47,7 @@ export class AuthService { }; } - async createToken(user: AuthUser): Promise { + async createToken(user: AuthUser): Promise { const payload = { id: user.id, username: user.username,