Basic Authentication with karotz?

151 views
Skip to first unread message

butl

unread,
Jul 19, 2012, 2:59:46 AM7/19/12
to karo...@googlegroups.com
Hey guys

I tried to write a js application for karotz, where I need to do some basic auth stuff.
I want to call a REST Service, where I need to be logged in.

Well, so i tried to use jQuery for handling the authenitaction part like that:

var auth = //my basic auth basic64 encrypted user:password
var data = jQuery.ajax({
type : "GET",
url : url,
beforeSend : function(req) {
req.setRequestHeader("Authorization", auth);
},
success : callback,
dataType : "json"
});

... but i always get the same error: Exception in thread "main" org.mozilla.javascript.EcmaError: ReferenceError: "window" is not defined. (jquery.js#15) 
So there is no "window" defined, because there is no brower-window on the karotz.
After that, I thought about another method i could try. So I decided to use the XMLHttpRequest, but same problem here.

So is there any way to handle basic auth with karotz?

Regards
Lenny

Johnny Baillargeaux

unread,
Jul 19, 2012, 5:56:09 AM7/19/12
to karo...@googlegroups.com
Hello,

Are you talking about an embedded application or are you creating an external web app that will call karotz api ? I am saying that because i don't understand why you are using Jquery.Ajax and not http.get. Otherwise, i would recommend you to play with the user-agent and pass something like  "Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405"  to the header 

Hope this helps,

butl

unread,
Jul 19, 2012, 7:38:38 AM7/19/12
to karo...@googlegroups.com
Hello!

I'm talking about an embedded application. 
And if i do http.get(..) i can't authenticate by using basic auth to our server.
How can I play around with the user-agent when i'm embedded?

Could it be that the problem is, that the  url starts with https and not http?

Anibal Bicho DBZ Capotorto

unread,
May 2, 2013, 6:51:32 AM5/2/13
to karo...@googlegroups.com
I know probably you already gave up on this or found something else, but given that this is the only post that talks about this am going to go ahead and share my experience

a way I found to get around authenticating on a karotz is the following

instead of http.get  use http.post but pass an empty hash as the data and "forge" a header hash with the authorization key which should look something like this


reqheaders = { 'Authorization': "Basic w9e8hrfw89sdsh982y340w9e0sdf=="} // note that the actual key is gibberish from my part , more below
rawdata = http.post(url,{},reqheaders,false); 

and that should work

to "generate that key" if you're on linux you can do a curl -v -I <rest of the parameters that will make your request actually succeed>

and you should see the Authrization: parameter there, just copy and paste the generated string (or google base64 basic auth bla bla bla :D )

Hope this helps 
Anibal "Bicho[DBZ]" Capotorto

Bastien Stefani

unread,
May 11, 2013, 1:02:41 PM5/11/13
to karo...@googlegroups.com
I think you can pass the user and password directly in the url :
Reply all
Reply to author
Forward
0 new messages