After installing Visual Studio 2010 beta 1 I decided to play around with Silverlight 3 and the new IDE. What better example to try out than connecting a Silverlight client to the Basecamp REST API. 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 problem.
The first thing I tried was adding the Authorization header to the Webclient, like you can do in Actionscript.
String.Format("https://{0}/{1}", basecampUrl, "projects.xml");
var webclient= new WebClient();
Byte[] authbytes =
System.Text.UTF8Encoding.UTF8.GetBytes("username:password");
webclient.Headers["Authorization"] =
"Basic " + Convert.ToBase64String(authbytes);
webclient.DownloadStringCompleted += downloadStringCompleted;
webclient.DownloadStringAsync(new Uri(url));
This didn’t work because the Authorization header can’t be set through code because it is restricted. Check this page for the list of restricted headers. Some can be set through a specific property, but not the Authorisation header. The error message I got was this:
The 'Authorization' header cannot be modified directly
Then I checked out Silverlight 3 and discovered the Credential property. You can set the Credential property to an instance of a NetworkCredential object.
But too bad, the exception I got this time was even more strange:
Seems like there is still something missing in the beta 1 version of Silverlight 3, so please Microsoft fix this or just remove the property if it’s not implemented.
So this means that the only way to get the Basic Authentication working from Silverlight at the moment is writing an extra server-side proxy class that delegates the calls and does the authentication. Or maybe there is another trick in the Silverlight Webclient class.
One Response to Silverlight 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
-





Same problem, I need acess services that are protect using basicAthenticaton, and acess this using silverlight 3 is a great problem. Thank’s for any news…