【问题标题】:Identity Server Add Claim Based Upon the Guid Generated in ResourceOwnerPassword ValidatorIdentity Server 根据 ResourceOwnerPassword Validator 中生成的 Guid 添加声明
【发布时间】:2018-12-17 05:26:00
【问题描述】:

我正在使用 ASP.Net Core 实现 Identity Server 4。我想添加基于类 ResourceOwnerPasswordValidator 中生成的 Guid 的声明,该类继承自 IResourceOwnerPasswordValidator。(声明是在继承自的 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;
        }
    }

【问题讨论】:

标签: c# asp.net asp.net-mvc ide asp.net-identity


【解决方案1】:

上下文是这两个类之间的通用参数。通过更新 ResourceOwnerPasswordValidator 类中的上下文(根据我们的方便的任何一个值),我们可以在另一个类(ProfileService)中使用该 Guid。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-14
    • 2015-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多