using System; using Microsoft.Extensions.Configuration; using Volo.Abp.DependencyInjection; using Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent.Authenticaitons; namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent; 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 token = _tokenService.GetTokenAsync().Result; TokenInfo.BaererToken = token; TokenInfo.GetTime = DateTimeOffset.Now; return true; } public string GetCurrentBearer() { return TokenInfo.BaererToken.access_token; } }