Carl Marsay
Carl Marsay

Reputation: 23

Service Stack authentication

? - Is it possible to have multiple authentication providers within the same MVC 4 hosted service stack web services, we will have multiple endpoints utilizing internal and external services that require differing levels/types of authentication.

I need initially to implement a couple of custom providers to suit our our needs so that depending on the URL a different authentication provider is utilized, so far I have only found examples of providing a single custom authentication provider.

Upvotes: 0

Views: 693

Answers (1)

kampsj
kampsj

Reputation: 3149

Yes. You can use multiple providers. Then you could have different roles for different resources (urls) to manage your internal vs external levels.

Take a look at the https://github.com/ServiceStack/SocialBootstrapApi example project. This example has a lot of different authentication providers. Each auth provider resolves to the path /auth/{provider} where provider is resolved using the IAuthProvider.Provider property of your custom providers and the build in providers.

You will need to register each auth provider you want to use.

//Register all Authentication methods you want to enable for this web app.            
Plugins.Add(new AuthFeature(
    () => new CustomUserSession(), //Use your own typed Custom UserSession type
    new IAuthProvider[] {
        new CredentialsAuthProvider(),        
        new TwitterAuthProvider(appSettings),  
        new FacebookAuthProvider(appSettings), 
        new DigestAuthProvider(appSettings),  
        new BasicAuthProvider(),               
        new GoogleOpenIdOAuthProvider(appSettings), 
        new YahooOpenIdOAuthProvider(appSettings),  
        new OpenIdOAuthProvider(appSettings),     
}));

Then you can login by hitting the different urls like

  • /auth/facebook
  • /auth/twitter

Upvotes: 1

Related Questions