This tutorial demonstrates how to add user login to a ServiceStack web application. We recommend you to Log in to follow this quickstart with examples configured for your account.
I want to integrate with my app15 minutes
I want to explore a sample app2 minutes
Get a sample configured with your account settings or check it out on Github.
Get Your Application Keys
When you signed up for Auth0, a new application was created for you, or you could have created a new one.
You will need some details about that application to communicate with Auth0. You can get these details from the Application Settings section in the Auth0 dashboard.
You need the following information:
- Client ID
- Client Secret
Configure Callback URLs
A callback URL is a URL in your application where Auth0 redirects the user after they have authenticated.
The callback URL for your app must be whitelisted in the Allowed Callback URLs field in your Application Settings. If this field is not set, users will be unable to log in to the application and will get an error.
Create a ServiceStack application
For this example, we will use the standard template that ships with Visual Studio. Select "FILE > New project > ASP.NET Web Application > MVC" .
Once the default template unfolds, use NuGet to install the ServiceStack.Host.Mvc nuget, running the command:
HomeController to return the
default.htm page. Under the Controllers folder add:
Configure ServiceStack to use Auth0
We provide a Nuget package to simplify integration of Auth0 with ServiceStack based applications.
Run this command on the Package Manager Console:
This command will add two classes to your project under the App_Start folder:
Auth0Provider extends ServiceStack's
OAuthProvider and handles the authentication transaction for you.
Enable Authentication and Plugin Auth0's Provider
AppHost.cs file (also under the App_Start folder) generated by the ServiceStack NuGet. Uncomment the following call under the
And then uncomment (if it is commented out) and edit the
ConfigureAuth method to look like this:
Enter Configuration Settings
web.config file and change the three Auth0's parameters under
Add Backend Code to Test the App
Authenticate Attribute to the
IAuthSession Property to the
HelloService to Return the Current User's
You will need to redirect the user to the Auth0 Authorization endpoint in order to log in to the application. We will use the Auth0.NET SDK to construct the redirect URL. First, install the
Auth0.AuthenticationApi NuGet package:
Then, add an
AccountController class to your MVC application with a
Login action. This action will construct the authorization URL, and then redirect the user to that URL.
Display User Information
default.htm and add a login button which will redirect the user to the
Also add the following statement in the
jQuery.ready body which will call the
/api/hello endpoint which will return the logged in user's information:
Add a section to display the