dotnetopenauth,MVC2 且未找到 OpenID 端点

发布于 2024-09-07 01:56:46 字数 3907 浏览 7 评论 0原文

升级到 MVC2 和最新的 dotnetopenauth 后,我不断收到“未找到 OpenID 端点”的消息。当我尝试使用谷歌应用程序登录时。我在本地主机上工作正常,但在我的域上却不行 - 有什么想法吗?

namespace TheDataEngineMVCb1.Areas.Admin.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.Linq;
    using System.Security.Principal;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Security;
    using System.Web.UI;
    using DotNetOpenAuth.Messaging;
    using DotNetOpenAuth.OpenId;
    using DotNetOpenAuth.OpenId.RelyingParty;
    using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;

    [HandleError]
    public class AccountController : Controller
    {
        private static readonly HostMetaDiscoveryService GoogleAppsDiscovery = new HostMetaDiscoveryService
        {
            UseGoogleHostedHostMeta = true,
        };

        private static OpenIdRelyingParty openid = new OpenIdRelyingParty();

        public ActionResult Index()
        {
            return View("Index");
        }

        public ActionResult LoginPopup()
        {
            return View("LoginPopup");
        }

        public ActionResult Logout()
        {
            FormsAuthentication.SignOut();
            return Redirect("/Admin");
        }

        public ActionResult Login()
        {
            // Stage 1: display login form to user
            return View("Login");
        }

        [ValidateInput(false)]
        public ActionResult Authenticate(string returnUrl)
        {
            openid.DiscoveryServices.Clear();
            openid.DiscoveryServices.Insert(0, GoogleAppsDiscovery);
            var response = openid.GetResponse();
            if (response == null)
            {
                // Stage 2: user submitting Identifier
                Identifier id;

                if (Identifier.TryParse(Request.Form["openid_identifier"], out id) && Request.Form["openid_identifier"]!=null)
                {
                    try
                    {

                        Session["openid_identifier"] = Server.HtmlEncode(Request.Form["openid_identifier"]);
                        var request = openid.CreateRequest(Request.Form["openid_identifier"]);

                        return request.RedirectingResponse.AsActionResult();
                    }
                    catch (ProtocolException ex)
                    {
                        ViewData["Message"] = ex.Message;
                        return View("Login");
                    }
                }
                else
                {
                    ViewData["Message"] = "Invalid identifier";
                    return View("Login");
                }
            }
            else
            {
                // Stage 3: OpenID Provider sending assertion response
                switch (response.Status)
                {
                    case AuthenticationStatus.Authenticated:
                        string authEmail = Request["dnoa.userSuppliedIdentifier"].ToString();

                        FormsAuthentication.SetAuthCookie(authEmail, false);

                        if (!string.IsNullOrEmpty(returnUrl))
                        {
                            return Redirect(returnUrl);
                        }
                        else
                        {
                            return RedirectToAction("Index", "Home");
                        }
                    case AuthenticationStatus.Canceled:
                        ViewData["Message"] = "Canceled at provider";
                        return View("Login");
                    case AuthenticationStatus.Failed:
                        ViewData["Message"] = response.Exception.Message;
                        return View("Login");
                }
            }
            return new EmptyResult();
        }
    }
}

After I upgraded to MVC2 and the newest dotnetopenauth I keep getting "No OpenID endpoint found." when I try to login using google apps. I works fine on localhost but not on my domain - any ideas?

namespace TheDataEngineMVCb1.Areas.Admin.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.Linq;
    using System.Security.Principal;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Security;
    using System.Web.UI;
    using DotNetOpenAuth.Messaging;
    using DotNetOpenAuth.OpenId;
    using DotNetOpenAuth.OpenId.RelyingParty;
    using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;

    [HandleError]
    public class AccountController : Controller
    {
        private static readonly HostMetaDiscoveryService GoogleAppsDiscovery = new HostMetaDiscoveryService
        {
            UseGoogleHostedHostMeta = true,
        };

        private static OpenIdRelyingParty openid = new OpenIdRelyingParty();

        public ActionResult Index()
        {
            return View("Index");
        }

        public ActionResult LoginPopup()
        {
            return View("LoginPopup");
        }

        public ActionResult Logout()
        {
            FormsAuthentication.SignOut();
            return Redirect("/Admin");
        }

        public ActionResult Login()
        {
            // Stage 1: display login form to user
            return View("Login");
        }

        [ValidateInput(false)]
        public ActionResult Authenticate(string returnUrl)
        {
            openid.DiscoveryServices.Clear();
            openid.DiscoveryServices.Insert(0, GoogleAppsDiscovery);
            var response = openid.GetResponse();
            if (response == null)
            {
                // Stage 2: user submitting Identifier
                Identifier id;

                if (Identifier.TryParse(Request.Form["openid_identifier"], out id) && Request.Form["openid_identifier"]!=null)
                {
                    try
                    {

                        Session["openid_identifier"] = Server.HtmlEncode(Request.Form["openid_identifier"]);
                        var request = openid.CreateRequest(Request.Form["openid_identifier"]);

                        return request.RedirectingResponse.AsActionResult();
                    }
                    catch (ProtocolException ex)
                    {
                        ViewData["Message"] = ex.Message;
                        return View("Login");
                    }
                }
                else
                {
                    ViewData["Message"] = "Invalid identifier";
                    return View("Login");
                }
            }
            else
            {
                // Stage 3: OpenID Provider sending assertion response
                switch (response.Status)
                {
                    case AuthenticationStatus.Authenticated:
                        string authEmail = Request["dnoa.userSuppliedIdentifier"].ToString();

                        FormsAuthentication.SetAuthCookie(authEmail, false);

                        if (!string.IsNullOrEmpty(returnUrl))
                        {
                            return Redirect(returnUrl);
                        }
                        else
                        {
                            return RedirectToAction("Index", "Home");
                        }
                    case AuthenticationStatus.Canceled:
                        ViewData["Message"] = "Canceled at provider";
                        return View("Login");
                    case AuthenticationStatus.Failed:
                        ViewData["Message"] = response.Exception.Message;
                        return View("Login");
                }
            }
            return new EmptyResult();
        }
    }
}

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

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

发布评论

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

评论(1

捎一片雪花 2024-09-14 01:56:46

这可能是一个信任问题。 Google Apps OpenID 要求您的 RP 标记为“完全信任”。也许它在您的本地主机上,但不在您的实时站点上?

It could be a trust issue. Google Apps OpenIDs require that your RP be marked with Full Trust. Perhaps it is on your localhost but not on your live site?

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