Does it possible to use both jsonp and Bearer Authorization in an Ajax call ?
Does it possible to use both jsonp and Bearer Authorization in an Ajax call ?
Hello,
I face an strange things when I trying to send a request to a remote server protected by Bearer authorization : my bearer token is not include in in request .
This is the code :
editorTranslations = new $.fn.dataTable.Editor({
ajax: {
create: {
type: "GET",
url: "{{ urlCreate }}",
dataType: "jsonp",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Bearer {{ bearerToken }}"
},
},
edit: {
type: "GET",
url: "{{ urlUpdate }}",
dataType: "jsonp",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Bearer {{ bearerToken }}"
},
},
remove: {
type: "GET",
url: "{{ urlDelete }}",
dataType: "jsonp",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Bearer {{ bearerToken }}"
},
}
},
...
}
And this is the request sent :
As you can see, no bearer
But I remove the dataType: "jsonp", the bearer is well include :
So, just to know, is it possible to use both jsonp and bearer Authorization? Or jsonp means no bearer ?
Note : as explained here https://datatables.net/forums/discussion/comment/64693/#Comment_64693, I use GET for all my REST method because of jsonp.
Thanks
Replies
Ok, found this https://stackoverflow.com/questions/7433556/jquery-jsonp-ajax-authentication-header-not-being-set, so it seems that not, this is not possible. And this is not related to Datatable.
Yes - JSONP is incompatible with that unfortunately since it is just inserting a
<script>
tag and you can't set headers for that.The only way around this is to use something other than JSONP. If it is a remote server with a different URL, then you would need a proxy on your own host server.
Allan
Exactly, this is what I did, and it works .