Over the past few years, I have tried to explain in simple and, most importantly, practical terms how to integrate Auth0 into the various types of applications you can build with .NET. My goal has been to simplify the experience of .NET developers approaching Auth0.
The topic of authentication and authorization is complex, and untangling the details of protocols like OIDC and OAuth2 is not easy. Fortunately, SDKs provide a great deal of help in abstracting the complexity inherent in the protocols. But even knowing which SDK to use based on the type of application and how to write the code to integrate Auth0 when an SDK is not available requires some familiarity with both the Auth0 product and the infrastructure provided by .NET.
To simplify the development experience for .NET developers, I tried to go beyond creating tutorials and started the Auth0 Templates for .NET project, a package of .NET project templates with everything needed to support Auth0's authentication and authorization services! 🎉
For your next .NET application using Auth0, you only need to select the right template and provide the configuration parameters from the Auth0 dashboard. But let's go one step at a time.
First, you need to install the NuGet package. You can do this by running the following command in a terminal window:
dotnet new install Auth0.Templates
Once the package is installed, you will have four templates to create your own applications:
- Auth0 MVC Application
- Auth0 Web API Application
- Auth0 Blazor Server Application
- Auth0 Blazor WebAssembly Application
The project is a work in progress, and more templates will be added in future releases.
You can use these templates from the command line, through the .NET CLI, or in Visual Studio.
Say you want to create a new Blazor Server application that uses Auth0 as its Identity provider. The first step is to register your app with Auth0. During this first step, you will get some data that you will use to set up your app through the templates.
Then, on your machine, run the following command in a terminal window:
dotnet new auth0blazorserver --domain <YOUR_AUTH0_DOMAIN> --client-id <YOUR_CLIENT_ID> -o MyBlazorApp
You specify the
auth0blazorserver template as the template to use. Then, you pass your Auth0 domain and your client ID, values that come from the registration step. Finally, you indicate the folder where the new application will be created.
Voila! After a few seconds, you will find a new Blazor Server project in the folder you specified with all the code to support authentication via Auth0! 🪄
If you prefer to use Visual Studio, you just need to select the Auth0 template from the list, as shown below:
Then, provide the required settings as shown in the following picture:
By the way, you can also use the templates in Visual Studio for Mac.
The Auth0 Templates for .NET project started as an Open Source project a few months ago. I'd like it to become the starting point for building any .NET application with Auth0 embedded. I plan to add more templates and improve the developer experience in the near future.
Give it a try and let me know what do you think. Your feedback is welcome, as well as your contribution. 🙏