Search code examples
authenticationasp.net-mvc-routingumbracoumbraco7auth0

Hook up Auth0AccountController in Umbraco 7


Has anyone successfully integrated Auth0 with Umbraco 7 for member (front-end public users, not CMS back-end users) authentication?

I've successfully integrated with owin startup and dealing with signin-auth0 response. However I'm stuck on hooking up the Auth0AccountController to work with Umbraco (I'm getting a 404). Any suggestions?

I've tried adding ~/Auth0Account to the "umbracoReservedPaths" appSetting, but I just get a slightly different looking 404 (not controlled by Umbraco by looks of it).

I've also tried mapping the route in Startup.cs using

RouteTable.Routes.MapRoute(
    "Auth0Account",
    "Auth0Account/{action}",
    new
    {
        controller = "Auth0Account"
    }
);

but that results in a "No route in the route table matches the supplied values" error.

Any ideas?


Solution

  • Mapping the Auth0Account route in Startup.cs was correct:

    RouteTable.Routes.MapRoute(
        "Auth0Account",
        "Auth0Account/{action}",
        new
        {
            controller = "Auth0Account"
        }
    );
    

    Turns out my problem was with the default redirect RedirectToLocal method in the Auth0AccountController controller. It was doing a

    return RedirectToAction("Index", "Home");
    

    which I didn't have a controller hooked up for. I replaced this with an Umbraco compatible redirect instead.

    Also, instead of Auth0AccountController inheriting from Controller it might be useful to inherit from Umbraco.Web.Mvc.SurfaceController or Umbraco.Web.Mvc.RenderMvcController to expose useful Umbraco methods to the code.