ASP.NET Web API Tutorial

Otherwise, please follow the steps below to configure your existing ASP.NET Web API app to use it with Auth0.

1. Install the WebApi.JsonWebToken package

You can either run the following command or install it via Package Manager.

Install-Package WebApi.JsonWebToken

2. Configure the JsonWebToken message handler

Open the WebApiConfig.cs file located in the App_Start folder and add the following using statements:

using Api.App_Start;
using System.Web.Configuration;

Add the following code snippet inside the Register method.

var clientID = WebConfigurationManager.AppSettings["Auth0ClientID"];
var clientSecret = WebConfigurationManager.AppSettings["Auth0ClientSecret"];

config.MessageHandlers.Add(new JsonWebTokenValidationHandler()
{
    Audience = clientID,
    SymmetricKey = clientSecret
});

3. Update the web.config file with your app's credentials

Open the web.config file located at the solution's root.

Add the following entries as children of the <appSettings> element.

<add key="Auth0ClientID" value="YOUR_CLIENT_ID"/>
<add key="Auth0ClientSecret" value="YOUR_CLIENT_SECRET"/>

4. Securing your API

All you need to do now is add the [System.Web.Http.Authorize] attribute to the controllers/actions for which you want to verify that users are authenticated.

5. You're done!

Now you have both your FrontEnd and Backend configured to use Auth0. Congrats, you're awesome!

Optional Steps

Configuring CORS

You can follow this article to configure CORS in your application.