I'm currently stuck on the mechanics of how to implement a refresh token flow in aspnet5.
Goal: I want to intercept every transaction to check if the token is expired or about to expire and if so, renew it. (I'm already validating the signature of it).
I found I can discover when the expiry is expiring in Startup.cs when setting the JWT options:
app.UseJwtBearerAuthentication(options =>
{
options.Audience = "http://localhost:7001";
//options.Authority = "http://localhost:7001";
options.AutomaticAuthenticate = true;
options.RequireHttpsMetadata = false;
options.TokenValidationParameters = new TokenValidationParameters()
{
LifetimeValidator = (DateTime? notBefore, DateTime? expires, SecurityToken securityToken, TokenValidationParameters validationParameters) =>
{
if (expires.Value < DateTime.UtcNow)
{
// it's expired! issue a refresh token here?
return false;
}
return true;
},
IssuerSigningKey = key,
ValidAudience = tokenOptions.Audience,
ValidIssuer = tokenOptions.Issuer,
ValidateSignature = true,
ValidateLifetime = true,
ClockSkew = TimeSpan.FromMinutes(10)
};
});
Currently this just throws an exception that "Lifetime validator failed"..and that's where I'm at.
Am I going about this the right way? Is this the right place to be checking expiration? How specifically do I ask the API to issue a refresh token from here?