我正在使用 dotnetopenauth 3.2 来实现 Openid,但无法弄清楚如何让 Google 在 claim 响应中传递电子邮件地址。我知道谷歌不支持简单注册,但我不能确定他们支持什么。
这个问题需要注意的是,我刚刚开始学习 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;
}
...
}
}
关于c# - OpenID:尝试从 Google OP 获取电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1301200/