Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating ASP.NET MVC 5 Identity and authentication with ServiceStack 4

I have recently created web services using authentication and roles through ServiceStack 4 including openId and OAuth providers Google, Twitter and LinkedIn backed by a MongoDB repository.

I would like to integrate those services with my ASP.NET 5 MVC website that currently uses Microsoft's new Identity (OWIN) framework with the same providers for registration, authentication and roles.

I would prefer to use ServiceStack for authentication, registration and roles and have my MVC Controllers authorize against that. I've read the posts regarding SimpleMembership and the wiki around Authorization and Session Handling in ServiceStack.

What I would like to know is if there is a starter template or example that takes the latest MVC 5 template and replaces/integrates that with ServiceStack 4.

Specifically, how does the existing AccountController, IdentityUser, UserManager and UserStore get replaced/modified to use ServiceStack?

like image 241
Nadeem Avatar asked Jan 18 '14 20:01

Nadeem


1 Answers

What I would like to know is if there is a starter template or example that takes the latest MVC 5 template and replaces/integrates that with ServiceStack 4.

ServiceStackVS is an extension which allows to create ServiceStack powered projects from scratch. There is a template for ASP.NET MVC 5.

Specifically, how does the existing AccountController, IdentityUser, UserManager and UserStore get replaced/modified to use ServiceStack?

Specifically, all of your controllers need to inherit from ServiceStackController<T> (where T is IAuthSession). in your Global.asax's Application_Start you need to initialize your AppHost. Then, you have something like that

public class MyAppHost : AppHostBase
{
    public MyAppHost() : base("My Service Name")
    {
    }

    public override void Configure(Container container)
    {
        // Configure your container here (authentication, plugins...)
    }
}

public class MvcApplication : HttpApplication
{
    private MyAppHost AppHost { get; set; }

    protected void Application_Start()
    {
        //...
        AppHost = new MyAppHost(this).Init();
        ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(AppHost.Container));
        //...
    }
}
like image 197
labilbe Avatar answered Oct 19 '22 15:10

labilbe