OpenID:试图从谷歌获得电子邮件地址OP

问题描述:

我正在使用dotnetopenauth 3.2来实现Openid,但无法弄清楚如何让Google在索赔响应中传递电子邮件地址。我知道Google不支持简单的注册,但我无法确定他们的支持。OpenID:试图从谷歌获得电子邮件地址OP

买者对这个问题是我刚开始学习的OpenID,我知道我没有关于这一点我认为是导致我的困惑规范扎实掌握。

任何帮助,将不胜感激!

好吧,算了一下。我发布了一个关于Goolge's Federated Log API group的问题,并被告知使用Attribute exchange

以下是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; 
     } 
     ... 
    } 
} 
+0

这是伟大的。你会不会知道如何获得提供者的名称(除了分析响应)? – 2010-11-27 06:57:58

+0

你的意思是声称的ID? 情况AuthenticationStatus.Authenticated: { 字符串标识符= response.ClaimedIdentifier; } – Rob 2010-12-16 23:51:54

+0

我认为他在谈论提供商的实际友好名称,即:“Google”“Facebook”无法解析响应。 – Brian 2011-01-02 23:53:15

当我试图让全名的响应为空,请提供一个解决方案,以获得全名, 这帖子真的有帮助 谢谢。 我的示例代码是这样的。

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); 
     }