Flex HTTPService and Basic Authentication
For an internal project I created an Adobe AIR application that connects to the Basecamp API. We have been using the application since the launch of Adobe AIR. Back then I had a problem connecting to the API using the HTTPService, because the combination of Basic Authentication and the https protocol was not supported. After several unsuccessful experiments I decided to go for an approach that uses a PHP Proxy on the server that delegates the calls to the Basecamp API. However the downside of this approach is that this setup needs extra configuration and a server-side deployment.
This week I got the chance to pick it up again and I stumbled upon this forum post on the Basecamp Forum. I found this piece of code posted on Verveguy’s blog. And it actually did the trick.
username:String, password:String):void
{
//add the header to request
var enc:Base64Encoder = new Base64Encoder();
enc.encode(username + ":" + password);
service.headers["Authorization"] = "Basic " + enc.toString();
}
For everybody who needs to connect a Flex application to an API that uses https in combination with Basic Authentication, here is the solution. All credits to the original blog post.
7 Responses to Flex HTTPService and Basic Authentication
Leave a Reply Cancel reply
Lifestream
-
Checking out CocoaPods - an Objective-C library manager > https://t.co/xdLU5OgO— February 1st via Twitter
-
Finally found some time to dive into iOS5 Storyboarding.— February 1st via Twitter
-
RT @robbedoes: Fun to watch: an interview w/ the sound designer of Angry Birds: http://t.co/lDARIGbB— February 1st via Twitter
-
@wuotr Also, check this out: Flood Fill > http://t.co/SpweLK0N ;)— January 30th via Twitter
-
Love it! Timesaver++ CocosBuilder, a tool for graphically laying out sprites, layers and scenes for @cocos2d > http://t.co/Jrb8233D— January 30th via Twitter
-
RT @rwenderlich: Awesome list of Cocos2D source code projects, extensions and code from @iuridium: http://t.co/ovwLYhCv— January 29th via Twitter
-
Moo! @ Kinderboerderij kiewit http://t.co/tYBlLsvH— January 29th via Twitter
-
I've been doing my epic chores and just leveled-up. I'm a Level 8 Well-groomed Clansman now! #EpicWinApp— January 27th via Twitter
-





[...] application is not that trivial as it would sound. A while ago I wrote a blog post about this (read it here), but this approach only works when you run it from an AIR application. The same code doesn’t [...]
[...] But again like the Twitter API, the Basecamp API uses Basic Authentication (see my previous post: Flex HTTPService and Basic Authentication) and also in the case of Silverlight, it appeared to be a [...]
@hufkens Running into basic auth problem on flex app. Did you commit changes http://bit.ly/w7pJu to your svn repo http://bit.ly/cQC3SF ?thnx
Has Flex SDK 4.1 broken this in your project? I was using same technique and have run into problems with 4.1.
Could be, I have not tested it with Flex 4.1 yet.
Thanks, you just saved me. Worked fine in Flex 4.5.1 in a mobile app.
private function authAndSend(service:HTTPService):void
{
var encoder:Base64Encoder = new Base64Encoder();
//encoder.insertNewLines = false; // see below for why you need to do this
encoder.encode(“test99:198$elect”);
service.headers["Authorization"] = “Basic ” + encoder.toString();
service.send();
}
I am not able to get it work in Flex Mobile 4.5
Jack can you help me