-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Closed
Description
This change only applies to Blazer WebApp tiered projects.
Old behavior
Previously, we used PersistentComponentState in App.razor to pass the access_token to the WebApp.Client project for API calls.
The BaseUrl of RemoteServices in the WebApp.Client project targets the API website.
[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;
[Inject]
private PersistentComponentState PersistentComponentState { get; set; }
private string? Token { get; set; } = default!;
protected override async Task OnInitializedAsync()
{
if (HttpContext.User?.Identity?.IsAuthenticated == true)
{
Token = await HttpContext.GetTokenAsync("access_token");
}
PersistentComponentState.RegisterOnPersisting(OnPersistingAsync, RenderMode.InteractiveWebAssembly);
}
async Task OnPersistingAsync()
{
if (!Token.IsNullOrWhiteSpace())
{
PersistentComponentState.PersistAsJson(PersistentAccessToken.Key, new PersistentAccessToken
{
AccessToken = Token
});
}
await Task.CompletedTask;
}New behavior
In the new Blazer WebApp tiered template, we will make HTTP requests to the current WebApp website instead of the API website.
Why
This way we will no longer need to pass the access_token to the WebApp.Client, because the WebApp uses cookie authentication.
Mitigations
- Change
BaseUrlofRemoteServicesin theWebApp.Client'sappsettings.jsonfile to the currentWebAppwebsite's URL.
{
"RemoteServices": {
"Default": {
"BaseUrl": "https://localhost:44334" // Your WebApp project URL.
},
"AbpAccountPublic": {
"BaseUrl": "https://localhost:44377"
}
}
}
- Change
AddBlazorWebAppTieredServicestoAddBlazorWebAppServicesinConfigureAuthenticationmethod inWebApp.Clientproject.
- builder.Services. AddBlazorWebAppTieredServices();
+ builder.Services.AddBlazorWebAppServices();- Update
App.razorinWebAppproject file as below:
@using Volo.Abp.AspNetCore.Mvc.AntiForgery;
[Inject]
private IAbpAntiForgeryManager AbpAntiForgeryManager { get; set; }
protected override Task OnInitializedAsync()
{
AbpAntiForgeryManager.SetCookie();
return Task.CompletedTask;
}