Extending DotNetOpenAuth for Facebook login – with email scope


It’s a mixed world of code out there and in this instance .net was the platform. Why make the wheel when there are so many useful tools like DotNetOpenAuth. Simple to setup for Google Authorization, facebook left a little to be desired, and, the tools were all there.

The Frustration: There isn’t just a simple write-up to add scope variables to DotNetOpenAuth for facebook permissions

The Solution: ApplicationBlock. DotNetOpenAuth includes a set of code extensions called ApplicationBlock found under the Samples folder of the package. There are two files for facebook: FacebookClient.cs and FacebookGraph.cs; that handle all the heavy lifting for you.

  1. download the package for your .net version
  2. copy the files into your App_Code directory
  3. copy the sample code from facebook.aspx found under the OAuthClient Samples folder
  4. add the optional parameter when calling the RequestUserAuthorization() command to initially login the user (vb example below)
    Dim scope As New Collections.Generic.List(Of String)
  5. This forces facebook to request the user to authorize access to their email address – add the fields as necessary to gain access to other data

Here is a more detailed tutorial on installing The ApplicationBlock into your Project.