OpenID:试图从Google OP获取电子邮件地址

我正在使用dotnetopenauth 3.2来实现Openid,并且无法弄清楚如何让Google通过Claim Response中的电子邮件地址。 我知道Google不支持简单的注册,但是我无法确定他们的支持。

对这个问题的警告是,我刚开始学习OpenID,我知道我没有牢牢把握规范,我认为这导致了我的困惑。

任何帮助,将不胜感激!

好吧,明白了。 我在Goolge的联合日志API组发布了一个问题,并被告知使用属性交换 。

以下是DotNetOpenAuth的代码。

请不要在生产中使用此代码。 这仅用于说明目的!

要求:

using (OpenIdRelyingParty openid = new OpenIdRelyingParty()) { IAuthenticationRequest request = openid.CreateRequest(openidurl); var fetch = new FetchRequest(); fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email); request.AddExtension(fetch); // Send your visitor to their Provider for authentication. request.RedirectToProvider(); } 

响应:

 OpenIdRelyingParty openid = new OpenIdRelyingParty(); var response = openid.GetResponse(); if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: { var fetch = response.GetExtension<FetchResponse>(); string email = string.Empty(); if (fetch != null) { email = fetch.GetAttributeValue( WellKnownAttributes.Contact.Email); } FormsAuthentication.RedirectFromLoginPage( response.ClaimedIdentifier, false); break; } ... } } 

当我试图获得全名响应为空,请提供一个解决scheme,以获得全名,这个职位真的很有帮助谢谢。 我的示例代码是这样的。

 var fetch = new FetchRequest(); fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email); fetch.Attributes.AddRequired(WellKnownAttributes.Name.FullName); fetch.Attributes.AddRequired(WellKnownAttributes.Company.CompanyName); //fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email); request.AddExtension(fetch); 

 if (fetch != null) { email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email); name = fetch.GetAttributeValue(WellKnownAttributes.Name.FullName); company = fetch.GetAttributeValue(WellKnownAttributes.Company.CompanyName); }