Asp.net Google登录 [英] Asp.net Google Sign In
问题描述
我正在尝试在ASP.net应用程序中实现Google登录.
我已经实现了将Google登录集成到您的网络应用,并且可以运行,但是我需要在数据库中存储一个Google用户ID,以便以后登录时进行标识.
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.
该页面指出我不应该使用 profile.getId
,但应该将 googleUser.getAuthResponse().id_token
发送到后端并验证此令牌.
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.
好吧,我已经将大量的字符发送到后端,但是我似乎无法弄清楚如何验证这组字符并从中检索有用的标识ID(对于Google用户应保持相同)此数据包.
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.
我看过:
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();
}
但这只是挂在我的 Page_Load
方法中.
But this just hangs in my Page_Load
method.
有人能做到这一点吗?
推荐答案
我不确定如何设置JavaScript,但是我已经设置了加载页面的方式,因此后端有一个API可以接收来自客户端的令牌,然后执行此操作以获取有效载荷:
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.
这篇关于Asp.net Google登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!