【发布时间】:2009-08-19 16:47:27
【问题描述】:
我正在使用 dotnetopenauth 3.2 来实现 Openid,但无法弄清楚如何让 Google 在声明响应中传递电子邮件地址。我知道谷歌不支持简单的注册,但我无法确定他们支持什么。
对这个问题的警告是,我刚开始学习 OpenID,我知道我对规范没有扎实的掌握,我认为这会导致我的困惑。
任何帮助将不胜感激!
【问题讨论】:
标签: c# openid dotnetopenauth
我正在使用 dotnetopenauth 3.2 来实现 Openid,但无法弄清楚如何让 Google 在声明响应中传递电子邮件地址。我知道谷歌不支持简单的注册,但我无法确定他们支持什么。
对这个问题的警告是,我刚开始学习 OpenID,我知道我对规范没有扎实的掌握,我认为这会导致我的困惑。
任何帮助将不胜感激!
【问题讨论】:
标签: c# openid dotnetopenauth
好的,想通了。我在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;
}
...
}
}
【讨论】:
当我尝试获取全名时,响应为空,请提供获取全名的解决方案, 这个帖子真的很有帮助 感谢。 我的示例代码是这样的。
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);
}
【讨论】: