Grid.Blazor icon indicating copy to clipboard operation
Grid.Blazor copied to clipboard

Authenticated grid loading problem

Open matteoventuri7 opened this issue 5 years ago • 2 comments
trafficstars

When I try to load from authenticated API errors occurred.

Page code:

protected override async Task OnParametersSetAsync()
    {
        string url = Navigation.BaseUri + Endpoint;

        if (NeedAuthorization)
        {
            var tokenResult = await AuthenticationService.RequestAccessToken();

            if (tokenResult.TryGetToken(out var token))
            {
                httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.Value}");
            }
            else
            {
                Navigation.NavigateTo(tokenResult.RedirectUrl);
            }
        }

        var query = new QueryDictionary<StringValues>();

        var client = new GridClient<T>(httpClient, url, query, false, Endpoint + "Grid",
            Columns);
        _grid = client.Grid;

        _task = client.UpdateGrid();
        await _task;
    }

Browser shows errors. After a while, server API receives correct invocation and return rights data, but it's too late.

Browser log: https://pastebin.com/UM6g0fPt

matteoventuri7 avatar Apr 21 '20 10:04 matteoventuri7

Blazor WA returns very few error info and makes it difficult to debug.

You could try to move all authentication code to the OnInitialized method, but not sure if it will work fine consistentlly.

I think the best option is to run all authentication stuff in the App.razor component, and authorization in the NavMenu.razor component and the back-end web services.

gustavnavar avatar Apr 22 '20 11:04 gustavnavar

You could try to move all authentication code to the OnInitialized method, but not sure if it will work fine consistentlly.

Same error.

I think the best option is to run all authentication stuff in the App.razor component, and authorization in the NavMenu.razor component and the back-end web services.

No, because I need to know server site who is calling API by JWT authorization token.

matteoventuri7 avatar Apr 22 '20 12:04 matteoventuri7