开发者

dotnetopenauth, MVC2 And No OpenID endpoint found

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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜