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.
41 lines
1.1 KiB
41 lines
1.1 KiB
2 years ago
|
using System;
|
||
|
using Microsoft.Extensions.Configuration;
|
||
|
using Volo.Abp.DependencyInjection;
|
||
|
using Win_in.Sfs.Wms.DataExchange.Authenticaitons;
|
||
|
|
||
|
namespace Win_in.Sfs.Wms.DataExchange;
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
public string GetCurrentBearer()
|
||
|
{
|
||
|
return TokenInfo.BaererToken.access_token;
|
||
|
}
|
||
|
}
|