-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
1767779
commit afcb384
Showing
57 changed files
with
205 additions
and
202 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
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,30 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { DynamicModule, Module, Provider } from '@nestjs/common'; | ||
import { PassportModule } from '@nestjs/passport'; | ||
import { JwtValidationAdapter } from './adapter'; | ||
import { JwtStrategy, WsJwtStrategy, XApiKeyStrategy } from './strategy'; | ||
|
||
@Module({ | ||
imports: [PassportModule], | ||
providers: [JwtStrategy, WsJwtStrategy, JwtValidationAdapter, XApiKeyStrategy], | ||
exports: [JwtValidationAdapter], | ||
}) | ||
export class AuthGuardModule {} | ||
export enum AuthGuardOptions { | ||
JWT = 'jwt', | ||
WS_JWT = 'ws-jwt', | ||
X_API_KEY = 'x-api-key', | ||
} | ||
|
||
@Module({}) | ||
export class AuthGuardModule { | ||
static register(options: AuthGuardOptions[]): DynamicModule { | ||
const providers: Provider[] = [JwtValidationAdapter]; | ||
|
||
if (options.includes(AuthGuardOptions.JWT)) providers.push(JwtStrategy); | ||
|
||
if (options.includes(AuthGuardOptions.WS_JWT)) providers.push(WsJwtStrategy); | ||
|
||
if (options.includes(AuthGuardOptions.X_API_KEY)) providers.push(XApiKeyStrategy); | ||
|
||
return { | ||
module: AuthGuardModule, | ||
imports: [PassportModule], | ||
providers, | ||
exports: [JwtValidationAdapter], | ||
}; | ||
} | ||
} |
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 +1,2 @@ | ||
export * from './x-api-key.config'; | ||
export * from './jwt-auth-guard.config'; | ||
export * from './x-api-key-auth-guard.config'; |
3 changes: 1 addition & 2 deletions
3
...src/infra/auth-guard/auth-guard.config.ts → ...uth-guard/config/jwt-auth-guard.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
2 changes: 1 addition & 1 deletion
2
...fra/auth-guard/config/x-api-key.config.ts → ...ard/config/x-api-key-auth-guard.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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export interface XApiKeyConfig { | ||
export interface XApiKeyAuthGuardConfig { | ||
ADMIN_API__ALLOWED_API_KEYS: string[]; | ||
} |
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 +1,3 @@ | ||
export * from './jwt-auth.decorator'; | ||
export * from './ws-jwt-auth.decorator'; | ||
export * from './x-api-key.decorator'; |
8 changes: 8 additions & 0 deletions
8
apps/server/src/infra/auth-guard/decorator/ws-jwt-auth.decorator.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,8 @@ | ||
import { applyDecorators, UseGuards } from '@nestjs/common'; | ||
import { WsJwtAuthGuard } from '../guard'; | ||
|
||
export const WsJwtAuthentication = () => { | ||
const decorator = applyDecorators(UseGuards(WsJwtAuthGuard)); | ||
|
||
return decorator; | ||
}; |
8 changes: 8 additions & 0 deletions
8
apps/server/src/infra/auth-guard/decorator/x-api-key.decorator.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,8 @@ | ||
import { applyDecorators, UseGuards } from '@nestjs/common'; | ||
import { XApiKeyGuard } from '../guard'; | ||
|
||
export const XApiKeyAuthentication = () => { | ||
const decorator = applyDecorators(UseGuards(XApiKeyGuard)); | ||
|
||
return decorator; | ||
}; |
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,10 +1,9 @@ | ||
export { JwtValidationAdapter } from './adapter'; | ||
export { AuthGuardModule } from './auth-guard.module'; | ||
export { AuthGuardConfig } from './auth-guard.config'; | ||
export { XApiKeyConfig } from './config'; | ||
export { CurrentUser, JWT, JwtAuthentication } from './decorator'; | ||
export { AuthGuardModule, AuthGuardOptions } from './auth-guard.module'; | ||
export { JwtAuthGuardConfig, XApiKeyAuthGuardConfig } from './config'; | ||
export { CurrentUser, JWT, JwtAuthentication, WsJwtAuthentication, XApiKeyAuthentication } from './decorator'; | ||
// JwtAuthGuard only exported because api tests still overried this guard. | ||
// Use JwtAuthentication decorator for request validation | ||
export { ApiKeyGuard, JwtAuthGuard, WsJwtAuthGuard } from './guard'; | ||
export { JwtAuthGuard, WsJwtAuthGuard, XApiKeyGuard } from './guard'; | ||
export { CreateJwtPayload, ICurrentUser, JwtPayload, StrategyType } from './interface'; | ||
export { CurrentUserBuilder, JwtPayloadFactory } from './mapper'; |
4 changes: 2 additions & 2 deletions
4
apps/server/src/infra/auth-guard/mapper/jwt-strategy-options.factory.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
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
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: 1 addition & 2 deletions
3
apps/server/src/modules/authentication/authentication-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
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
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,18 +1,18 @@ | ||
import { Configuration } from '@hpi-schul-cloud/commons'; | ||
import { JwtAuthGuardConfig } from '@infra/auth-guard'; | ||
import { Algorithm } from 'jsonwebtoken'; | ||
|
||
export interface BoardCollaborationConfig { | ||
export interface BoardCollaborationConfig extends JwtAuthGuardConfig { | ||
NEST_LOG_LEVEL: string; | ||
} | ||
|
||
const boardCollaborationConfig = { | ||
const boardCollaborationConfig: BoardCollaborationConfig = { | ||
NEST_LOG_LEVEL: Configuration.get('NEST_LOG_LEVEL') as string, | ||
|
||
// Node's process.env escapes newlines. We need to reverse it for the keys to work. | ||
// See: https://stackoverflow.com/questions/30400341/environment-variables-containing-newlines-in-node | ||
JWT_PUBLIC_KEY: (Configuration.get('JWT_PUBLIC_KEY') as string).replace(/\\n/g, '\n'), | ||
JWT_SIGNING_ALGORITHM: Configuration.get('JWT_SIGNING_ALGORITHM') as Algorithm, | ||
SC_DOMAIN: Configuration.get('SC_DOMAIN') as string, | ||
ADMIN_API__ALLOWED_API_KEYS: (Configuration.get('ADMIN_API__ALLOWED_API_KEYS') as string).split(','), | ||
}; | ||
|
||
export const config = () => boardCollaborationConfig; |
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
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
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
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
Oops, something went wrong.