Search⌘ K
AI Features

Protect the Web API

Explore how to secure your Blazor WebAssembly application's Web API by integrating Auth0 authentication. Learn to configure Auth0 in the server project, install and use JwtBearer for token validation, and enforce authorization on API endpoints to prevent unauthorized access.

To protect the weather forecast API from unauthorized access, we need to configure and modify the Server project of the Blazor WebAssembly solution.

The server configuration

First, we need to let our API know about Auth0 settings. Therefore, let’s move to the Server project, open the appsettings.json, and apply the changes shown below:

Node.js
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Auth0": {
"Domain": "YOUR_AUTH0_DOMAIN",
"Audience": "YOUR_API_IDENTIFIER"
}
}

We added the "Auth0" section in the configuration file with two keys— "Domain" and "Audience". Let’s replace the ...