// Post: /api/ApplicationUser/Login public async Task <IActionResult> Login(LoginModel model) { var user = await _userManager.FindByNameAsync(model.UserName); if (user != null && await _userManager.CheckPasswordAsync(user, model.Password)) { // get roles assigned to user var role = await _userManager.GetRolesAsync(user); IdentityOptions options = new IdentityOptions(); string token = AuthorizationHelper.CreateUserAuthorizationToken("UserID", user.Id, role, options, _appSettings.ClientSecret); return(Ok(new { token })); } else { return(BadRequest(new { message = "Username or password is incorrect" })); } }