Skip to content

Commit

Permalink
Update Authentication_JWTSetup.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
anjoy8 committed Nov 18, 2023
1 parent b3e7fbc commit c93c3eb
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using System;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Blog.Core.Extensions
{
Expand Down Expand Up @@ -74,7 +71,7 @@ public static void AddAuthentication_JWTSetup(this IServiceCollection services)
},
OnChallenge = context =>
{
context.Response.Headers.Add("Token-Error", context.ErrorDescription);
context.Response.Headers["Token-Error"] = context.ErrorDescription;
return Task.CompletedTask;
},
OnAuthenticationFailed = context =>
Expand All @@ -88,20 +85,20 @@ public static void AddAuthentication_JWTSetup(this IServiceCollection services)
if (jwtToken.Issuer != Issuer)
{
context.Response.Headers.Add("Token-Error-Iss", "issuer is wrong!");
context.Response.Headers["Token-Error-Iss"] = "issuer is wrong!";
}
if (jwtToken.Audiences.FirstOrDefault() != Audience)
{
context.Response.Headers.Add("Token-Error-Aud", "Audience is wrong!");
context.Response.Headers["Token-Error-Aud"] = "Audience is wrong!";
}
}
// 如果过期,则把<是否过期>添加到,返回头信息中
if (context.Exception.GetType() == typeof(SecurityTokenExpiredException))
{
context.Response.Headers.Add("Token-Expired", "true");
context.Response.Headers["Token-Expired"] = "true";
}
return Task.CompletedTask;
}
Expand Down

0 comments on commit c93c3eb

Please sign in to comment.