Blazor Project
Blazor is a free, open-source framework that enables one to build an interactive client-based application with .NET. It uses this open-source without any plugins; one can use C# in the case of JavaScript and .NET system of open libraries. These components can be hosted on the server or the client using Blazor, it enables developers to bring the client code on web pages, and it’s easy to read and learn. The Blazor server is used in the separation of various components used to showcase the application of logic in the implementation of IU updates. It supports the hosting of various razor components in the ASP.NET core application of the server. These updates, event handling, and JavaScript calls are done over a signaIR connection (Chiarelli, 2019). There are two ways Blazor offers client options to run their web applications. These options are called Hosting models whereby they include the Blazor Server and Blazor WebAssembly. The sections below shall explain how to achieve
Building a Blazor Server Application
To construct a Blazor Server App, one has to open the Blazor server project to type in their commands. Users are offered root folders, data folders, page folders, and shared folders to complete their program as desired. One then proceeds to create the Model and the Service of the application and gives it a UI. Take the example of creating a simple quiz application. The code
Dotnet new blazorserver –o QuizManager
Uses the Blazor server template to create a new folder called Quiz Manager. The next step involves deleting the models and services implementing the business logic within the DataFolder. QuizItem.cs is then used to replace the removed content in the data folder. More files with code are added to build up towards creating the model and service of the application. The next steps involve adding components and running the application. Razor components are many and are implemented in the file .razor. To execute components, one has to access the pages folder and replace the default files with their QuizVier.razor file to run the code for their anticipated UI. Once all the steps are achieved successfully, the app is run using the dotnet run command. Users are then able to access their application at https://localhost:5001

Building a Blazor WebAssembly Application
When building the Blazor WebAssembly application, users are required to have client sides’ applications. This application is supported on .NET Core SDK 3.1 preview. By running the following code, users can create a new WebAssembly Project:
Dotnet new blazorwasm –o QuizManagerClientHosted –hosted
One then creates the project folder, which contains the client folder, server folder, and the shared folder (Chiarelli, 2019). After that, the user creates the Server using the server controller folders and adding a new file name with codes. The output created is usually the WEB API version of the class that has been created in the Blazor server application. Next, the user creates a client by client page or folder by eliminating the default files and replacing them with their project file that has their desired code. This enables one to make an HTTP GET call to the quiz endpoint of the WEB API created. The application is completed by replacing the navmenu razor with the desired application code. One then runs this application by using the dotnet run command (Chiarelli, 2019). The application is then hosted to http://localhost:5001.
Creating the Auth0 application
Auth0 enables the authentication and authorization of various services. To support the process of securing the application, one is required to create an Auth0 application. One can also create the account for free since it’s available in the Auth0 dashboard. On the dashboard, users are required to create an application, provide it with an appropriate name, and then choose the Regular Web Application as the type of application to be used. This enables the created application to be conscious of the Blazor application and allows one to control access to this application (Chiarelli, 2019). Once it has been created, one has to note the Auth0 domain, client id, and the clients’ secret and then allocate the http://localhost:5001/callback on the allowed callbacks URL fields and https://localhost:5001/ on the allowed logout URL fields.
The former value informs Auth0 which URL to call back after the authentication of the user is finished while the latter informs the URL where to redirect the user after their logout. Configuration of the Blazor application is then carried out by changing the values obtained from the Auth0 dashboard. This Auth0 is then integrated by installing Microsoft. AspNetCore. Authentification. OpenIdconnect. The Blazor configuration is then configured to enable it support authentification via OpenID Connect. The server is then secured by adding authorize attribute since Auth0 depends on HTTP one has to create a login and logout endpoints. The authorized view component is tasked with controlling access to various segments of the Blazor application. The razor authorization component is then created this enables it only to be accessible to the authorized personnel.

Reference
Chiarelli, A. (2019, November 11). What is Blazor? A Tutorial on Building Web Apps with Authentication. Retrieved from https://auth0.com/blog/what-is-blazor-tutorial-on-building-webapp-with-authentication/

Published by
Essays
View all posts