Facebook/ Twitter with Dotnetopenauth

Facebook/ Twitter with dotnetopenauth?

At the time of me answering this question, DotNetOpenAuth has a public Community Tech Preview (CTP) which is available to download.

Pew Pew

  1. Download that source code. Should be a .7z file. You can use 7-Zip to unzip the code if you don't already have it (it's free).
  2. Open up the samples source code solution in Visual Studio. I'm using VS2010 but I think there's also a VS2008 solution file.

More Pew Pew


  1. Now, open up the web.config file for the OAuthClient project.
    Sample Image

  2. Next, edit the following settings :-

    <!-- Facebook sign-up: http://developers.facebook.com/setup/ -->

    <add key="facebookAppID" value="------"/>

    <add key="facebookAppSecret" value="------------"/>

You can get these values from your application on Facebook.


  1. Debug/Run the OAuthClient Web Application. This will start an instance of Cassini/Visual Studio Developer Server and a web browser should open:

Sample Image

Voilà! you can now connect to Facebook to log in.

If you get errors, then you need to make sure that:

  1. You've manually changed the Facebook app settings in your web.config file.
  2. You've correctly setup your app settings in the Facebook developer website.

Utilising the SelectorProviderButton with facebook/twitter in DotNetOpenAuth 4.0 CTP

DotNetOpenAuth v3.4.x fully supports OAuth 1.0a, which is all that Twitter uses. So you should have no problem authenticating with Twitter.

Facebook uses OAuth 2.0, an older draft of the unfinalized spec, that is. So yes, you either code this up by hand in your app (which is actually quite easy) or you can use an (older) CTP of DotNetOpenAuth OAuth 2.0 preview. I say older because the newer builds of OAuth 2.0 preview implement a more recent draft than Facebook does, so it's incompatible.

I recommend given the crazily ill-state of affairs with OAuth 2.0, that you just follow Facebook's docs as an OAuth 2.0 client and code up the 2-3 URLs yourself for your app to log into Facebook for now.

BTW, there's no way currently to use SelectorProviderButton's with the OAuth protocol (1.0a or 2.0). It's strictly an OpenID feature.

How to log in with Facebook using DotNetOpenAuth

Facebook implements an older OAuth 2 spec than the latest DotNetOpenAuth beta does. To interop with Facebook, you should use the CTP of v3.5 of DotNetOpenAuth to avoid the 400 Bad Request error.

DotNetOpenAuth and Facebook

Facebook uses OAuth 2.0 instead of OpenID for logins, so you must download the DotNetOpenAuth CTP in order to get the Facebook login sample. And the sample isn't for MVC, it's for web forms. But since it's all code in the code-behind anyway, you hopefully can make the translation yourself.

DotNetOpenAuth - Facebook - How can I authenticate users without forcing them to install a Facebook App?

This will work until Facebook forces everybody to use the "Enhanced Auth Dialog"

You can fix this dialog by going into your advanced application settings:

Sample Image

Changing this setting will cause the dialog to appear as you suggested in your excellent question.

Sample Image

Posting a tweet to a Twitter account using DotNetOpenAuth

Here's what you need to do:

  1. The RequestUserAuthorization method returns a URL to an authorization page.
  2. You should redirect the user to that page, typically Process.Start(url), where the user will authorize your application.
  3. Twitter the redirects the user to a page with a multi-digit number, which is the verifier.
  4. After you've sent the user to the authorization page, your application should wait with a dialog or prompt so that the user can enter the verifier and submit it to your application.
  5. Once you have the verifier, pass it as the 2nd argument to ProcessUserAuthorization.

Here's a blog post that say's something similar and has a code example:

http://whelkaholism.blogspot.com/2010/08/c-doing-stuff-with-google-using-oauth.html



Related Topics



Leave a reply



Submit