[英]Gathering information from Google+ Sign in with C#/ASP.NET MVC 4
Ok, I've been through a ton of documentation, "quick guides", and samples from Google, but nothing is making much sense to me, so I apologise in advance if I don't make much sense. 好的,我已经阅读了大量的文档,“快速指南”和谷歌的样本,但没有什么对我有意义,所以如果我没有多大意义,我会事先道歉。 I'm fairly new to ASP and MVC.
我是ASP和MVC的新手。 I really don't know what my next step is.
我真的不知道我的下一步是什么。
I have a very simple task, I want to log into my ASP.NET MVC 4 application with Google+, and then access user information (Name, Address, Gender) using C#, in my HomeController.cs class. 我有一个非常简单的任务,我想用Google+登录我的ASP.NET MVC 4应用程序,然后在我的HomeController.cs类中使用C#访问用户信息(名称,地址,性别)。
I am using the default ASP.NET template project (Razor), and successfully added my client ID and secret to Startup.Auth.cs, and I can log in with my Google+ account, and I have the proper scopes. 我正在使用默认的ASP.NET模板项目(Razor),并成功将我的客户端ID和秘密添加到Startup.Auth.cs,我可以使用我的Google+帐户登录,并且我有适当的范围。
Startup.Auth.cs: Startup.Auth.cs:
app.UseGooglePlusAuthentication(
clientId: "CLIENT-ID",
clientSecret: "CLIENT-SECRET");
Now from here is where I'm stumped. 现在从这里开始我就难倒了。
The example at the bottom of this page is exactly what I want to do, except it does not provide a C#/ASP example. 本页底部的示例正是我想要做的,除了它没有提供C#/ ASP示例。
My questions are:
我的问题是:
How can I access account information from my HomeController once I've successfully logged in with Google+? 我成功登录Google+后,如何从HomeController访问帐户信息?
What is my next step? 我下一步要做什么? I would greatly appreciate it if someone could direct me in the right direction.
如果有人能指引我朝着正确的方向前进,我将不胜感激。
Many thanks, this was a last resort. 非常感谢,这是最后的手段。
I think the following should set you on the right lines: 我认为以下内容应该为您指明正确的方向:
var externalIdentity = HttpContext.GetOwinContext().Authentication.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie);
var extEmailClaim = externalIdentity.Result.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email);
var extEmail = emailClaim.Value;
You should be able to follow the above pattern to access other pieces of data relating to your user by adjusting the ClaimTypes value within the lambda expression. 您应该能够通过调整lambda表达式中的ClaimTypes值来遵循上述模式来访问与您的用户相关的其他数据。
Please see the following link for other ClaimTypes values: ClaimTypes Class - MSDN 有关其他ClaimTypes值,请参阅以下链接: ClaimTypes Class - MSDN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.