46 lines
1.9 KiB
46 lines
1.9 KiB
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using Newtonsoft.Json;
|
|
using System.Text.Encodings.Web;
|
|
using Znyc.CloudCar.Model.ViewModels.ReportsCallBack;
|
|
|
|
namespace Znyc.CloudCar.Auth.Policys
|
|
{
|
|
public class ApiResponseHandler : AuthenticationHandler<AuthenticationSchemeOptions>
|
|
{
|
|
public ApiResponseHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock)
|
|
{
|
|
}
|
|
|
|
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
protected override async Task HandleChallengeAsync(AuthenticationProperties properties)
|
|
{
|
|
Response.ContentType = "application/json";
|
|
//Response.StatusCode = StatusCodes.Status403Forbidden;
|
|
var response = new ResponseOutput();
|
|
response.Successed = false;
|
|
response.Code = 401;
|
|
response.Msg = "很抱歉,授权失效,请重新登录!";
|
|
await Response.WriteAsync(JsonConvert.SerializeObject(response).ToLower());
|
|
}
|
|
|
|
protected override async Task HandleForbiddenAsync(AuthenticationProperties properties)
|
|
{
|
|
Response.ContentType = "application/json";
|
|
//Response.StatusCode = StatusCodes.Status403Forbidden;
|
|
//await Response.WriteAsync(JsonConvert.SerializeObject(new ApiResponse(StatusCode.CODE403)));
|
|
|
|
var response = new ResponseOutput();
|
|
response.Successed = false;
|
|
response.Code = 401;
|
|
response.Msg = "很抱歉,授权失效,请重新登录!";
|
|
await Response.WriteAsync(JsonConvert.SerializeObject(response).ToLower());
|
|
}
|
|
|
|
}
|
|
}
|
|
|