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.
 
 
 
 
 
 

40 lines
1.1 KiB

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;
}
}