damienbod / Blazor.BFF.OpenIDConnect.Template

Blazor.BFF.OpenIDConnect.Template, Blazor WASM hosted in ASP.NET Core using OpenID Connect BFF (server authentication)
https://www.nuget.org/packages/Blazor.BFF.OpenIDConnect.Template/
MIT License
122 stars 15 forks source link

Intermittent Error on Azure #53

Open DreamDelerium opened 8 months ago

DreamDelerium commented 8 months ago

Hello, I have developed my app using this template and it works fine running locally. But, when I run it on Azure I get this intermittent error:

blazor.webassembly.js:1 Exception: Microsoft.JSInterop.JSException: Could not find 'getAntiForgeryToken' ('getAntiForgeryToken' was undefined).

and this will be followed by a number of errors in my services (that rely on the token I assume). This error will resolve itself if I refresh the page but it does happen often. Is there a way to resolve this issue? I have Azure .Net set to 7 (as in my local environment) and I have tried turning WebSockets on.

My setup is a little different from how you setup your services. Here is an example:

Client/Services/MyService.cs:

    ```
    private readonly IAntiforgeryHttpClientFactory _httpClientFactory;
    public AsaDomainService(IAntiforgeryHttpClientFactory httpClientFactory)
    {
        _httpClientFactory = httpClientFactory;
    }
    public async Task<ServiceResponse<List<ObjectDTO>>> GetAllObjects()
    {
        var client = await _httpClientFactory.CreateClientAsync("default");
        var result = await client.GetFromJsonAsync<ServiceResponse<List<ObjectDTO>>>("api/MyObjects/get-all-objects");
        return result;
    }

**Server/Contorller/MyController.cs**

private readonly IObjService _ObjService; public MyController(IObjService objService) { _objService = objService; } [HttpGet("get-all-objects")] public async Task<ActionResult<ServiceResponse<List>>> GetAllObjects() {
return Ok(await this._objService.GetAllObjects(true)); }


**Server/Services/MyServerService.cs**
//this service does the DB calls and returns the object

Thank you for the assistance!
damienbod commented 8 months ago

Thanks for reporting this, I will look into this, I have not noticed this with my prod deployments. Validating.

worse case, you could switch to a custom header CRSF protection, if this is a big problem.

Greetings Damien