-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
93 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
apps/server/src/modules/authentication/config/x-api-key.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface IXApiKeyConfig { | ||
ADMIN_API__ALLOWED_API_KEYS: string[]; | ||
} |
27 changes: 27 additions & 0 deletions
27
apps/server/src/modules/authentication/strategy/x-api-key.strategy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Injectable, UnauthorizedException } from '@nestjs/common'; | ||
import { PassportStrategy } from '@nestjs/passport'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import Strategy from 'passport-headerapikey'; | ||
import { IXApiKeyConfig } from '../config/x-api-key.config'; | ||
|
||
@Injectable() | ||
export class XApiKeyStrategy extends PassportStrategy(Strategy, 'api-key') { | ||
private readonly allowedApiKeys: string[]; | ||
|
||
constructor(private readonly configService: ConfigService<IXApiKeyConfig, true>) { | ||
super( | ||
{ header: 'X-API-KEY', prefix: '' }, | ||
true, | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
async (apiKey: string, done: (error: Error | null, data: boolean | null) => void) => this.validate(apiKey, done) | ||
); | ||
this.allowedApiKeys = this.configService.get<string[]>('ADMIN_API__ALLOWED_API_KEYS'); | ||
} | ||
|
||
public validate = (apiKey: string, done: (error: Error | null, data: boolean | null) => void) => { | ||
if (this.allowedApiKeys.includes(apiKey)) { | ||
done(null, true); | ||
} | ||
done(new UnauthorizedException(), null); | ||
}; | ||
} |
8 changes: 4 additions & 4 deletions
8
...ntroller/deletionExecutions.controller.ts → ...troller/deletion-executions.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...controller/deletionRequests.controller.ts → ...ontroller/deletion-requests.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { LoggerModule } from '@src/core/logger'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { DeletionRequestService } from './services/deletion-request.service'; | ||
import { DeletionRequestRepo } from './repo/deletion-request.repo'; | ||
import { AuthenticationModule } from '../authentication'; | ||
import { DeletionRequestsController } from './controller/deletion-requests.controller'; | ||
import { DeletionExecutionsController } from './controller/deletion-executions.controller'; | ||
import { IXApiKeyConfig } from '../authentication/config/x-api-key.config'; | ||
|
||
@Module({ | ||
imports: [LoggerModule], | ||
providers: [DeletionRequestService, DeletionRequestRepo], | ||
imports: [LoggerModule, AuthenticationModule], | ||
controllers: [DeletionRequestsController, DeletionExecutionsController], | ||
providers: [DeletionRequestService, DeletionRequestRepo, ConfigService<IXApiKeyConfig, true>], | ||
exports: [DeletionRequestService], | ||
}) | ||
export class DeletionModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters