diff --git a/src/account/account.controller.ts b/src/account/account.controller.ts index 54f2779..1b64292 100644 --- a/src/account/account.controller.ts +++ b/src/account/account.controller.ts @@ -14,7 +14,7 @@ import { HttpCode, HttpStatus, } from '@nestjs/common'; -import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; +import { ApiSecurity, ApiTags } from '@nestjs/swagger'; import { Exception } from '../utils/exception'; import { AuthGuard } from './account.guard'; import { AccountService } from './account.service'; @@ -67,7 +67,7 @@ export class AccountController { } @Get(':akey') - @ApiBearerAuth() + @ApiSecurity('custom-auth') async findOne(@Param('akey') akey: string) { const account = await this.accountService.findOne(akey); @@ -101,7 +101,7 @@ export class AccountController { } @Patch(':akey/token') - @ApiBearerAuth() + @ApiSecurity('custom-auth') async changeToken( @Param('akey') akey: string, @Body() changeTokenDto: ChangeTokenDto, @@ -125,7 +125,7 @@ export class AccountController { } @Patch(':akey/password') - @ApiBearerAuth() + @ApiSecurity('custom-auth') async changePassword( @Param('akey') akey: string, @Body() changePasswordDto: ChangePasswordDto, diff --git a/src/logs/logs.controller.ts b/src/logs/logs.controller.ts index 5a6dfdc..68bf265 100644 --- a/src/logs/logs.controller.ts +++ b/src/logs/logs.controller.ts @@ -19,7 +19,7 @@ import { AuthGuard } from '../account/account.guard'; import { LogsGuard } from './logs.guard'; import { OwnsLog } from './decorators/owns-log.decorator'; import { SyncDto } from './dto/sync.dto'; -import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'; +import { ApiTags, ApiSecurity } from '@nestjs/swagger'; import { LogNotExistsException } from './exceptions/log-not-exists.exception'; import { LogMissingSyncDataException } from './exceptions/log-missing-sync-data.exception'; import { TYPE } from './entities/type.entity'; @@ -35,7 +35,7 @@ import { PremiumRequiredException } from '../premium/exceptions/premium-required @UseGuards(LogsGuard) @UseGuards(PremiumGuard) @ApiTags('Logs & Sync') -@ApiBearerAuth() +@ApiSecurity('custom-auth') export class LogsController { constructor(private readonly logsService: LogsService) {} diff --git a/src/main.ts b/src/main.ts index 3a043b0..bfa7556 100644 --- a/src/main.ts +++ b/src/main.ts @@ -23,7 +23,16 @@ async function bootstrap() { .setTitle('EVNotify API') .setDescription('Documentation for EVNotify API') .setVersion('3.0') - .addBearerAuth() + .addApiKey( + { + type: 'apiKey', + name: 'Authorization', + in: 'header', + description: + 'Enter your authorization string in the format: , e.g. "123456 8c6a51c82307e2b4df0c"', + }, + 'custom-auth', + ) .build(); const document = SwaggerModule.createDocument(app, config); diff --git a/src/migration/migration.module.ts b/src/migration/migration.module.ts index 5b48a7f..379dbb9 100644 --- a/src/migration/migration.module.ts +++ b/src/migration/migration.module.ts @@ -6,6 +6,7 @@ import { Log, LogSchema } from "../logs/schemas/log.schema"; import { LastSync, LastSyncSchema } from "../logs/schemas/last-sync.schema"; import { MigrationService } from "./migration.service"; import { MigrationAccount, MigrationAccountSchema } from "./schemas/migration-account.schema"; +import { PremiumModule } from "../premium/premium.module"; @Module({ controllers: [MigrationController], @@ -16,6 +17,7 @@ import { MigrationAccount, MigrationAccountSchema } from "./schemas/migration-ac { name: LastSync.name, schema: LastSyncSchema }, { name: MigrationAccount.name, schema: MigrationAccountSchema }, ]), + PremiumModule, ], }) export class MigrationModule { }; \ No newline at end of file diff --git a/src/premium/premium.controller.ts b/src/premium/premium.controller.ts index a0c289e..9c9e22c 100644 --- a/src/premium/premium.controller.ts +++ b/src/premium/premium.controller.ts @@ -1,5 +1,5 @@ import { BadRequestException, Body, ConflictException, Controller, Get, HttpCode, HttpStatus, InternalServerErrorException, Logger, NotFoundException, Param, Post, UseGuards } from "@nestjs/common"; -import { ApiBearerAuth, ApiTags } from "@nestjs/swagger"; +import { ApiSecurity, ApiTags } from "@nestjs/swagger"; import { AuthGuard } from "../account/account.guard"; import { PremiumService } from "./premium.service"; import { PremiumStatusDto } from "./dto/premium-status.dto"; @@ -19,7 +19,7 @@ export class PremiumController { ) { } @Get(':akey') - @ApiBearerAuth() + @ApiSecurity('custom-auth') async status(@Param('akey') akey: string): Promise { try { const expiryDate = await this.premiumService.getExpiryDate(akey); @@ -35,7 +35,7 @@ export class PremiumController { } @Post(':akey/redeem/ad') - @ApiBearerAuth() + @ApiSecurity('custom-auth') @HttpCode(HttpStatus.OK) async redeemAd(@Param('akey') akey: string): Promise { try { @@ -61,7 +61,7 @@ export class PremiumController { } @Post(':akey/redeem/voucher/:code') - @ApiBearerAuth() + @ApiSecurity('custom-auth') @HttpCode(HttpStatus.OK) async redeemVoucher(@Param('akey') akey: string, @Param('code') code: string): Promise { try { @@ -82,7 +82,7 @@ export class PremiumController { } @Post(':akey/redeem/subscription/:code') - @ApiBearerAuth() + @ApiSecurity('custom-auth') @HttpCode(HttpStatus.OK) async redeemSubscription(@Param('akey') akey: string, @Param('code') code: string) { try { diff --git a/src/settings/settings.controller.ts b/src/settings/settings.controller.ts index f634395..c5693ca 100644 --- a/src/settings/settings.controller.ts +++ b/src/settings/settings.controller.ts @@ -1,5 +1,5 @@ import { Controller, Get, Body, Patch, Param, UseGuards } from '@nestjs/common'; -import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; +import { ApiSecurity, ApiTags } from '@nestjs/swagger'; import { AuthGuard } from '../account/account.guard'; import { SettingsField } from './decorators/settings-field.decorator'; import { SettingDto } from './dto/setting.dto'; @@ -10,7 +10,7 @@ import { SettingsService } from './settings.service'; @UseGuards(AuthGuard) @UseGuards(SettingsGuard) @ApiTags('Settings') -@ApiBearerAuth() +@ApiSecurity('custom-auth') export class SettingsController { constructor(private readonly settingsService: SettingsService) {} diff --git a/src/stations/stations.controller.ts b/src/stations/stations.controller.ts index af3af69..97dc272 100644 --- a/src/stations/stations.controller.ts +++ b/src/stations/stations.controller.ts @@ -1,5 +1,5 @@ import { Controller, Get, HttpException, HttpStatus, InternalServerErrorException, Param, Query, UseGuards } from "@nestjs/common"; -import { ApiTags } from "@nestjs/swagger"; +import { ApiSecurity, ApiTags } from "@nestjs/swagger"; import { AuthGuard } from "src/account/account.guard"; import { StationsService } from "./stations.service"; import { ListStationsFilterDto } from "./dto/list-stations.dto"; @@ -14,6 +14,7 @@ import { RouteCalculatedRecentlyException } from "./exceptions/route-calculated- @Controller('stations') @UseGuards(AuthGuard) @UseGuards(PremiumGuard) +@ApiSecurity('custom-auth') @ApiTags('Stations') export class StationsController { constructor( diff --git a/src/tripnotify/tripnotify.controller.ts b/src/tripnotify/tripnotify.controller.ts index 49d53f3..1ddf6bc 100644 --- a/src/tripnotify/tripnotify.controller.ts +++ b/src/tripnotify/tripnotify.controller.ts @@ -1,5 +1,5 @@ import { BadRequestException, Body, Controller, Delete, ForbiddenException, Get, InternalServerErrorException, NotFoundException, Param, Post, UseGuards } from "@nestjs/common"; -import { ApiTags } from "@nestjs/swagger"; +import { ApiSecurity, ApiTags } from "@nestjs/swagger"; import { TripNotifyService } from "./tripnotify.service"; import { TripDto } from "./dto/trip.dto"; import { AuthGuard } from "src/account/account.guard"; @@ -20,6 +20,7 @@ import { TripInformationDto } from "./dto/trip-information.dto"; @Controller('trips') @UseGuards(AuthGuard) @UseGuards(PremiumGuard) +@ApiSecurity('custom-auth') @ApiTags('TripNotify') export class TripNotifyController { constructor(