我一直试图使一个类似于.net 4.5内核的系统无法成功。我仍在尝试完全掌握核心内容,但仍认为关键项目仍然存在。我的最终目标是让一个具有自定义声明的主体返回,并使其在整个会话或内存中持续约15分钟,然后再进行重新检查。这是我似乎无法克服的问题,在互联网上搜索没有成功。
我当前代码的示例:
public class ClaimsTransformer : IClaimsTransformation
{
public Task<ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal)
{
ClaimsIdentity cidentity = (ClaimsIdentity)principal.Identity;
//IQueryable<Claim> claims = cidentity.Claims.AsQueryable();
List<Claim> claims = new List<Claim>();
cidentity.AddClaim(new Claim("TestClaimAdd", "Test Worked"));
cidentity.AddClaim(new Claim(ApplicationClaimTypes.UserID, Guid.NewGuid().ToString()));
cidentity.AddClaim(new Claim(ClaimTypes.Name, principal.Identity.Name));
claims.AddRange(cidentity.Claims);
//foreach (var claim in claims)
//{
// var name = claim.Subject.Name;
//}
//cidentity.AddClaim(new Claim("TestClaimAdd","Test Worked"));
var identity = new ClaimsIdentity(claims, "TEST", ClaimTypes.Name, ApplicationClaimTypes.ApplicationRole);
var myPrincipal = new ApplicationClaimsPrincipal(identity);
//principal.AddIdentity(identity);
return Task.FromResult((ClaimsPrincipal)myPrincipal);
}
}
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddAuthentication(IISDefaults.AuthenticationScheme);
services.AddScoped<IClaimsTransformation, ClaimsTransformer>();
}
任何帮助将不胜感激。
答案 0 :(得分:0)
我“想”您所追求的是Net Core应用程序中的Windows身份验证? Microsoft已经在框架中提供了一种执行此操作的标准方法:https://docs.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?view=aspnetcore-2.2&tabs=visual-studio