Search⌘ K
AI Features

Call the Protected API

Explore how to enable a Blazor WebAssembly application to securely call a protected API. Learn to configure the HTTP client for authorized requests with Auth0 access tokens and set the API audience for proper authentication.

In this lesson, we are going to enable the Blazor WebAssembly application to make authorized requests to the weather forecast API.

Create the HTTP client

To make our HTTP request to the API, we need an HTTP client. Fortunately, the .NET platform provides a powerful client.

Let’s move to the Client folder of our solution and install the HTTP client by running the following command:

dotnet add package Microsoft.Extensions.Http

This package allows us to create named HTTP clients and customize their behavior.

We need to make authorized requests to the weather forecast API. This means that the requests must include an access token issued by Auth0.

We create an HTTP client that automatically attaches an access ...