70

I've pretty much got OpenID working using the DotNetOpenAuth library. Now I would like users to be able to use Facebook and Twitter to login.

This requires OAuth so I am looking for a tutorial on how to use DotNetOpenAuth OAuth.

I'm having trouble trying to find some simple tutorials on how to do this.

Can anyone please help?

Pure.Krome
  • 78,923
  • 102
  • 356
  • 586
chobo2
  • 75,304
  • 170
  • 472
  • 780
  • 2
    DotNetOpenAuth includes a sample in the OAuthConsumer project of logging in with Twitter. The DotNetOpenAuth OAuth 2.0 CTP includes a Facebook login sample in the OAuthConsumer project as well. – Andrew Arnott Jan 27 '11 at 22:52
  • @Andrew Arnott - Hmm I had a problem with loading up the samples(I had a question on stack but for some reason I accepted an answer that I never tried out). You commented on that post so maybe you can elaborate on it. http://stackoverflow.com/questions/4671367/where-are-tutorials-for-dotnetopenauth-and-how-to-solve-compile-error-in-its-samp – chobo2 Jan 27 '11 at 23:22
  • I also find that written tutorials are helpful too as when I look into the samples I feel a bit over whelmed and not even sure where to start. I like to see a nice simple example before going straight into full blown scenario. – chobo2 Jan 27 '11 at 23:23
  • I found a tutorial for twitter http://blog.techcle.com/2010/03/20/simple-oauth-integration-for-twitter-in-asp-net-mvc/ that I think might be good. However I noticed there is a .dll called DotNetOpenAuth.ApplicationBlock what does not seem to come nuget. I am wondering if you know why. I still would like to try to get the sample ones to work. – chobo2 Jan 28 '11 at 02:36
  • Hmm the tutorial might be out of date. I can't get InMemoryTokenManager to work. It says I can't use it because it is an internal class. – chobo2 Jan 28 '11 at 03:09
  • @Andrew Arnott - I got the sample to work. I am wondering is there an example in the solution to make the openid ajax through mvc? – chobo2 Jan 28 '11 at 17:17
  • I ok I am getting the twitter example to work but I am just wondering can I control the url through code instead of through the application settings at twitters homepage? – chobo2 Jan 28 '11 at 19:44
  • Well the return url that I setup for twitter(on their page) does not seem to work. Does dotnetopenauth override it? – chobo2 Jan 28 '11 at 20:31
  • @Andrew Arnott - I can't find also DotNetOpenAuth OAuth 2.0 CTP seems like all the download links I find are dead. – chobo2 Jan 28 '11 at 23:45
  • I used [http://www.voiceoftech.com/swhitley/index.php/2009/03/twitter-oauth-with-net/](http://www.voiceoftech.com/swhitley/index.php/2009/03/twitter-oauth-with-net/) as a reference for twitter's OAuth. It took some custom work and I ended up wrapped a custom membership provider around it, but it worked pretty easily once I wrapped my head around everything. I haven't used facebook connect, yet so I can't offer much help there. – TheRightChoyce Jan 27 '11 at 22:11

1 Answers1

62

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. enter image description here

  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:

enter image description here

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.
David Pfeffer
  • 36,331
  • 28
  • 120
  • 198
Pure.Krome
  • 78,923
  • 102
  • 356
  • 586
  • I had to change int in FacebookGraph.cs to long and to fetch user email I added an Email property as well. Not sure if this is the only way to get it working though..but thanks for your help :) – Jags Jun 09 '11 at 15:59
  • 3
    +1. Note to others: The DotNetOpenAuth sample `OAuthClient` with Facebook settings is not available in versions 3.4.5.10202 or 3.4.7.11121, but it is available in version 3.5.0.10357 and 4.0.0.11165. You have to use at least the version shown by @Pure.Krome here. – Drew Noakes Jul 20 '11 at 15:31
  • 2
    Does anyone know why the FB login is only available in the 3.5 versions? and not in the new ones? – mateuscb Sep 01 '11 at 00:07
  • 2
    Facebook are on a different draft of OAuth 2.0. The version that dotnetopenauth uses is a later version. It sucks. – Pete - MSFT Oct 08 '11 at 01:09
  • For up to date code you can refer to their [github repo](https://github.com/DotNetOpenAuth/DotNetOpenAuth.Samples/tree/master/src/OAuth/OAuthClient) – Ferran Salguero Feb 03 '14 at 15:06