FileManager Feature fails if Identity Platform used

Ive been successful in setting up a blazor feature template example without authentication.

When i enable identity platofrm, i have progressed to have a working active directory login, so authentication is working.


The file manager fails with the following:

blazor.server.js:21 [2021-12-16T11:24:26.290Z] Error: System.Text.Json.JsonException: '<' is an invalid start of a value. Path: $ | LineNumber: 2 | BytePositionInLine: 0. ---> System.Text.Json.JsonReaderException: '<' is an invalid start of a value. LineNumber: 2 | BytePositionInLine: 0. at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes) at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker) at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first) at System.Text.Json.Utf8JsonReader.ReadSingleSegment() at System.Text.Json.Utf8JsonReader.Read() at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) --- End of inner exception stack trace --- at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex) at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.JsonSerializer.ReadCore[TValue](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.JsonSerializer.ReadCore[TValue](Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options) at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, Type returnType, JsonSerializerOptions options) at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options) at Syncfusion.Blazor.FileManager.SfFileManager`1.GetData[T](String action, T[] data, T targetData, String path, FileManagerAjaxSettings ajaxSettings, Boolean showHiddenItems, String name, String newName, String[] names, Boolean caseSensitive, String searchString, String targetPath, String[] renameFiles) at Syncfusion.Blazor.FileManager.SfFileManager`1.Read[T](T[] data, T targetData, String path, FileManagerAjaxSettings ajaxSettings, Boolean showHiddenItems) at Syncfusion.Blazor.FileManager.SfFileManager`1.OnAfterRenderAsync(Boolean firstRender) at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)

I assume this is because of some invalid html being returned, but i cant see how to read the inner contents of the underlying error. Any suggestions on what must be changed to get the filemager working?


11 Replies

KR Keerthana Rajendran Syncfusion Team December 17, 2021 01:18 PM UTC

Hi Daniel, 

The reported issue with File Manager only occurs when the Authentication is included in Blazor application due to framework limitations. We face similar issue with Http Client call in default Blazor application as well.  

We have raised queries regarding this Http Client issue in general forums and tracking it closely for the solution. 


We request you to track the above GitHub link for further updates on this. 

Regards, 
Keerthana R. 



DR Daniel Reibelt December 18, 2021 04:11 AM UTC

Thanks, I have followed as requested.


I also note that I have extracted the response, and it is the login request form from login.microsoft.com, so it appears token is not being passed to the http client, and the subsequence filemanager controller api call.


I have checked the HTTPClient service prior to syncfusion service.


I have tried injecting the HTTP client with the headers as per suggestion on various pages, but still this kicks to the login page.


I also encounter a similar issue with a datagrid/datamanager webapiadaptor page where using EF.


UPDATE: 

I discovered a nuget version mismatch which was leading to my above scenario.


After upgrading, i now face the issue as discribed in the github article. Ultimately, this is creating very similar symptoms, but i do progress a little further.



KR Keerthana Rajendran Syncfusion Team December 20, 2021 02:27 PM UTC

Hi Daniel, 

Query: “I also encounter a similar issue with a datagrid/datamanager webapiadaptor page where using EF.”  
  
From your query, we understand that you are facing an issue while enabling the Authorization with Identity Server in SfDataManager component. We would like to inform you that authorization bearer token can be sent as Custom Header using Headers property of SfDataManager.    
  
We have already documented this topic in our UG documentation, kindly refer to the below link. 
  
  
Also refer our public forums for your reference  
  
  
Please get back to us if you have further queries or if you are still facing the reported issue with DataGrid/DataManager component. 

Kindly track the provided GitHub link for further updates on using HTTP Client call with Authorization in Blazor application.  

Regards, 
Keerthana R. 



DR Daniel Reibelt replied to Keerthana Rajendran December 20, 2021 10:43 PM UTC

Thanks for the follow up.


To clarify, i have 

- successfully logged in using Microsoft.Identity.Web

 - can successfully pull downstream data using graph api 


When calling OnInitialised

 var token = await TokenAquisition.GetAccessTokenForUserAsync(new string[] { "User.Read" });

token is set

then call 

_httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);

a token is set


for testing i used this httpClient to make a GetAsync call to my controller at this point and still requests login, so its not a SF issue

if I manually type the Controller address in new tab, it adheres to loggin session, and does not request login


this is the exact method i use for Microsoft Graph API calls, which function perfectly.


My instinct says my startup has something wrong, but feel ive exhaused my search abilities here. I can attach if you would like.



KR Keerthana Rajendran Syncfusion Team December 21, 2021 06:16 AM UTC

Hi Daniel, 
 
Sorry to inform that we couldn’t help you further with the initial error “System.Text.Json.JsonException: '<' is an invalid start of a value” reported in this ticket since it is framework limitation.  
 
We are closely tracking on the below GitHub link to come up with a better solution for this Authorization scenario. 
 
 
However, if you are facing any other issues, please share your File Manager project with exact replication steps to check whether we can help you in that.  
 
Regards, 
Keerthana R. 



DS Dieter Stapelberg September 27, 2022 06:50 PM UTC

Hello guys, exact same use case and issue for me, as Daniel described:


"Ive been successful in setting up a blazor feature template example without authentication.

When i enable identity platofrm, i have progressed to have a working active directory login, so authentication is working.


The file manager fails with the following:

blazor.server.js:21 [2021-12-16T11:24:26.290Z] Error: System.Text.Json.JsonException: '<' is an invalid start of a value. Path: $ | LineNumber: 2 | BytePositionInLine: 0. ---> System.Text.Json.JsonReaderException: '<' is an invalid start of a value. LineNumber: 2 | BytePositionInLine: 0. at"...


Syncfusion gents - considering the age and the status of the bug (still in Backlog, and still in investigate) is there a workaround, or anything else you could suggest?

Daniel - if you do read this - did you find an acceptable solution to this while maintaining the identity framework authorization?


Thanks in advance, one of those roadblocks >.<

Dieter



DS Dieter Stapelberg replied to Dieter Stapelberg September 27, 2022 07:44 PM UTC

Hey all, while not ideal, here is an immediate workaround. I allowed anonymous access on the controller with the [AllowAnonymous] modifier in the controller. This selective security mod is acceptable, as this is an intranet corporate application. Hope this helps someone else.


Here's the snippet. I renamed the SampleDataController.cs which is part of the FileManager setup documentation to FileManagerController.cs. Modify whichever file is appropriate:


----------

namespace filemanager.Server.Controllers {

  [Route("api/[controller]")]

  [AllowAnonymous]

  public class FileManagerDataController : Controller {

    public PhysicalFileProvider operation;

    public string basePath;

----------



IL Indhumathy Loganathan Syncfusion Team September 28, 2022 09:45 AM UTC

Hi Dieter,


We were that you have find a workaround way to resolve the issue. However, the reported issue is caused by sample level Windows authentication. As explained earlier, we have used HttpClient for web API calls in FileManager to perform all file operations. Even the basic HttpClient call has the same issue while including the authentication code. We have already raised a general query on this issue.


As of now, you can either comment out the authentication related codes in your Startup.cs file, else follow the steps mentioned in the below blog to enable Authentication in Blazor Server side application to avoid the issue.


https://www.syncfusion.com/blogs/post/easy-steps-create-a-blazor-server-app-with-authentication.aspx


Please check whether the shared details helpful for you and get back to us if you need any further assistance.


Regards,

Indhumathy L



DA Dave Arnoldi April 26, 2023 08:19 PM UTC

Hi 

Is there any news on a proper fix for this issue yet?


I see in the github issue tracker that it was suggested that the calls to the azure blob sdk be implemented inside a service instead of through http calls. This makes a lot of sense and would be more performant. 


Are you planning on implementing such a solution? 


Thanks

Dave 



IL Indhumathy Loganathan Syncfusion Team April 27, 2023 07:50 AM UTC

Hi Dave,


We have considered providing support to customize the HttpHandler of the Blazor File Manager component. By using this support, you can modify HttpClient using the HttpHandler to achieve Windows authentication for the Blazor File Manager. This feature will be included in any of our upcoming releases. Generally, we will plan any feature implementation based on customer request count, feature rank, and wish list plan. You can track the feature status through the below link,


https://www.syncfusion.com/feedback/32624/provide-support-to-customize-the-httphandler-in-blazor-file-manager


Regards,

Indhumathy L



DA Dave Arnoldi replied to Indhumathy Loganathan April 27, 2023 08:03 AM UTC

Thanks for the response.


Voted 8)


Loader.
Up arrow icon