找到dotnetopenauth,MVC2和No OpenID端点

时间:2010-06-21 10:56:57

标签: asp.net-mvc asp.net-mvc-2 dotnetopenauth google-apps

升级到MVC2和最新的dotnetopenauth后,我不断发现“找不到OpenID端点”。当我尝试使用谷歌应用程序登录时。我在localhost上工作正常,但在我的域名上没有 - 任何想法?

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();
        }
    }
}

1 个答案:

答案 0 :(得分:3)

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