How to hit internal API with Authentication in Blazor Server
Can anybody help me with this?
I have a api endpoint in my controller:
[HttpDelete("delete/{id}")]public async Task<IActionResult> DoSomething(int id){ var user = await userManager.GetUserAsync(User);}
[HttpDelete("delete/{id}")]public async Task<IActionResult> DoSomething(int id){ var user = await userManager.GetUserAsync(User);}
And i have a Blazor page where i want to invoke that:
private async Task MyAction(){ var result = await HttpClient.DeleteAsync($"/api/mycontroller/delete/{someId}");}
private async Task MyAction(){ var result = await HttpClient.DeleteAsync($"/api/mycontroller/delete/{someId}");}
I am logged in on my Blazor page and I want to pass along the identity/authentication to the api controller. In my case, the GetUserAsync on the controller side always returns null. I am using the default Identity.Application authentication sheme.
I tried modifing the request header with the data from the IHttpContextAccessor but I didnt get it to work and i dont think this is the way you are supposed to do this.