Merge pull request #1693 from sbwalker/dev
fix #1691 - AntiForgeryToken header not being set during startup
This commit is contained in:
commit
30fb6fd8e2
|
@ -47,11 +47,13 @@
|
|||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
SiteState.AntiForgeryToken = AntiForgeryToken;
|
||||
InstallationService.SetAntiForgeryTokenHeader(AntiForgeryToken);
|
||||
|
||||
_installation = await InstallationService.IsInstalled();
|
||||
if (_installation.Alias != null)
|
||||
{
|
||||
SiteState.Alias = _installation.Alias;
|
||||
SiteState.AntiForgeryToken = AntiForgeryToken;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -68,8 +70,10 @@
|
|||
{
|
||||
// parameter values are not set when running on WebAssembly (seems to be a .NET 5 bug) - need to retrieve using JSInterop
|
||||
var interop = new Interop(JSRuntime);
|
||||
AntiForgeryToken = await interop.GetElementByName(Constants.RequestVerificationToken);
|
||||
SiteState.AntiForgeryToken = AntiForgeryToken;
|
||||
|
||||
SiteState.AntiForgeryToken = await interop.GetElementByName(Constants.RequestVerificationToken);
|
||||
InstallationService.SetAntiForgeryTokenHeader(SiteState.AntiForgeryToken);
|
||||
|
||||
Runtime = await interop.GetElementByName("app_runtime");
|
||||
RenderMode = await interop.GetElementByName("app_rendermode");
|
||||
}
|
||||
|
|
|
@ -25,8 +25,6 @@ namespace Oqtane.Services
|
|||
|
||||
public async Task<Installation> IsInstalled()
|
||||
{
|
||||
// add antiforgerytoken header so that it is included on all HttpClient calls for the lifetime of the app
|
||||
AddRequestHeader(Constants.AntiForgeryTokenHeaderName, _siteState.AntiForgeryToken);
|
||||
var path = new Uri(_navigationManager.Uri).LocalPath.Substring(1);
|
||||
return await GetJsonAsync<Installation>($"{ApiUrl}/installed/?path={WebUtility.UrlEncode(path)}");
|
||||
}
|
||||
|
@ -50,5 +48,14 @@ namespace Oqtane.Services
|
|||
{
|
||||
await PostJsonAsync($"{ApiUrl}/register?email={WebUtility.UrlEncode(email)}", true);
|
||||
}
|
||||
|
||||
public void SetAntiForgeryTokenHeader(string antiforgerytokenvalue)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(antiforgerytokenvalue))
|
||||
{
|
||||
AddRequestHeader(Constants.AntiForgeryTokenHeaderName, antiforgerytokenvalue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,5 +41,11 @@ namespace Oqtane.Services
|
|||
/// <param name="email">Email of the user to be registered</param>
|
||||
/// <returns></returns>
|
||||
Task RegisterAsync(string email);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the antiforgerytoken header so that it is included on all HttpClient calls for the lifetime of the app
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
void SetAntiForgeryTokenHeader(string antiforgerytokenvalue);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user