I am new to C#. I have a project using C#, ASP.NET Core 3.1 and Entity Framework.
I have done all the JWT configuration.
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[HttpPost, Route("delete/{id}")]
public async Task<ActionResult<Login>> DeleteUsuario(int id)
.
.
.
in Startup.cs
public void ConfigureServices(IServiceCollection services){
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.
.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseAuthentication();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
When the token
is not sent immediately as a response a 401
error is generated. I would like to return a json like this, when I getting this error:
{"message": "Sign in"}
How can I do it?