I have been trying to see a way to add authentication to the RESTDataSource. Is there a way we can have it add a custom HTTP Header when it makes it calls, or have it pass the username and password? We don't want to pass that on the URL.
Thanks,
Eric
OK, next question: how can I handle it gracefully if the authorization fails? I have an igGrid with its dataSource set to an igDataSource. If the authorization succeeds then all well and good, the data appears in the grid. But if authorization fails it just sits there spinning. I'm not entirely clear which line actually makes the request to the REST service.
Thanks, John
In case it helps anybody, I got this working with:
xhr.setRequestHeader('Authorization', 'some value');
Thanks, this might work.
Hello Eric,
While the ajax calls made by the RESTDataSource (or any other igDataSource derivative) cannot be directly modified, you could set global rules for all of them through the ajaxSetup jQuery method. For example:
:
$.ajaxSetup({ beforeSend: function(xhr) { xhr.setRequestHeader('x-auth-header', 'some value'); } });
This will set the 'x-auth-header' to all ajax requests including those made by the RESTDataSource. You can also refer to this SO thread for more information.
I hope this helps! Thank you for using Infragistics forums!
Best regards,
Stamen Stoychev