我正在使用ASP.Net Core实现Identity Server 4.我想添加声明,该声明基于在类ResourceOwnerPasswordValidator中生成的Guid,该类继承自IResourceOwnerPasswordValidator。(声明在ProfileService类中生成,该ProfileService类继承自IProfileService)。如何在这两个类之间传递参数。
public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
{
int res = verifyUser.verify(context.UserName, context.Password, context.Request.Client.ClientId);
if (res == 1)
{
context.Result.Error = "Invalid User";
context.Result.ErrorDescription = "Email ID doesnot Resgistered";
return Task.CompletedTask;
}
else if (res == 2)
{
context.Result.Error = "Verify Mail";
context.Result.ErrorDescription = "Please Verify Your Mail";
return Task.CompletedTask;
}
else if (res == 4)
{
context.Result.Error = "Invalid Password";
context.Result.ErrorDescription = "Password Missmatch";
return Task.CompletedTask;
}
else
{
Guid claim=verifyUser.GetGuid(context.UserName);
//For this Guid Claim Should be added in ProfileService
context.Result = new GrantValidationResult("", authenticationMethod: context.UserName);
return Task.CompletedTask;
}
}
答案 0 :(得分:0)
Context是这两个类之间的Common参数。通过更新ResourceOwnerPasswordValidator类中的Context(根据我们的便利性来确定一个值),我们可以在另一个类(ProfileService)中使用该Guid。