This repository contains two projects:
- An ASP.NET Core MVC application integrated with Auth0 authentication in the
HealthCheckWebApp
folder. - An ASP.NET Core Web API protected with Auth0 in the
HealthCheckApi
folder.
Check out the article Use Private Key JWTs to Authenticate Your .NET Application for the implementation details.
- .NET 8 SDK installed on your machine
- Visual Studio 2022 (optional)
-
Clone the repo with the following command:
git clone https://github.com/auth0-blog/dotnet-private-key-jwt-authetication.git
-
Move to the
HealthCheckApi
folder. -
Add your Auth0 domain and API identifier to the
appsettings.json
configuration file. Take note of the API identifier. -
Type
dotnet run
in a terminal window to launch the API. -
Move to the
HealthCheckWebApp
folder. -
Create a private and public key pair by running the following command:
openssl genrsa -out app_keys.pem 2048
-
Extract the public key with the following command:
openssl rsa -in app_keys.pem -outform PEM -pubout -out pub_key.pem
-
Use the public key in the
pub_key.pem
file to configure Private Key JWT authentication in your Auth0 dashboard. -
Add your Auth0 domain and client ID to the
appsettings.json
configuration file. Also, assign the API identifier value to theAudience
key. -
Type
dotnet run
in a new terminal window to launch the application. -
Point your browser to the https://localhost:7062 address.