enter image description hereI am trying to implement Google sign in into my web forms page because we use G suite for business. basically I am using javascript to get the token then using ajax to post to the google api then I am looking at the HD claim to make sure they are apart of our domain and thne posting to the code behind the email and doing a lookup to get a user ID then setting the form cookie and trying to redirect to our defalut page. So we have a mvc app that I done this exact thing with and it works perfectly I just routed them to the controller. For some reason it just seems like I am not getting anything from my code behind code.
here is my javascript.
<script>
function onSignIn(googleUser) {
debugger;
const profile = googleUser.getBasicProfile();
let boolRedirectUrl = false;
const id_token = googleUser.getAuthResponse().id_token;
const pathname = window.location.pathname;
const url = window.location.href;
let redirectPath = "";
if (window.location.href.indexOf("ReturnUrl") > -1) {
boolRedirectUrl = true;
redirectPath = readQueryString("ReturnUrl");
}
const googleUrl = "https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=" + id_token;
$.ajax({
url: googleUrl,
dataType: 'json',
data: '{}',
contentType: 'application/json',
success: (data, status, xhr) => {
const domain = data.hd;
const email = data.email;
if (domain === "kimbelmechanical.com") {
$.ajax({
url: "Login.aspx/GoogleLogin",
type: "POST",
data: { 'email': email },
success: (data, status, xhr) => {
//window.location.href = "Default.aspx"
},
error: (xhr, status, error) => {
console.log("I stopeed on the call to controller " + status);
}
});
}
},
error: (xhr, status, error) => {
console.log(status);
}
});
};
function readQueryString(key) {
key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&");
var match = location.search.match(new RegExp("[?&]" + key + "=([^&]+)(&|$)"));
return match && decodeURIComponent(match[1].replace(/\+/g, " "));
}
</script>
this is my c# code behind.
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void GoogleLogin(string email)
{
string userID = "";
using (var context = new KPDataContext(KP.Common.KPConnectionString))
{
var user = context.Employees.Where(p => p.Email == email);
foreach (var e in user)
{
userID = e.Username;
}
}
if (userID != "")
{
FormsAuthentication.SetAuthCookie(userID, false);
Response.Redirect("~/Default.aspx", true);
}
}
if I redirect from the success to my default page it loads it default.aspx found but for some reason it does login.aspx?ReturnUrl=?default.aspx but stays on the login page so I am in a endless loop of loading the login page over and over.