I am using ASPNET Core and configuring the authentication in the ConfigureServices method in the Startup.cs.
I am setting it up as follows:
services
.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(cfg =>
{
cfg.RequireHttpsMetadata = false;
cfg.SaveToken = true;
cfg.Authority = Configuration["Auth:Authority"];
cfg.Audience = Configuration["Auth:Audience"];
cfg.Events = new JwtBearerEvents
{
OnTokenValidated = context => { return Task.CompletedTask; },
OnMessageReceived = context => { return Task.CompletedTask; },
OnAuthenticationFailed = context => { return Task.CompletedTask; },
};
});
This all works fine when the project starts and I have internet connection. However, if the ASPNET Core project starts without internet connection, it will not authenticate the JWT when authentication is requested.
Does anyone have a solution for this? How do we support offline?
Thanks!