Angular HTTP Interceptor is not honoured in odata calls

Posted by: seaninglis on 10 December 2021, 6:42 am EST

    • Post Options:
    • Link

    Posted 10 December 2021, 6:42 am EST

    I have an Angular app with an HTTP interceptor that adds a JWT Bearer token to an Authorization header.

    This works as expected for API calls I make directly from my Angular App, but in 5.20213.824 this interceptor is not triggered when a FlexGrid is bound to an ODataCollectionView and the view fetches data on my behalf. Returning / paging data results in a series of 401s…

    I can manually fix this issue by supplying a value to the requestHeaders property of the ODataCollectionView on initialisation and making sure it’s kept up to date, but is this expected behaviour?

    Is there anything I should do to ask the ODataCollectionView to use Angular’s HttpClient or does it just need to do it’s own thing?

  • Posted 13 December 2021, 8:33 am EST

    Hi Sean,

    This is the expected behavior. Angular interceptor works only if the HTTP requests are made using its HttpClient module, calls outside of HttpClient are not visible to the interceptors. In case of wijmo, it uses the underlying XMLHttpRequest object to make http calls, that is why, they cannot be handled using the angular HttpInterceptor.

    If you want to intercept the wijmo http calls, then you may override the wijmo’s httpRequest method and add the required logic. You need to have code something similar to the following:

    
    var oldHttpRequest = window["wijmo"].httpRequest;
    window["wijmo"].httpRequest = function(){
        console.log("making http call", arguments);
        var req = oldHttpRequest.apply(this, arguments);
        return req;
    }
    

    Regards

    Sharad

  • Posted 13 December 2021, 10:05 am EST

    Understood.

    As long as I know this is expected behaviour, I can just subscribe to changes in the JWT and update the headers property of the collection view on the fly.

    Thanks for the workaround - it’ll be useful if I find something more exotic I haven’t allowed for.

  • Posted 14 December 2021, 1:01 am EST

    If you just need to update the request headers then you may just use the requestHeaders property. For more complicated intercept scenario you may use the suggested workaround.

  • Posted 14 December 2021, 8:49 am EST

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels