Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-7653 - Add guard decorators and make auth guard module dynamic #5307

Merged
merged 65 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
539f32e
Switch to asymmetric signing
dyedwiper Oct 15, 2024
92dbf9d
Adjust configs
dyedwiper Oct 15, 2024
2f0b221
Fix tests
dyedwiper Oct 15, 2024
35d13fb
Make secret combination of private and public key in feathers
dyedwiper Oct 16, 2024
4f906da
Add tests
dyedwiper Oct 16, 2024
c50292b
Update typ of JWT
dyedwiper Oct 16, 2024
d14c39a
Update authConfig in tests
dyedwiper Oct 16, 2024
dda6c8e
Merge branch 'main' into BC-8019-asymmetric-jwt
dyedwiper Oct 16, 2024
0747c68
Merge branch 'BC-8019-asymmetric-jwt' of github.com:hpi-schul-cloud/s…
dyedwiper Oct 16, 2024
b09f55c
Merge branch 'main' into BC-8019-asymmetric-jwt
dyedwiper Oct 17, 2024
44821a8
Handle new lines in keys
dyedwiper Oct 17, 2024
c53d5ff
Merge branch 'BC-8019-asymmetric-jwt' of github.com:hpi-schul-cloud/s…
dyedwiper Oct 17, 2024
b3bbb70
Clean up strategy tests
dyedwiper Oct 18, 2024
d7e04f8
Use JwtModuleOptionsFactory
dyedwiper Oct 18, 2024
a8353fd
Use factory method instead of class
dyedwiper Oct 18, 2024
1376f58
Remove authConfig
dyedwiper Oct 18, 2024
8f49fe2
Remove unnecessary props in AuthGuardConfig
dyedwiper Oct 18, 2024
6bbb8b1
Add AuthGuardConfig to files-storage
dyedwiper Oct 18, 2024
75daeff
Change setting of options in authn service
dyedwiper Oct 21, 2024
b665f02
Add authn test modules
dyedwiper Oct 21, 2024
f6188ff
Fix authn service test
dyedwiper Oct 21, 2024
c5515d9
Merge branch 'main' into BC-8019-asymmetric-jwt
dyedwiper Oct 21, 2024
41fe72f
Change iss and aud of JWT
dyedwiper Oct 21, 2024
1ae5dff
Merge branch 'BC-8019-asymmetric-jwt' of github.com:hpi-schul-cloud/s…
dyedwiper Oct 21, 2024
6eb471b
Fix reading of config for other apps
dyedwiper Oct 21, 2024
9e82a8c
Add XApiKeyDecorator
bischofmax Oct 22, 2024
9b81974
Add WSJwtAuthenticationDecorator
bischofmax Oct 22, 2024
ffc33be
Change AuthGuardModule to dynamic module
bischofmax Oct 22, 2024
caae755
Fix import
bischofmax Oct 23, 2024
f0a1c5b
Only import AuthGuardModul in ServerModul
bischofmax Oct 24, 2024
1f133c3
Add JWT_SIGNING_ALGORITHM as env var
dyedwiper Oct 25, 2024
36185c6
Add check of algorithm in JWT validation
dyedwiper Oct 25, 2024
23dadda
Add check of issuer and audience in JWT validation
dyedwiper Oct 25, 2024
2d0b20a
Remove unnecessary consts
dyedwiper Oct 25, 2024
68a9764
Merge branch 'main' into BC-8019-asymmetric-jwt
dyedwiper Oct 25, 2024
f44de44
Skip broken test
dyedwiper Oct 25, 2024
1952aac
Merge branch 'BC-8019-asymmetric-jwt' into BC-7653
bischofmax Oct 25, 2024
41565fb
Add SC_Domain to preview-generator-configmap
dyedwiper Oct 25, 2024
83f0acf
Split configs
bischofmax Oct 25, 2024
6400acf
Add interface FwuLearningContentsConfig
bischofmax Oct 28, 2024
d5fcf1e
Merge branch 'BC-8019-asymmetric-jwt' into BC-7653
bischofmax Oct 28, 2024
334a78f
Merge branch 'main' into BC-8019-asymmetric-jwt
bischofmax Oct 28, 2024
a1dffd2
Merge branch 'BC-8019-asymmetric-jwt' into BC-7653
bischofmax Oct 28, 2024
c66aff6
Add values to top-level configs where forgotten
dyedwiper Oct 28, 2024
aa04b55
Merge branch 'BC-8019-asymmetric-jwt' of github.com:hpi-schul-cloud/s…
dyedwiper Oct 28, 2024
4b4c13f
Merge branch 'BC-8019-asymmetric-jwt' into BC-7653
bischofmax Oct 28, 2024
cc7ff5b
Add factory for strategy options to satisfy SonarCloud
dyedwiper Oct 29, 2024
c768092
Merge branch 'main' into BC-8019-asymmetric-jwt
dyedwiper Oct 29, 2024
e946b82
Use getOrThrow to read values from ConfigService
dyedwiper Oct 29, 2024
937130f
Define defaultMikroOrmOptions in for AdminApiServerModule separately …
dyedwiper Oct 29, 2024
2c11a11
Merge branch 'BC-8019-asymmetric-jwt' of github.com:hpi-schul-cloud/s…
dyedwiper Oct 29, 2024
014c915
Add JWT_PUBLIC_KEY to configmap of admin-api-server
dyedwiper Oct 29, 2024
7601962
Add JWT_PUBLIC_KEY to configmap of preview-generator
dyedwiper Oct 29, 2024
0933cd2
Merge branch 'main' into BC-8019-asymmetric-jwt
dyedwiper Oct 29, 2024
5c0fa9d
Merge branch 'main' into BC-8019-asymmetric-jwt
dyedwiper Oct 30, 2024
f2abf0c
Merge branch 'BC-8019-asymmetric-jwt' into BC-7653
bischofmax Oct 30, 2024
3e2dd8b
Remove JWT_PUBLIC_KEY from admin api server config map
bischofmax Oct 30, 2024
489d537
Fix import for JwtAuthGuardConfig
bischofmax Oct 30, 2024
ed0ebd6
Merge branch 'main' into BC-8019-asymmetric-jwt
bischofmax Nov 4, 2024
bb986c2
Merge branch 'BC-8019-asymmetric-jwt' into BC-7653
bischofmax Nov 4, 2024
93a14bf
Merge main
bischofmax Nov 5, 2024
45df9fd
Fix tl draw tests
bischofmax Nov 5, 2024
705b880
Merge branch 'main' into BC-7653
bischofmax Nov 5, 2024
e08bd9c
Add RabbitMQWrapperTestModule and AuthGuardModule to BoardCollaborati…
bischofmax Nov 6, 2024
b8ed599
Merge branch 'BC-7653' of github.com:hpi-schul-cloud/schulcloud-serve…
bischofmax Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions apps/server/src/infra/auth-guard/auth-guard.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export interface AuthGuardConfig {
ADMIN_API__ALLOWED_API_KEYS: string[];
JWT_AUD: string;
JWT_LIFETIME: string;
AUTHENTICATION: string;
JWT_PUBLIC_KEY: string;
}
33 changes: 26 additions & 7 deletions apps/server/src/infra/auth-guard/auth-guard.module.ts
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],
};
}
}
10 changes: 0 additions & 10 deletions apps/server/src/infra/auth-guard/config/auth-config.ts

This file was deleted.

1 change: 0 additions & 1 deletion apps/server/src/infra/auth-guard/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './auth-config';
export * from './x-api-key.config';
2 changes: 2 additions & 0 deletions apps/server/src/infra/auth-guard/decorator/index.ts
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';
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;
};
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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { AuthGuard } from '@nestjs/passport';
import { StrategyType } from '../interface';

@Injectable()
export class ApiKeyGuard extends AuthGuard(StrategyType.API_KEY) {}
export class XApiKeyGuard extends AuthGuard(StrategyType.API_KEY) {}
8 changes: 4 additions & 4 deletions apps/server/src/infra/auth-guard/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export { JwtValidationAdapter } from './adapter';
export { AuthGuardModule } from './auth-guard.module';
export { AuthGuardConfig } from './auth-guard.config';
export { XApiKeyConfig, authConfig } from './config';
export { CurrentUser, JWT, JwtAuthentication } from './decorator';
export { AuthGuardModule, AuthGuardOptions } from './auth-guard.module';
export { XApiKeyConfig } 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';
247 changes: 0 additions & 247 deletions apps/server/src/infra/auth-guard/mapper/authConfig.factory.spec.ts

This file was deleted.

Loading
Loading