简体   繁体   中英

Asp.net Google Sign In

I'm trying to implement Google Sign In in my ASP.net application.
I have implemented the javascript code from Integrating Google Sign-In into your web app and that works but I need to store a Google User ID in my Database for identification in future logins.

The page states that I shouldn't use the profile.getId but I should send the googleUser.getAuthResponse().id_token to the backend and validate this token.

Well I've sent this huge bundle of characters to the backend but I can't seem to figure out how to validate this bundle of characters and retrieve a useful identification ID (which should stay the same for a Google User) from this data bundle.

I've taken a look at:

protected void Page_Load(object sender, EventArgs e)
{
 System.Threading.Tasks.Task<Google.Apis.Auth.GoogleJsonWebSignature.Payload> Sig = Google.Apis.Auth.GoogleJsonWebSignature.ValidateAsync(Request.Form["idToken"], null, true);
 Sig.Wait();
}

But this just hangs in my Page_Load method.

Has anyone got this working?

I'm not sure how you setup your javascript, but the way I have my setup the page already loaded, so I have an API on the backend that receives the token from the client, then do this to get the payload:

GoogleJsonWebSignature.Payload payload = await GoogleJsonWebSignature.ValidateAsync(Token);

The payload will give you all the user's information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM