This is a migrated thread and some comments may be shown as answers.

Kendo Autocomplete Authorization Headers

1 Answer 165 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 19 Nov 2015, 02:33 PM

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);
    }
});

1 Answer, 1 is accepted

Sort by
0
Steven
Top achievements
Rank 1
answered on 19 Nov 2015, 06:45 PM

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.

Tags
Data Source
Asked by
Steven
Top achievements
Rank 1
Answers by
Steven
Top achievements
Rank 1
Share this question
or