
[英]Get email address from OpenID Provider with DotNetOpenAuth
[英]OpenID: Trying to Get Email Address from Google OP
我正在使用dotnetopenauth 3.2来实现Openid,但无法弄清楚如何让Google通过Claims Response中的电子邮件地址。 我知道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;
}
...
}
}
当我尝试获取全名时,响应为null,请提供一种获取全名的解决方案,这篇帖子对您真的很有帮助。谢谢。 我的示例代码是这样的。
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.