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.
57 lines
1.5 KiB
57 lines
1.5 KiB
using System;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Volo.Abp.DependencyInjection;
|
|
using Win_in.Sfs.Wms.Pda.Authenticaitons;
|
|
|
|
namespace Win_in.Sfs.Wms.Pda;
|
|
|
|
|
|
/// <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 baseUrl = _configuration["AuthServer:Authority"];
|
|
var token = _tokenService.GetTokenAsync(baseUrl).Result;
|
|
TokenInfo.BaererToken = token;
|
|
TokenInfo.GetTime = DateTimeOffset.Now;
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取当前Token
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetCurrentBearer()
|
|
{
|
|
return TokenInfo.BaererToken.access_token;
|
|
}
|
|
}
|