I needed a way to apply a custom filter to a single action and didnt want to build authorization policys as the filters were temporary.
Ideally the examples below should rather validate a JSON Web Token (JWT), its not best practice to pass the client key and secret with each request but rather exchange these using the OAuth2 Client Credentials Flow.
Creating a filter
- Create the filter using IActionFilter or IAsyncActionFilter.
1 | namespace AuthService.Application.Filters |
- Register the filter
1 | namespace AuthService.Application.Extensions |
- Apply the filter
1 | namespace AuthService.Controllers |
- Now all PATCH requests to
/credentials/upsert
will need to include header values that match the injected options for:
Client-Id
Client-Secret