misoproject / dataset

JavaScript library that makes managing the data behind client-side visualisations easy
http://misoproject.com
GNU General Public License v2.0
1.18k stars 99 forks source link

Importers.Remote - Support Authentication #184

Open gregberns opened 11 years ago

gregberns commented 11 years ago

Currently Dataset can use the Remote Importer to pull data from an external data source. It does not appear that the Remote importer supports an authenticated URL, though.

Without support for authentication, I it seems like developers will have to re-write the Remote Importer and support that code independent of the project.

Since the Remote importer is part of the project, I would think it would be beneficial to the project to support authenticated data sources through it.

Thx for considering Greg

This request is similar to the following issue, but I would argue it is more generic and valuable to all. https://github.com/misoproject/dataset/issues/76

gregberns commented 11 years ago

I think I got this working with a very small change. In "Dataset.Xhr" of the Remote Importer, there are two lines of AJAX code, 'settings.ajax.open()' and 'settings.ajax.send()'. If you call 'settings.ajax.setRequestHeader()', you can set the Auth header.

So to get this implemented, you could use the code below. Then when the developer wants to pass in the auth, they can by supplying 'auth' as a parameter when extending the Remote object.

settings.ajax.open(settings.type, settings.url, settings.async); if (settings.auth) { settings.ajax.setRequestHeader('Authorization', settings.auth); } settings.ajax.send(settings.data || null);

I don't know if this is 'best practice' or would be considered good coding(I'm a bit of a nube), but I think it works.