This repository contains two projects:
- An ASP.NET Core MVC application integrated with Auth0 authentication in the
HealthCheckWebAppfolder. - An ASP.NET Core Web API protected with Auth0 in the
HealthCheckApifolder.
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
HealthCheckApifolder. -
Add your Auth0 domain and API identifier to the
appsettings.jsonconfiguration file. Take note of the API identifier. -
Type
dotnet runin a terminal window to launch the API. -
Move to the
HealthCheckWebAppfolder. -
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.pemfile to configure Private Key JWT authentication in your Auth0 dashboard. -
Add your Auth0 domain and client ID to the
appsettings.jsonconfiguration file. Also, assign the API identifier value to theAudiencekey. -
Type
dotnet runin a new terminal window to launch the application. -
Point your browser to the https://localhost:7062 address.