OpenID登录:试图从谷歌OP获取邮箱地址 [英] OpenID: Trying to Get Email Address from Google OP

查看:544
本文介绍了OpenID登录:试图从谷歌OP获取邮箱地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用dotnetopenauth 3.2来实现OpenID和无法弄清楚如何让谷歌在声明响应传送的电子邮件地址。我知道,谷歌不支持简单的登记,但我不能确定他们做了什么支持。

I’m using dotnetopenauth 3.2 to implement Openid and can’t figure out how to get Google to pass the email address in the Claims Response. I know that Google doesn’t support simple registration, but I can’t determine what they do support.

注意,该问题是,我刚开始学习的OpenID,我知道我没有关于这一点我认为是导致我的困惑规范扎实掌握。

Caveat to this question is that I just started learning OpenID and I know I don’t have a solid grasp on the specification which I think is leading to my confusion.

任何帮助将是AP preciated!

Any help would be appreciated!

推荐答案

好了它。我贴在<一个问题href=\"http://groups.google.com/group/google-federated-login-api/browse_thread/thread/5521cae736698091#\"相对=nofollow> Goolge的公司联合登录API组,被告知使用<一个href=\"http://docs.dotnetopenauth.net/v3.3/html/N_DotNetOpenAuth_OpenId_Extensions_AttributeExchange.htm\"相对=nofollow>属性交换。

Ok figured it out. I posted a question on Goolge's Federated Log API group and was told to use Attribute exchange.

下面是code为 DotNetOpenAuth

请不要在生产中使用这个code。这是用于说明目的而已!

Please don't use this code in production. This is for illustration purposes only!

的请求:

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;
        }
        ...
    }
}

这篇关于OpenID登录:试图从谷歌OP获取邮箱地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆