using System;
using Microsoft.Extensions.Configuration;
using Volo.Abp.DependencyInjection;
using Win_in.Sfs.Wms.Pda.Authenticaitons;
namespace Win_in.Sfs.Wms.Pda;
///
/// 鉴权处理
///
public class HttpAuthorizationHandler:ISingletonDependency
{
private readonly ITokenService _tokenService;
private readonly IConfiguration _configuration;
private static TokenInfo TokenInfo { get; } = new();
///
/// 鉴权处理
///
///
///
public HttpAuthorizationHandler(ITokenService tokenService,IConfiguration configuration)
{
_tokenService = tokenService;
_configuration = configuration;
}
///
/// 是否已鉴权
///
///
public bool IsLoggedIn()
{
if (!string.IsNullOrEmpty(TokenInfo.BaererToken?.access_token) &&
TokenInfo.ExpireTime > DateTimeOffset.Now)
{
return true;
}
var baseUrl = _configuration["AuthServer:Authority"];
var token = _tokenService.GetTokenAsync(baseUrl).Result;
TokenInfo.BaererToken = token;
TokenInfo.GetTime = DateTimeOffset.Now;
return true;
}
///
/// 获取当前Token
///
///
public string GetCurrentBearer()
{
return TokenInfo.BaererToken.access_token;
}
}