【发布时间】:2009-04-07 16:38:56
【问题描述】:
我正在尝试使用 dotNetOpenId 登录到 GMail 帐户。它有效,但我无法检索任何索赔。我知道我也可以检索电子邮件地址或用户名,但是只有 ClaimedIdentifier 可用,才会返回任何声明。有人知道如何从 Gmail 帐户中检索这些数据吗?如果您能提供一个 ClaimsRequest 配置的示例,我将不胜感激。
谢谢
【问题讨论】:
标签: gmail dotnetopenauth
我正在尝试使用 dotNetOpenId 登录到 GMail 帐户。它有效,但我无法检索任何索赔。我知道我也可以检索电子邮件地址或用户名,但是只有 ClaimedIdentifier 可用,才会返回任何声明。有人知道如何从 Gmail 帐户中检索这些数据吗?如果您能提供一个 ClaimsRequest 配置的示例,我将不胜感激。
谢谢
【问题讨论】:
标签: gmail dotnetopenauth
// Either you're creating this already or you can get to it in
// the LoggingIn event of the control you're using.
IAuthenticationRequest request;
// Add the AX request that says Email address is required.
var fetch = new FetchRequest();
fetch.Attributes.Add(
new AttributeRequest(WellKnownAttributes.Contact.Email, true));
request.AddExtension(fetch);
然后,Google 会对用户进行身份验证并返回您可以使用的电子邮件地址:
var fetch = openid.Response.GetExtension<FetchResponse>();
if (fetch != null)
{
IList<string> emailAddresses = fetch.GetAttribute(
WellKnownAttributes.Contact.Email).Values;
string email = emailAddresses.Count > 0 ? emailAddresses[0] : null;
}
您可以在该主题上查看my blog post 以获取更多信息。这里要注意的重要一点是,如果您将其标记为必需,Google 只会告诉您用户的电子邮件地址(就像我在上面的 sn-p 中所做的那样)。但这也意味着如果用户不想分享他的电子邮件地址,他就根本无法登录。抱歉,Google 就是这样设置的。不幸的是,人们使用的其他提供者有不同的行为。
【讨论】: