You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.5 KiB
C#
39 lines
1.5 KiB
C#
using Admin.Core.Model;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Text.Encodings.Web;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Admin.Core.Extensions
|
|
{
|
|
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.Status401Unauthorized;
|
|
await Response.WriteAsync(JsonConvert.SerializeObject((new ApiResponse(StatusCode.CODE401)).MessageModel));
|
|
}
|
|
|
|
protected override async Task HandleForbiddenAsync(AuthenticationProperties properties)
|
|
{
|
|
Response.ContentType = "application/json";
|
|
Response.StatusCode = StatusCodes.Status403Forbidden;
|
|
await Response.WriteAsync(JsonConvert.SerializeObject((new ApiResponse(StatusCode.CODE403)).MessageModel));
|
|
}
|
|
|
|
}
|
|
}
|