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) { } /// /// 重写 才能获取到token /// /// protected override async Task 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; } }