我正在使用 dotnetopenauth 3.2 来实现 Openid,但不知道如何让 Google 在声明响应中传递电子邮件地址。我知道 Google 不支持简单注册,但我无法确定他们支持什么。
对这个问题的警告是,我刚刚开始学习 OpenID,我知道我对规范没有扎实的掌握,我认为这导致了我的困惑。
任何帮助,将不胜感激!
好吧,明白了。我发布了一个问题Google 的联合日志 API 组 http://groups.google.com/group/google-federated-login-api/browse_thread/thread/5521cae736698091#并被告知使用属性交换 http://docs.dotnetopenauth.net/v3.3/html/N_DotNetOpenAuth_OpenId_Extensions_AttributeExchange.htm.
下面是代码DotNetOpenAuth http://dotnetopenauth.net/.
请不要在生产中使用此代码。这仅用于说明目的!
请求:
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;
}
...
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)