首页 > 解决方案 > 如何使用 Identity 自定义登录方法

问题描述

我有一个派生自 IdentityUser 的元素,其中包含一个名为 AppId 的属性。我正在尝试自定义 SignInManager.PasswordSignInAsync,因此它包含 AppId(来自 AspNetUsers,其中 AppId = id)。

这甚至可能吗?

到目前为止我所拥有的:

public class LCUserManager
{
    public LCUserManager(IdentityDbContext context)
    {
        this.DbContext = context;
    }

    public async Task<IProfile> SignIn(int appId, string userName, string password)
    {
        IProfile result = default;
        PasswordHasher<Profile> hash = new PasswordHasher<Profile>();

        var tmp = this.DbContext.Profiles.SingleOrDefault(u => u.Active && u.AppId.Equals(appId) && u.NormalizedUserName.Equals(userName.ToNormalized()));

        if (tmp != default)
        {

        }
        else
        {

        }
    }

    public IIdentityDbContext DbContext { get; }
}

标签: c#asp.net-coreasp.net-core-identity

解决方案


推荐阅读