Skip to content

Commit c44f6aa

Browse files
authored
Blazor WASM security updates (#19844)
1 parent 199782d commit c44f6aa

4 files changed

Lines changed: 310 additions & 42 deletions

File tree

aspnetcore/blazor/security/server/additional-scenarios.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,31 @@ In the `App` component (`App.razor`), resolve the service and initialize it with
107107
}
108108
```
109109

110+
Add a package reference to the app for the [Microsoft.AspNet.WebApi.Client](https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Client) NuGet package.
111+
110112
In the service that makes a secure API request, inject the token provider and retrieve the token to call the API:
111113

112114
```csharp
115+
using System;
116+
using System.Net.Http;
117+
using System.Threading.Tasks;
118+
113119
public class WeatherForecastService
114120
{
115-
private readonly TokenProvider _store;
121+
private readonly TokenProvider store;
116122

117123
public WeatherForecastService(IHttpClientFactory clientFactory,
118124
TokenProvider tokenProvider)
119125
{
120126
Client = clientFactory.CreateClient();
121-
_store = tokenProvider;
127+
store = tokenProvider;
122128
}
123129

124130
public HttpClient Client { get; }
125131

126132
public async Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
127133
{
128-
var token = _store.AccessToken;
134+
var token = store.AccessToken;
129135
var request = new HttpRequestMessage(HttpMethod.Get,
130136
"https://localhost:5003/WeatherForecast");
131137
request.Headers.Add("Authorization", $"Bearer {token}");

0 commit comments

Comments
 (0)