HTTP Authentication with Flash

For posterity and the rest of the internet, here is the trick to get flash to load variables using LoadVars on a password protected site, when it's using http authentication. I have found parts of examples, but not an actual working example, so here it is.

First of all, get the actionscript Base64 encoder class.
Put it in your classpath or the same directory as your .fla file.

Then do something like this:

var loadvars = new LoadVars();
var str = Base64.Encode("username:password");
loadvars.addRequestHeader("Authorization:", "Basic "+str);
loadvars.load("some_password_protected_url.php");

That's all.

RSS feed | Trackback URI

15 Comments »

Comment by Jason Nussbaum
2005-12-30 19:04:14

Y'know, that's the whole reason I ported that code – I was playing around with the del.ico.us api. Should've put up an example, but I haven't had time to get back into it.
Sometime soon, hopefully. In the meantime, thanks for posting this…

Comment by Brian Meidell
2005-12-31 12:26:50

You're welcome.
Thanks for porting the base64 class :)

(Comments wont nest below this level)
 
Comment by Inan Olcer Subscribed to comments via email
2006-07-14 17:45:21

Base 64 works well but, when i test it with delicious api i could not get satisfied.
Descussion on livedocs ends with "you cannot access headers directly from Flash" discussion. Is there any way to reach delicious api without asp of php gateway which sends headers for flash and returns results back? Thanks.

(Comments wont nest below this level)
Comment by Kai Zimmer Subscribed to comments via email
2006-08-07 11:16:58

Hi Inan,
you're only able to modify the header via addRequestHeader when using the post method. You could use the sendAndLoad method to achieve that.
Cheers, Kai.

 
 
 
Comment by Marcin
2006-01-02 14:51:23

Here You will find ASCrypt extension for Flash. It is very handy.

Regards
Marcin Andrzejewski

 
Comment by şebnem ferah
2007-08-13 02:19:36

Sometime soon, hopefully. In the meantime, thanks for posting this.. one day…

 
Comment by nlking
2007-08-16 11:04:25

This solution does not work anymore in IE 7. :-(

Has someone fixed this in IE7?

 
Comment by Mukul
2007-10-11 06:59:00

hi
I am using flash and actionscript client to access my web service which require authentication. I am using the above technique it works fine in firefox but no headers are sent in case of IE…Can anyone help me for this..I need it quick..
thanks

Comment by Frank Subscribed to comments via email
2010-04-19 15:54:33

Hi Mukul,

its more than two years ago, but Ive one question about what you wrote:

I am using flash and actionscript client to access my web service which require authentication. I am using the above technique it works fine in firefox…

How exactly you create the access to a webservice which requires authentication?

Thats my standard-AS2 to call a webservice:

var my_wsc:WebServiceConnector = new WebServiceConnector();
my_wsc.WSDLURL = http://xyz/webservice.asmx?WSDL;
my_wsc.addEventListener(result, my_listener);
my_wsc.operation = WS-Operation;
my_wsc.params = [...];
my_wsc.trigger();
function my_listener(obj:Object) {
var res:Object = obj.target.results;
}

(Comments wont nest below this level)
 
 
Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.