diff --git a/README.md b/README.md index 9868f3a..0dbdcb9 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ curl -X "POST" "https://keycloak.aam-digital.net/realms//protocol/op --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 TokenDecorator for any request to the API endpoints. Sample token: +This returns a JWT access token required to provided as Bearer Token for any request to the API endpoints. Sample token: ```json { "access_token": "eyJhbGciOiJSUzI...", diff --git a/src/auth/core/jwt-auth.guard.ts b/src/auth/core/jwt-auth.guard.ts index 47fad5b..b83df2f 100644 --- a/src/auth/core/jwt-auth.guard.ts +++ b/src/auth/core/jwt-auth.guard.ts @@ -6,7 +6,7 @@ import { } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { Reflector } from '@nestjs/core'; -import { Scopes } from './scope.decorator'; +import { Scopes } from './scopes.decorator'; /** * Represents a validated JwtTokenPayload diff --git a/src/auth/core/scope.decorator.ts b/src/auth/core/scope.decorator.ts deleted file mode 100644 index 6b0473d..0000000 --- a/src/auth/core/scope.decorator.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Reflector } from '@nestjs/core'; - -export const Scopes = Reflector.createDecorator(); diff --git a/src/auth/core/scopes.decorator.ts b/src/auth/core/scopes.decorator.ts new file mode 100644 index 0000000..e22c196 --- /dev/null +++ b/src/auth/core/scopes.decorator.ts @@ -0,0 +1,7 @@ +import { Reflector } from '@nestjs/core'; + +/** + * Annotate an endpoint to require a certain permission in the Auth token. + * All the values in the array are required to gain access. + */ +export const Scopes = Reflector.createDecorator(); diff --git a/src/notification/controller/webhook.controller.ts b/src/notification/controller/webhook.controller.ts index 15c1b6e..e11fa70 100644 --- a/src/notification/controller/webhook.controller.ts +++ b/src/notification/controller/webhook.controller.ts @@ -16,7 +16,7 @@ import { Webhook } from '../domain/webhook'; import { NotificationService } from '../core/notification.service'; import { CreateWebhookDto, WebhookDto } from './dtos'; import { JwtAuthGuard } from '../../auth/core/jwt-auth.guard'; -import { Scopes } from '../../auth/core/scope.decorator'; +import { Scopes } from '../../auth/core/scopes.decorator'; @Controller('/api/v1/reporting/webhook') export class WebhookController { diff --git a/src/report/controller/report-calculation.controller.ts b/src/report/controller/report-calculation.controller.ts index 41ec63b..a67baaf 100644 --- a/src/report/controller/report-calculation.controller.ts +++ b/src/report/controller/report-calculation.controller.ts @@ -17,7 +17,7 @@ import { CreateReportCalculationUseCase, } from '../core/use-cases/create-report-calculation-use-case.service'; import { JwtAuthGuard } from '../../auth/core/jwt-auth.guard'; -import { Scopes } from '../../auth/core/scope.decorator'; +import { Scopes } from '../../auth/core/scopes.decorator'; @Controller('/api/v1/reporting') export class ReportCalculationController { diff --git a/src/report/controller/report.controller.ts b/src/report/controller/report.controller.ts index 39e56dc..e24216d 100644 --- a/src/report/controller/report.controller.ts +++ b/src/report/controller/report.controller.ts @@ -18,7 +18,7 @@ import { ReportDto } from './dtos'; import { Reference } from '../../domain/reference'; import { Report } from '../../domain/report'; import { JwtAuthGuard } from '../../auth/core/jwt-auth.guard'; -import { Scopes } from '../../auth/core/scope.decorator'; +import { Scopes } from '../../auth/core/scopes.decorator'; @Controller('/api/v1/reporting') export class ReportController {