Hog*_*eed 5 gmail dotnetopenauth
我正在尝试使用dotNetOpenId登录GMail帐户.它工作,但我无法检索任何索赔.我知道我也可以检索电子邮件地址或用户名,但只有ClaimedIdentifier可用时才会返回任何声明.有人知道如何从Gmail帐户中检索此数据吗?如果你能提供一个ClaimsRequest配置的例子,我将不胜感激.
谢谢
// 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);
Run Code Online (Sandbox Code Playgroud)
然后,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;
}
Run Code Online (Sandbox Code Playgroud)
您可以查看我关于该主题的博客文章以获取更多信息。这里需要注意的重要一点是,如果您将用户的电子邮件地址标记为必需(正如我在上面的代码片段中所做的那样),Google 只会告诉您用户的电子邮件地址。但这也意味着,如果用户不想共享他的电子邮件地址,他根本无法登录。抱歉,谷歌就是这么设置的。不幸的是,人们使用的其他提供商有不同的行为。
| 归档时间: |
|
| 查看次数: |
790 次 |
| 最近记录: |