I followed a tutorial to be able to show the google profiles login whenever someone visits the webpage.
Tutorial I followed
It is not working for me and i followed the steps one by one. I didn't get any error.
Please i need this for my project.
<div id="g_id_onload"
data-client_id="943211693904-t65iccmo80ilv19gd10djijafpljtdt5.apps.googleusercontent.com"
data-login_uri='/Home/google-response'>
</div>
Controller
[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["name"] = payload.Name;
TempData["email"] = payload.Email;
return Json(payload);
}
appsettingsjson:
"GoogleAuthSettings": {
"ClientId": "???",
"ClientSecret": "???"
}
I added the following packages:
Google.Apis.Auth and Microsoft.AspNetCore.Authentication.Google