viezel / napp.alloy.adapter.restapi

RestAPI Sync Adapter for Titanium Alloy Framework
197 stars 102 forks source link

HTTP Basic Auth implementation #3

Closed apsylone closed 11 years ago

apsylone commented 11 years ago

I would like to use the adapter with HTTP Basic Auth. It seems like I have to modify the file in order to have the "username" and "password" headers set.

It would be really useful to implements the method.

viezel commented 11 years ago

you can use the header functionality, look here: https://github.com/viezel/napp.alloy.adapter.restapi/blob/master/restapi.js#L51

apsylone commented 11 years ago

Yes but I think we should maybe use the class properly : http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Network.HTTPClient-property-password http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Network.HTTPClient-property-username http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Network.HTTPClient-property-withCredentials

viezel commented 11 years ago

authString: 'Basic ' + Titanium.Utils.base64encode(username+':'+password),

viezel commented 11 years ago

no, because you cannot access the httpclient with standard backbone methods. This is why header is used..

apsylone commented 11 years ago

You should maybe put an example in the documentation so... :-) Or explaining me 'how to' add headers :-)

viezel commented 11 years ago

sure.. Its all in the Backbone docs..

collection.fetch({
    headers: {
        Authorization: 'Basic ' + Titanium.Utils.base64encode(username+':'+password)
    }
});
apsylone commented 11 years ago

Great ! Really thanks for your help... Sorry for the question, i'm not comfortable with Backbone...

viezel commented 11 years ago

sure thing.. :)

bcooke commented 10 years ago

Just wanted to throw in that the param name should be 'headers' rather than 'header'

Threw me off for a bit.

viezel commented 10 years ago

sorry about that.. Ive updated the comment.

bcooke commented 10 years ago

No worries. Thanks for the great adapter. Cheers!