views:

341

answers:

1

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();
        }
    }
}
+3  A: 

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?

Andrew Arnott
That worked but strange that would change when upgrading to MVC2 (it worked fine with MVC1) - thanks
pch