|
|
@ -23,7 +23,6 @@ namespace AuthStudy.Authentication.Browser
|
|
|
|
/// 浏览器认证处理器:基于默认类型实现
|
|
|
|
/// 浏览器认证处理器:基于默认类型实现
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public class BrowserAuthenticationHandler : AuthenticationHandler<BrowserAuthenticationOptions>
|
|
|
|
public class BrowserAuthenticationHandler : AuthenticationHandler<BrowserAuthenticationOptions>
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public string DefaultSchemeName = BrowserAuthenticationDefault.SchemeName;
|
|
|
|
public string DefaultSchemeName = BrowserAuthenticationDefault.SchemeName;
|
|
|
|
public HttpContext? CurrentHttpContext;
|
|
|
|
public HttpContext? CurrentHttpContext;
|
|
|
@ -126,16 +125,26 @@ namespace AuthStudy.Authentication.Browser
|
|
|
|
{
|
|
|
|
{
|
|
|
|
properties?.Parameters.Add("x-itme", "无效的认证");
|
|
|
|
properties?.Parameters.Add("x-itme", "无效的认证");
|
|
|
|
|
|
|
|
|
|
|
|
CurrentHttpContext!.Response.StatusCode = 401;
|
|
|
|
if (CurrentHttpContext != null)
|
|
|
|
if (CurrentHttpContext?.Response.Body.CanWrite ?? false)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var msg = UTF8Encoding.UTF8.GetBytes("认证无效");
|
|
|
|
CurrentHttpContext.Response.StatusCode = 401;
|
|
|
|
var t = CurrentHttpContext!.Response.Body.WriteAsync(msg);
|
|
|
|
if (CurrentHttpContext?.Response.Body.CanWrite ?? false)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var msg = UTF8Encoding.UTF8.GetBytes("认证无效");
|
|
|
|
|
|
|
|
var t = CurrentHttpContext!.Response.Body.WriteAsync(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrentHttpContext!.Items.Add("认证结束时间", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CurrentHttpContext?.Items.Add("认证结束时间", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
return Task.CompletedTask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override Task InitializeHandlerAsync()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CurrentHttpContext = base.Context;
|
|
|
|
|
|
|
|
return base.InitializeHandlerAsync();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static bool IsMobile(string deviceInfo)
|
|
|
|
private static bool IsMobile(string deviceInfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool isMobile = false;
|
|
|
|
bool isMobile = false;
|
|
|
|