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.3 KiB

2 years ago
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Volo.Abp.Http.Client.IdentityModel.Web;
using Volo.Abp.IdentityModel;
namespace Win_in.Sfs.Shared.Host;
public class SfsHttpContextIdentityModelRemoteServiceHttpClientAuthenticator :
HttpContextIdentityModelRemoteServiceHttpClientAuthenticator
{
public SfsHttpContextIdentityModelRemoteServiceHttpClientAuthenticator(
IIdentityModelAuthenticationService identityModelAuthenticationService)
: base(identityModelAuthenticationService)
{
}
/// <summary>
/// 重写 才能获取到token
/// </summary>
/// <returns></returns>
protected override async Task<string> GetAccessTokenFromHttpContextOrNullAsync()
{
var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext == null)
{
return null;
}
string token = await httpContext.GetTokenAsync(JwtBearerDefaults.AuthenticationScheme, "access_token").ConfigureAwait(false);
if (token.IsNullOrEmpty())
{
string authHeader = httpContext.Request.Headers["Authorization"];
token = authHeader?.Replace("Bearer ", "");
}
return token;
}
}