Monday, April 23, 2012

Integrating BrowserId with MVC3

Recently I read about BrowserId in Web Designer magazine.  It seems that BrowserId removes the burden of maintaining passwords within your application.  As such I became quite interested.  I set out to get it working with MVC.  The example in WD was with PHP.   I don't do PHP, for no other reason than I just haven't been exposed to it. 

I found some hints along the way on how to integrate it with Asp.net.
First I found this blog; http://www.eggheadcafe.com/tutorials/asp-net/7784b8c5-51ed-4aa9-b837-ed4084924ee8/implementing-browserid-signin-with-aspnet.aspx.  That put me halfway there but the problem was that that blog demo'ed it using Asp.net webforms.   So I made it my mission to integrate it with MVC.   The browserid backend code was encapsulated in it's own class so it wasn't very difficult.

I don't want to say much about how I got it working other than to point you to the demo site, the github repository and some other resources.  These resources have all the information you need to see it in action for yourself.

Github Repo (My Version): https://github.com/fernandozamoraj/BrowserIdDemoWithMVC3
Demo Website (My Version): http://browseridwithmvc3demo.apphb.com/

I also later found another implementation by someone else.  Below are those links.  His implementation may be more correct than mine.

Github Repo (Rajeesh): https://github.com/cvrajeesh/NBrowserID
Demo Website (Rajeesh): http://nbrowserid.apphb.com/
Rajeesh's Post: http://www.rajeeshcv.com/post/details/46/integrating-browserid-in-to-your-asp-net-mvc-application

 If you want a good explanation of how to access BrowserId I reommend you take a look at Rajeesh's blog post above.  Here is a quick summary of what you need:

  1. You must include the browserid script from https://browserid.org/include.js
  2. You need a Sign In button that triggers the a call to NagivatorId.GetVerifiedEmail
  3. Forward the assertion value from the call back to some BrowserId code.
  4. If the assertion is valid or invalid direct the user accordingly.
 I hope this arms you with enough knowledge to conquer BrowserId.  I am still playing around with it myself and am also researching other decentralized login options.

Until next time.... happy coding.

No comments: