mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 09:46:30 -05:00
refactor: move TokenAuthGuard in the same file as TokenStrategy
This should help to make clear why code is executed when the TokenAuthGuard is encountered by a request. Currently, one has to connect both files via the string 'token', which is a bit cryptic Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
5ecb0c0694
commit
216baa42a1
9 changed files with 11 additions and 18 deletions
|
@ -23,7 +23,7 @@ import {
|
||||||
ApiUnauthorizedResponse,
|
ApiUnauthorizedResponse,
|
||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
|
|
||||||
import { TokenAuthGuard } from '../../../auth/token-auth.guard';
|
import { TokenAuthGuard } from '../../../auth/token.strategy';
|
||||||
import { NotInDBError } from '../../../errors/errors';
|
import { NotInDBError } from '../../../errors/errors';
|
||||||
import { HistoryEntryUpdateDto } from '../../../history/history-entry-update.dto';
|
import { HistoryEntryUpdateDto } from '../../../history/history-entry-update.dto';
|
||||||
import { HistoryEntryDto } from '../../../history/history-entry.dto';
|
import { HistoryEntryDto } from '../../../history/history-entry.dto';
|
||||||
|
|
|
@ -31,7 +31,7 @@ import {
|
||||||
ApiUnauthorizedResponse,
|
ApiUnauthorizedResponse,
|
||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
|
|
||||||
import { TokenAuthGuard } from '../../../auth/token-auth.guard';
|
import { TokenAuthGuard } from '../../../auth/token.strategy';
|
||||||
import {
|
import {
|
||||||
ClientError,
|
ClientError,
|
||||||
MediaBackendError,
|
MediaBackendError,
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {
|
||||||
ApiUnauthorizedResponse,
|
ApiUnauthorizedResponse,
|
||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
|
|
||||||
import { TokenAuthGuard } from '../../../auth/token-auth.guard';
|
import { TokenAuthGuard } from '../../../auth/token.strategy';
|
||||||
import { MonitoringService } from '../../../monitoring/monitoring.service';
|
import { MonitoringService } from '../../../monitoring/monitoring.service';
|
||||||
import { ServerStatusDto } from '../../../monitoring/server-status.dto';
|
import { ServerStatusDto } from '../../../monitoring/server-status.dto';
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -29,7 +29,7 @@ import {
|
||||||
ApiUnauthorizedResponse,
|
ApiUnauthorizedResponse,
|
||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
|
|
||||||
import { TokenAuthGuard } from '../../../auth/token-auth.guard';
|
import { TokenAuthGuard } from '../../../auth/token.strategy';
|
||||||
import {
|
import {
|
||||||
AlreadyInDBError,
|
AlreadyInDBError,
|
||||||
ForbiddenIdError,
|
ForbiddenIdError,
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
*/
|
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { AuthGuard } from '@nestjs/passport';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class TokenAuthGuard extends AuthGuard('token') {}
|
|
|
@ -4,13 +4,16 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||||
import { PassportStrategy } from '@nestjs/passport';
|
import { AuthGuard, PassportStrategy } from '@nestjs/passport';
|
||||||
import { Strategy } from 'passport-http-bearer';
|
import { Strategy } from 'passport-http-bearer';
|
||||||
|
|
||||||
import { NotInDBError, TokenNotValidError } from '../errors/errors';
|
import { NotInDBError, TokenNotValidError } from '../errors/errors';
|
||||||
import { User } from '../users/user.entity';
|
import { User } from '../users/user.entity';
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class TokenAuthGuard extends AuthGuard('token') {}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TokenStrategy extends PassportStrategy(Strategy, 'token') {
|
export class TokenStrategy extends PassportStrategy(Strategy, 'token') {
|
||||||
constructor(private authService: AuthService) {
|
constructor(private authService: AuthService) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ import request from 'supertest';
|
||||||
import { PublicApiModule } from '../../src/api/public/public-api.module';
|
import { PublicApiModule } from '../../src/api/public/public-api.module';
|
||||||
import { AuthModule } from '../../src/auth/auth.module';
|
import { AuthModule } from '../../src/auth/auth.module';
|
||||||
import { MockAuthGuard } from '../../src/auth/mock-auth.guard';
|
import { MockAuthGuard } from '../../src/auth/mock-auth.guard';
|
||||||
import { TokenAuthGuard } from '../../src/auth/token-auth.guard';
|
import { TokenAuthGuard } from '../../src/auth/token.strategy';
|
||||||
import appConfigMock from '../../src/config/mock/app.config.mock';
|
import appConfigMock from '../../src/config/mock/app.config.mock';
|
||||||
import mediaConfigMock from '../../src/config/mock/media.config.mock';
|
import mediaConfigMock from '../../src/config/mock/media.config.mock';
|
||||||
import { GroupsModule } from '../../src/groups/groups.module';
|
import { GroupsModule } from '../../src/groups/groups.module';
|
||||||
|
|
|
@ -14,7 +14,7 @@ import request from 'supertest';
|
||||||
import { PublicApiModule } from '../../src/api/public/public-api.module';
|
import { PublicApiModule } from '../../src/api/public/public-api.module';
|
||||||
import { AuthModule } from '../../src/auth/auth.module';
|
import { AuthModule } from '../../src/auth/auth.module';
|
||||||
import { MockAuthGuard } from '../../src/auth/mock-auth.guard';
|
import { MockAuthGuard } from '../../src/auth/mock-auth.guard';
|
||||||
import { TokenAuthGuard } from '../../src/auth/token-auth.guard';
|
import { TokenAuthGuard } from '../../src/auth/token.strategy';
|
||||||
import appConfigMock from '../../src/config/mock/app.config.mock';
|
import appConfigMock from '../../src/config/mock/app.config.mock';
|
||||||
import mediaConfigMock from '../../src/config/mock/media.config.mock';
|
import mediaConfigMock from '../../src/config/mock/media.config.mock';
|
||||||
import { GroupsModule } from '../../src/groups/groups.module';
|
import { GroupsModule } from '../../src/groups/groups.module';
|
||||||
|
|
|
@ -14,7 +14,7 @@ import request from 'supertest';
|
||||||
import { PublicApiModule } from '../../src/api/public/public-api.module';
|
import { PublicApiModule } from '../../src/api/public/public-api.module';
|
||||||
import { AuthModule } from '../../src/auth/auth.module';
|
import { AuthModule } from '../../src/auth/auth.module';
|
||||||
import { MockAuthGuard } from '../../src/auth/mock-auth.guard';
|
import { MockAuthGuard } from '../../src/auth/mock-auth.guard';
|
||||||
import { TokenAuthGuard } from '../../src/auth/token-auth.guard';
|
import { TokenAuthGuard } from '../../src/auth/token.strategy';
|
||||||
import appConfigMock from '../../src/config/mock/app.config.mock';
|
import appConfigMock from '../../src/config/mock/app.config.mock';
|
||||||
import mediaConfigMock from '../../src/config/mock/media.config.mock';
|
import mediaConfigMock from '../../src/config/mock/media.config.mock';
|
||||||
import { NotInDBError } from '../../src/errors/errors';
|
import { NotInDBError } from '../../src/errors/errors';
|
||||||
|
|
Loading…
Reference in a new issue