使用 DotNetOpenAuth 从 OpenID 提供商获取电子邮件地址

发布于 2024-11-04 03:11:02 字数 1441 浏览 1 评论 0原文

我无法获取 GetExtension 方法中返回的电子邮件地址,但它包含在 Google(我正在测试的 OP)发回给我的 URL 中。

if (Page.IsPostBack)
{
    using (var openid = new OpenIdRelyingParty())
    {
        var request = openid.CreateRequest(Request.Form["openid_identifier"]);

        var fetch = new FetchRequest();
        fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Contact.Email, true));

        request.AddExtension(fetch);

        request.RedirectToProvider();
    }
}
else
{
    using (var openid = new OpenIdRelyingParty())
    {
        var response = openid.GetResponse();
        if (response != null)
        {
            switch (response.Status)
            {
                case AuthenticationStatus.Authenticated:
                    var claimsResponse = response.GetExtension<FetchRequest>();
                    break;
                case AuthenticationStatus.Canceled:
                    //this.loginCanceledLabel.Visible = true;
                    break;
                case AuthenticationStatus.SetupRequired:
                    //this.loginFailedLabel.Visible = true;
                    break;

                // We don't need to handle SetupRequired because we're not setting
                // IAuthenticationRequest.Mode to immediate mode.
                ////case AuthenticationStatus.SetupRequired:
                ////    break;
            }
        }
    }
}

任何人都知道出了什么问题吗?

I can't get the email address returned in GetExtension method, but it is included in the url that Google (the OP I'm testing with) sends back to me.

if (Page.IsPostBack)
{
    using (var openid = new OpenIdRelyingParty())
    {
        var request = openid.CreateRequest(Request.Form["openid_identifier"]);

        var fetch = new FetchRequest();
        fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Contact.Email, true));

        request.AddExtension(fetch);

        request.RedirectToProvider();
    }
}
else
{
    using (var openid = new OpenIdRelyingParty())
    {
        var response = openid.GetResponse();
        if (response != null)
        {
            switch (response.Status)
            {
                case AuthenticationStatus.Authenticated:
                    var claimsResponse = response.GetExtension<FetchRequest>();
                    break;
                case AuthenticationStatus.Canceled:
                    //this.loginCanceledLabel.Visible = true;
                    break;
                case AuthenticationStatus.SetupRequired:
                    //this.loginFailedLabel.Visible = true;
                    break;

                // We don't need to handle SetupRequired because we're not setting
                // IAuthenticationRequest.Mode to immediate mode.
                ////case AuthenticationStatus.SetupRequired:
                ////    break;
            }
        }
    }
}

Anyone knows what's wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一个人的旅程 2024-11-11 03:11:02

尝试以下代码:

switch (response.Status)
 {
     case AuthenticationStatus.Authenticated:
         var fetch = response.GetExtension<FetchResponse>();
         string email = String.Empty; 
         if (fetch != null)
         {
            email =  fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);
         }  
        break;
    //...
}

Try the following code:

switch (response.Status)
 {
     case AuthenticationStatus.Authenticated:
         var fetch = response.GetExtension<FetchResponse>();
         string email = String.Empty; 
         if (fetch != null)
         {
            email =  fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);
         }  
        break;
    //...
}
可遇━不可求 2024-11-11 03:11:02

在 C# 中,以上内容都不适合我(使用 PayPal Access 作为标识符)

以下内容对我有用:

    OpenIdRelyingParty openid = new OpenIdRelyingParty();

    protected void Page_Load(object sender, EventArgs e)
    {
        var response = openid.GetResponse();

        if (response != null)
        {
            switch (response.Status)
            {
                case AuthenticationStatus.Authenticated:

                    if (this.Request.Params["openid.ext1.value.alias1"] != null)
                    {
                        Response.Write(this.Request.Params["openid.ext1.value.alias1"]);
                        Response.Write(this.Request.Params["openid.ext1.value.alias2"]);
                    }
                    else {
                        Response.Write("Alias wrong");
                    }
                    break;
            }
        }
    }
     protected void loginButton_Click(object sender, EventArgs e)
    {

        var openidRequest = openid.CreateRequest(openIdBox.Text);
        var fetch = new FetchRequest();

        fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
        fetch.Attributes.AddRequired(WellKnownAttributes.Name.FullName);
        openidRequest.AddExtension(fetch);

        openidRequest.RedirectToProvider();

    }

None of the above worked for me (using PayPal Access as a identifier) in C#

The below worked for me:

    OpenIdRelyingParty openid = new OpenIdRelyingParty();

    protected void Page_Load(object sender, EventArgs e)
    {
        var response = openid.GetResponse();

        if (response != null)
        {
            switch (response.Status)
            {
                case AuthenticationStatus.Authenticated:

                    if (this.Request.Params["openid.ext1.value.alias1"] != null)
                    {
                        Response.Write(this.Request.Params["openid.ext1.value.alias1"]);
                        Response.Write(this.Request.Params["openid.ext1.value.alias2"]);
                    }
                    else {
                        Response.Write("Alias wrong");
                    }
                    break;
            }
        }
    }
     protected void loginButton_Click(object sender, EventArgs e)
    {

        var openidRequest = openid.CreateRequest(openIdBox.Text);
        var fetch = new FetchRequest();

        fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
        fetch.Attributes.AddRequired(WellKnownAttributes.Name.FullName);
        openidRequest.AddExtension(fetch);

        openidRequest.RedirectToProvider();

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文