我正在使用 dotnetopenauth 3.2 来实现 Openid,但无法弄清楚如何让 Google 在声明响应中传递电子邮件地址。我知道谷歌不支持简单的注册,但我无法确定他们支持什么。
对这个问题的警告是,我刚开始学习 OpenID,我知道我对规范没有扎实的掌握,我认为这会导致我的困惑。
任何帮助,将不胜感激!
我正在使用 dotnetopenauth 3.2 来实现 Openid,但无法弄清楚如何让 Google 在声明响应中传递电子邮件地址。我知道谷歌不支持简单的注册,但我无法确定他们支持什么。
对这个问题的警告是,我刚开始学习 OpenID,我知道我对规范没有扎实的掌握,我认为这会导致我的困惑。
任何帮助,将不胜感激!
好的,想通了。我在Goolge 的 Federated Log API 组上发布了一个问题,并被告知使用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);
}