This tutorial demonstrates how to add user login to a Nancy FX 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.
Configure your application to use Auth0
Install the Dependencies
Install Auth0 NancyFX dependency with
In your Nancy self-hosted application add the following to your BootStrapper:
RedirectOnLoginFailed specifies the view that should be shown to an authenticated user when they try to access a restricted view.
CookieName allows you to set the name of the cookie that will be used to save the User information.
UserIdentifier lets you set an identifier for the user. Currently, here are the fields that are available:
Add Auth0 Configuration
You need to configure your Auth0 keys in the
Block all Unauthenticated Requests
After you enabled the
Auth0Authentication you are able to block all unauthenticated requests with the following code.
Add Auth0 Callback Handler
We need to add the handler for the Auth0 callback so that we can authenticate the user and get their information. We also need to add an endpoint to let users log in and log out.