Web Development with Blazor - Second Edition by Jimmy Engström

Web Development with Blazor - Second Edition by Jimmy Engström

Author:Jimmy Engström
Language: eng
Format: epub
Publisher: Packt
Published: 2023-11-15T00:00:00+00:00


Technical requirements

Make sure you have followed the previous chapters or use the Chapter07 folder as a starting point.

You can find the source code for this chapter’s end result at https://github.com/PacktPublishing/Web-Development-with-Blazor-Second-Edition/tree/main/Chapter08.

Setting up authentication

There are a lot of built-in functionalities when it comes to authentication. The easiest way to add authentication is to select an authentication option when creating a project.

We need to implement authentication separately for the Blazor Server project and the Blazor WebAssembly project because they work differently.

But there are still things we can share between these two projects. First, we need to set up Auth0.

Auth0 is a service that can help us with handling our users. There are many different services like this, but Auth0 is the one that seems to be a very good service to use. We can connect one or many social connectors, which will allow our users to log in with Facebook, Twitter, Twitch, or whatever we add to our site.

Even though all of this can be achieved by writing code ourselves, integration like this is a great way to add authentication fast and also get a very powerful solution. Auth0 is free for up to 7,000 users (which our blog probably won’t reach, especially not the admin interface).

It also has great functionality to add data to our users that we have access to. We will do that later in the chapter when we add roles to our users. You’ll need to take the following steps:

Head over to https://auth0.com and create an account.

Click the Create Application button.

Now it’s time to name our application. Use MyBlog, for example. Then it’s time to select what kind of application type we are using. Is it a native app? Is it a Single-Page Web Application, Regular Web Application, or Machine to Machine Application? This depends on what version of Blazor we are going to run.

But it won’t limit the functionality, only what we need to configure when setting up our application.

We will start with Blazor server, which is a regular web application. But we want to be able to use the same authentication for both Blazor Server and Blazor WebAssembly, and we can do that by selecting Single Page Application.

And if we are only making a Blazor Server Application, we should use Regular Web Application, but since we are doing both, select Single Page Web Application since this will make it possible to run both.

Next, we will choose what technology we are using for our project. We have got Apache, .NET, Django, Go, and many other choices, but we don’t have a choice for Blazor specifically, at least not at the time of writing.

Just skip this and click the Setting tab.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.