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

Authenticating to a data source

7 Answers 303 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
luke
Top achievements
Rank 1
luke asked on 10 May 2013, 12:33 AM
Hi there

New to Kendo

Hoping for some direction here. When i use the following code i keep getting a 401 error. The username and password are correct
var dataSource = new kendo.data.DataSource({
                  autoSync: true,
                    
                  transport: {
                    read:  {
                        url: "web service url",
                        beforeSend: function (xhr) {
                //your code
                            xhr.setRequestHeader("Authorization", "Basic username:password"); //i set the username and password to valid settings
            },
                      dataType: "jsonp" // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
                    },
                    update: {
                      url: "web service url",
                      dataType: "jsonp" // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
                    }
                  },
                  schema: {
                    model: { id: "Id" }
                  }
});


If i use eclipse and build an android app i can set the username and password properties of the DefaultHttpClient and i can connect successfully, so it appears the service works (I can also access it via a browser which prompts for credentials and i get the data)

any ideas ??

7 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 13 May 2013, 07:33 AM
Hello,

 The problem is caused by the JSONP dataType setting. jQuery doesn't use an XMLHttp request when performing JSONP requests. As a result you cannot set request headers. Try setting the dataType option to "json" if your service is in the same domain.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
luke
Top achievements
Rank 1
answered on 13 May 2013, 08:13 AM
Thanks for the reply Atanas

I set the dataType option to json with no luck. The service is outside of our domain, and clients will be accessing it via the internet. Anything else you can think of ???

0
Atanas Korchev
Telerik team
answered on 13 May 2013, 08:58 AM
Hi,

Since setting the request header is supported only for json requests I cannot think of a workaround. 

Greetings,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Accepted
luke
Top achievements
Rank 1
answered on 14 May 2013, 06:04 AM
I managed to get this working by encoding the username:password combination

Now just make sense of the data

Luke
0
JonathanElsner
Top achievements
Rank 1
answered on 03 Oct 2013, 07:31 PM
Can someone give an example of this?  I am trying to authenticate to a service outside of our domain so I need to set the authentication header and use jsonp?
If this is not possible what is the recommended way to authenticate with a service outside my domain?
0
Atanas Korchev
Telerik team
answered on 04 Oct 2013, 06:13 AM
Hello Jonathan,

 Setting any HTTP headers isn't possible with JSONP. The latter works by dynamically injecting <script> elements in the page which doesn't allow setting http headers. The only suggestion we can give is to use CORS if possible.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Steve Gray
Top achievements
Rank 1
answered on 15 Apr 2015, 01:20 PM
Can you post your code, please? I'm working on this too.
Tags
Data Source
Asked by
luke
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
luke
Top achievements
Rank 1
JonathanElsner
Top achievements
Rank 1
Steve Gray
Top achievements
Rank 1
Share this question
or