Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
feat: jwt token validation and scope checks (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwwinter authored Feb 29, 2024
1 parent 9732920 commit 078157b
Show file tree
Hide file tree
Showing 18 changed files with 385 additions and 59 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ curl -X "POST" "https://keycloak.aam-digital.net/realms/<your_realm>/protocol/op
--data-urlencode "client_id=<your_client_id>" \
--data-urlencode "client_secret=<your_client_secret>" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "scopes=openid reports_read reports_write"
--data-urlencode "scopes=openid reporting_read reporting_write"
```
Check API docs for the required "scopes".
This returns a JWT access token required to provided as Bearer Token for any request to the API endpoints. Sample token:
Expand All @@ -45,7 +45,7 @@ This returns a JWT access token required to provided as Bearer Token for any req
"refresh_expires_in": 0,
"token_type": "Bearer",
"not-before-policy": 0,
"scope": "openid reports_read reports_write"
"scope": "openid reporting_read reporting_write"
}
```

Expand Down
121 changes: 112 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@nestjs/common": "^10.3.3",
"@nestjs/config": "^3.2.0",
"@nestjs/core": "^10.3.3",
"@nestjs/jwt": "10.2.0",
"@nestjs/platform-express": "^10.3.3",
"@nestjs/schedule": "4.0.1",
"@ntegral/nestjs-sentry": "^4.0.1",
Expand Down
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ScheduleModule } from '@nestjs/schedule';
import { AppConfiguration } from './config/configuration';
import { ReportChangesModule } from './report-changes/report-changes.module';
import { NotificationModule } from './notification/notification.module';
import { AuthModule } from './auth/auth.module';

const lowSeverityLevels: SeverityLevel[] = ['log', 'info'];

Expand All @@ -35,6 +36,7 @@ const lowSeverityLevels: SeverityLevel[] = ['log', 'info'];
ignoreEnvFile: false,
load: [AppConfiguration],
}),
AuthModule,
SentryModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
Expand Down
27 changes: 27 additions & 0 deletions src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { JwtAuthGuard } from './core/jwt-auth.guard';
import { APP_GUARD } from '@nestjs/core';
import { JwtConfigurationFactory } from './core/jwt.configuration';
import { ConfigService } from '@nestjs/config';
import { HttpModule } from '@nestjs/axios';

@Module({
imports: [
HttpModule,
JwtModule.registerAsync({
global: true,
useFactory: JwtConfigurationFactory,
inject: [ConfigService],
}),
],
providers: [
JwtAuthGuard,
{
provide: APP_GUARD,
useClass: JwtAuthGuard,
},
],
exports: [JwtAuthGuard],
})
export class AuthModule {}
Loading

0 comments on commit 078157b

Please sign in to comment.