jQWidgets Forums
jQuery UI Widgets › Forums › Plugins › Data Adapter › Token authentication
Tagged: authentication
This topic contains 6 replies, has 3 voices, and was last updated by mpotts 8 years, 10 months ago.
-
AuthorToken authentication Posts
-
I need to access data in a REST API source requiring token authentication.
TO access the data I need to send a request header ‘Authentication’ ‘Bearer xxxx’, but it is not working. For example:var source = { dataType: "json", dataFields: [ { name: 'id', type: 'number' }, { name: 'name', type: 'string' }, { name: 'upid', type: 'number' } ], hierarchy: { keyDataField: { name: 'id' }, parentDataField: { name: 'upid' } }, id: 'id', url: "http://localhost:9000/ird/v1/areas" }; var dataAdapter = new $.jqx.dataAdapter(source, { beforeSend: function (jqXHR, settings) { jqXHR.setRequestHeader('Authorization', 'Bearer xxxxxxx'); } });
The beforeSend function is being called but the header is not being set. Any clues?
Hi gapfranco,
No, we do not know why the header is not
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
But it should, right? I mean, the use of beforeSend is correct? Any ideas on how to debug it? There is no error messages.
Or must we assume that the request header cannot be set? That would be a show stopper on our use of jqwidgets.Best regards,
Hi gapfranco,
Sorry to learn that. This code seems like a “hack” to me. According to me, the contentType should be used instead.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
A “hack”? I just followed the documentation:
beforeSend(jqXHR, settings): A pre-request callback function that can be used to modify the jqXHR
There is no exemples on usage.
How can I set a request authorization header using the contentType?
And how to use this library to access the Twitter API, for exemple, that also requires an Authorization header? For exemple:POST /1/statuses/update.json?include_entities=true HTTP/1.1 Accept: */* Connection: close User-Agent: OAuth gem v0.4.4 Content-Type: application/x-www-form-urlencoded Authorization: OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog", ... Content-Length: 76 Host: api.twitter.com
There is the Content-Type AND there is the Authorization headers. The question is: How to set that Authorization header?
Best regards,
Hi gapfranco,
I believe xhrFields should be used in this case, too. We don’t have such field so your choice is to use basic jQuery Ajax call.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi All,
This approach (beforesend: … setRequestHeader …) works for me and includes the custom header I specify in the HTTP request.
However the inclusion of a custom header may cause the browser to precede the HTTP request with a pre-flight “OPTIONS” request, which must be responded to with a “200 Ok” including an appropriate “Access-Control-Allow-Headers: …” before the actual HTTP request will be sent.
“Authorization” is a standard HTTP header for basic authentication and should probably not be used for a fully custom header.
Hope this helps.
Mark
-
AuthorPosts
You must be logged in to reply to this topic.