I am trying to add a new user to db using the info i receive from google sign-in but i get errors
[Route("google-response")]
public async Task<ActionResult> GoogleResponse()
{
var google_csrf_name = "g_csrf_token";
var cookie = Request.Cookies[google_csrf_name];
if (cookie == null)
return StatusCode((int)HttpStatusCode.BadRequest);
var requestbody = Request.Form[google_csrf_name];
if (requestbody != cookie)
return StatusCode((int)HttpStatusCode.BadRequest);
var idtoken = Request.Form["credential"];
GoogleJsonWebSignature.Payload payload = await GoogleJsonWebSignature.ValidateAsync(idtoken).ConfigureAwait(false);
TempData["email"] = payload.Email;
//return Json(payload);
var user = new User { UserName = payload.Email, Email = payload.Email, IsEnabled = true, EmailConfirmed = true, DateRegister = DateTime.Now };
await _userManager.CreateAsync(user).ConfigureAwait(false);
// Sign-in the user
await _signInManager.SignInAsync(user, isPersistent: false).ConfigureAwait(false);
return RedirectToAction("Index","Home");
}
How to add new user? I have the following added in the controller:
public class HomeController : Controller
{
private SignInManager<User> _signManager;
private UserManager<User> _userManager;
public HomeController(UserManager<User> userManager, SignInManager<User> signManager)
{
_userManager = userManager;
_signManager = signManager;
}
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
please advise