I have created a class to validate my own token. Within this class I need to use a service, which I have previously added in the startup.cs
with services.AddScoped
. how can I do it ?
x.SecurityTokenValidators.Add(new DynamicKeyJwtValidationHandler());
Inside the DynamicKeyJwtValidationHandler class I need to use a service.
public class DynamicKeyJwtValidationHandler : JwtSecurityTokenHandler, ISecurityTokenValidator
{
public SecurityKey GetKeyForClaimedId(string claimedId)
{
throw new NotImplementedException();
}
public override ClaimsPrincipal ValidateToken(string token, TokenValidationParameters validationParameters, out SecurityToken validatedToken)
{
ClaimsPrincipal cp = new ClaimsPrincipal();
validatedToken = null;
try
{
cp = base.ValidateToken(token, validationParameters, out validatedToken);
} catch (Exception) {}
return cp;
}
}