Kendo Autocomplete Authorization Headers

2 posts, 0 answers
  1. Steven
    Steven avatar
    7 posts
    Member since:
    Nov 2015

    Posted 19 Nov 2015 Link to this post

    I can't figure out why my Kendo Autocomplete widget is not sending the authorization headers in the request to the server:

    var dataSource = new kendo.data.DataSource({
        type: 'odata',
        serverFiltering: true,
        transport: {
            read: {
                url: myApiUrl,
                type: 'GET',
                beforeSend: function (xhr) {
                    xhr.setRequestHeader('Authorization', myAuthorizationValue);
                }
            }
        }
    });
     
    $('#myAutocompleteField').kendoAutoComplete({
        dataTextField: 'fieldName',
        filter: 'contains',
        minLength: 3,
        dataSource: dataSource
    });

    When I check the server response in dev tools, I am getting a 401 Unauthorized error from the server. Looking at the Request Headers, I don't see the Authorization property at all.

    What do I need to do to get the Authorization header to be included with the request?

     If I just do a typical $.ajax request with the same object as transport.read in the Kendo DataSource parameter, it sends the headers and I get a successful response.

    $.ajax({
        url: myApiUrl,
        type: 'GET',
        beforeSend: function (xhr) {
            xhr.setRequestHeader('Authorization', myAuthorizationValue);
        },
        success: function(res) {
            console.log('success!');
            console.log(res);
        }
    });

  2. Steven
    Steven avatar
    7 posts
    Member since:
    Nov 2015

    Posted 19 Nov 2015 in reply to Steven Link to this post

    I was able to locate another forum post with a similar issue: http://www.telerik.com/forums/odata-not-working-with-custom-authorization-header

    The `type: 'odata'` was causing the headers to not be sent. Not using the type: odata property enabled the authorization headers in the request.

  3. Kendo UI is VS 2017 Ready
Back to Top