Authentication Failures - possible modification?

May 11, 2011 at 10:50 PM
Edited May 12, 2011 at 5:20 PM

Hi Chris,

Here's a possible change suggestion...While testing this on my localhost I found that I could not log in.  The first time I tried to login, I got a message which said "Sorry, login failed."  In subsequent attemps, I'd click the "Sign-in" link and then "Google" and without giving me a chance to log in, it would return to the blog home page.

The example UserController in the DotNetOpenAuth samples was a little different from nblob, so I modified OpenIdCallback (in AuthenticationController) as follows:

        public ActionResult OpenIdCallback(string returnUrl)
        {
            var model = new LoginModel { ReturnUrl = returnUrl };
            var openId = new OpenIdRelyingParty();
            var openIdResponse = openId.GetResponse();

            switch (openIdResponse.Status)
            {
                case AuthenticationStatus.Authenticated:
                    var friendlyName = GetFriendlyName(openIdResponse);
                    SetAuthCookie(openIdResponse.ClaimedIdentifier, true, friendlyName);
                    model.Message = "Logged-on successfuly";
                    return Redirect(returnUrl.AsNullIfEmpty() ?? Url.Action("Index", "Home"));
                case AuthenticationStatus.Canceled:
                    model.Message = "Canceled at provider";
                    return View("Login", model);
                    //return Redirect(returnUrl.AsNullIfEmpty() ?? Url.Action("Index", "Home"));
                case AuthenticationStatus.Failed:
                    model.Message = "Sorry, login failed - error: " + openIdResponse.Exception.Message;
                    return View("Login", model);
                    //return Redirect(returnUrl.AsNullIfEmpty() ?? Url.Action("Index", "Home"));
                default:
                    model.Message = "Unknown error.";
                    return View("Login", model);
                    //return Redirect(returnUrl.AsNullIfEmpty() ?? Url.Action("Index", "Home"));
            }

        }

 Once I made that change, I was able to see the actual error: openid "return_to parameter does not match the actual URL".  Turns out that when I set up the local web site, I named it "NBlog" ("//localhost/NBlog/") and the actual web site was "//localhost/nblog/".