I'm looking to add a database check to my JWT Token validation in an ASP.NET Core 2.2 Wep Api application.
In simple terms, after the JWT has been validated by netcore I want to then check that the corresponding "user" entity exists - if not then this should be a failed Authentication.
I've found a post that discusses additional validation, using an override of JwtSecurityTokenHandler
but there are DI issues.
The alternative seems to be creating an Authorisation policy using AuthorizationHandler<T>
overrides - but again, there are DI issues.
My question boils down to 2 parts:
- Is Authentication the right place for this check or is it Authorisation (it feels like the former, but you could argue JWT validation has already "authenticated" the caller)?
- If I use
JwtSecurityTokenHandler
orAuthorizationHandler<T>
to do my database check - using EF Core - do I have any alternative to using Service Locator (by passing a reference to theServiceProvider
into the instances created during startup in order to get a ScopedDbContext
when required)