Is it possible to add custom validation to each request when authenticating web api calls using a bearer token?
I\'m using the following configuration and the applicatio
To add additional logic to authenticate or validate incoming tokens:
Write a custom provider inherit from OAuthBearerAuthenticationProvider or implement IOAuthBearerAuthenticationProvider
in your custom authentication provider, override/implement ValidateIdentity(...)
and/or RequestToken(...)
to check the incoming token with each request
Use your custom provider by assigning it to the JwtBearerAuthenticationOptions.Provider property
Example:
app.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions
{
// ... other properties here
Provider = new MyCustomTokenAuthenticationProvider()
// ... other properties here
});
Write a custom token handler inherit from JwtSecurityTokenHandler
override any relevant method you like to extend (there are many!)
Use your custom token handler by assigning it to the JwtBearerAuthenticationOptions.TokenHandler property
Example:
app.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions
{
// ... other properties here
TokenHandler = new MyCustomTokenHandler()
// ... other properties here
});