You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
using System;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
namespace Win_in.Sfs.Wms.Dashboard.Host;
|
|
|
|
/// <summary>
|
|
/// 鉴权处理
|
|
/// </summary>
|
|
public class HttpAuthorizationHandler : ISingletonDependency
|
|
{
|
|
private readonly ITokenService _tokenService;
|
|
private readonly IConfiguration _configuration;
|
|
|
|
private static TokenInfo TokenInfo { get; } = new();
|
|
|
|
/// <summary>
|
|
/// 鉴权处理
|
|
/// </summary>
|
|
/// <param name="tokenService"></param>
|
|
/// <param name="configuration"></param>
|
|
public HttpAuthorizationHandler(ITokenService tokenService, IConfiguration configuration)
|
|
{
|
|
_tokenService = tokenService;
|
|
_configuration = configuration;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 是否已鉴权
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool IsLoggedIn()
|
|
{
|
|
if (!string.IsNullOrEmpty(TokenInfo.BaererToken?.access_token) &&
|
|
TokenInfo.ExpireTime > DateTimeOffset.Now)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
var token = _tokenService.GetTokenAsync().Result;
|
|
TokenInfo.BaererToken = token;
|
|
TokenInfo.GetTime = DateTimeOffset.Now;
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取当前Token
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetCurrentBearer()
|
|
{
|
|
return TokenInfo.BaererToken.access_token;
|
|
}
|
|
}
|
|
|