.Net Core IdentityServer使用ApplicationUser的自定义表

时间:2019-07-11 04:53:51

标签: authentication asp.net-core .net-core token identityserver4

我们正在为.net核心api项目实施Identityserver身份验证。我已经实现了IdentityServer基础结构,该基础结构创建了AspNetUsers,AspNetUserRoles等表。用户被插入aspnetusers表中。我想使用我们的成员表而不是aspnetusers表。我该怎么办?

  public class ApplicationUser : IdentityUser
        {
            [Required]
            [MaxLength(200)]
            public String Name { get; set; }
        }



    [HttpPost]
            [Route("token")]
            public async Task<IActionResult> CreateToken([FromBody] LoginModel loginModel)
            {
                if (ModelState.IsValid)
                {
                    var loginResult = await signInManager.PasswordSignInAsync(loginModel.Username, loginModel.Password, isPersistent: false, lockoutOnFailure: false);

                    if (!loginResult.Succeeded)
                    {
                        return BadRequest();
                    }

                    var user = await userManager.FindByNameAsync(loginModel.Username);

Login();

                    return Ok(GetToken(user));
                }
                return BadRequest(ModelState);

            }

0 个答案:

没有答案