-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Authentication and authorization
This page has moved to docs.servicestack.net
Built into ServiceStack is an optional Authentication feature you can use to add Authentication to your services by providing web services to Authenticate existing users, Register new users as well Assign/UnAssign Roles to existing users (if you need them). It's highly pluggable and customizable where you can plug-in your own Auth logic, change the caching and session providers as well as what RDBMS is used to persist UserAuth data.
A minimal configuration needed to get Basic Authentication up and running is the following in AppHost.Config() (derived from the AuthTests unit test):
public override void Configure(Container container)
{
Plugins.Add(new AuthFeature(() => new AuthUserSession(),
new IAuthProvider[] {
new BasicAuthProvider(), //Sign-in with HTTP Basic Auth
new CredentialsAuthProvider(), //HTML Form post of UserName/Password credentials
}));
Plugins.Add(new RegistrationFeature());
container.Register<ICacheClient>(new MemoryCacheClient());
var userRep = new InMemoryAuthRepository();
container.Register<IUserAuthRepository>(userRep);
//The IUserAuthRepository is used to store the user credentials etc.
//Implement this interface to adjust it to your app's data storage
}The high-level overview below shows how all the different parts fit together and which parts are customizable:
From the overview we can see the built-in AuthProviders that are included:
-
Credentials - For authenticating with username/password credentials by posting to the
/auth/credentialsservice - API Keys - Allowing users to authenticate with API Keys
- JWT Tokens - Allowing users to authenticate with JWT Tokens
- Basic Auth - Allowing users to authenticate with HTTP Basic Auth
- Digest Auth - Allowing users to authenticate with HTTP Digest Authentication
-
Custom Credentials - By inheriting CredentialsAuthProvider and providing your own Username/Password
TryAuthenticateimplementation - AspNetWindowsAuthProvider - Allowing users to authenticate with Windows Authentication
- Twitter OAuth - Allow users to Register and Authenticate with Twitter
- Facebook OAuth - Allow users to Register and Authenticate with Facebook
- GitHub OAuth - Allow users to Register and Authenticate with GitHub
- Yammer OAuth - Allow users to Register and Authenticate with Yammer
- Yandex OAuth - Allow users to Register and Authenticate with Yandex
- VK OAuth - Allow users to Register and Authenticate with VK
- Odnoklassni OAuth - Allow users to Register and Authenticate with Odnoklassni
The ServiceStack.Authentication.OAuth2 NuGet package provides OAuth2 Providers support to ServiceStack that includes:
- Instagram OAuth2 - Allow users to Register and Authenticate with Instagram OAuth2
- Google OAuth2 - Allow users to Register and Authenticate with Google OAuth2
- LinkedIn OAuth2 - Allow users to Register and Authenticate with LinkedIn OAuth2
- Microsoft Live OAuth2 - Allow users to Register and Authenticate with Microsoft Live OAuth2
The ServiceStack.Authentication.OpenId NuGet package provides OpenId Auth Providers support to ServiceStack that includes:
- Google OpenId - Allow users to Register and Authenticate with Google
- Yahoo OpenId - Allow users to Register and Authenticate with Yahoo
- MyOpenId - Allow users to Register and Authenticate with MyOpenId
