Alex Rivera | Logout

DotNetOpenAuth CTP - Facebook bad request

Asked 2010-09-16T08:59:31.517
10

I am trying to use the CTP to connect with Facebook over OAuth 2.0.

I can get the initial request to Facebook working OK, but when it comes back and we call:

// Where null will become an HttpRequestInfo object
client.ProcessUserAuthorization(null);

I get:

The remote server returned an error: (400) Bad Request.

I haven't really done much with the initial codebase; merely set the optional values to null (we're still on .NET 3.5). Any clues would be much appreciated.

Also, and i guess this is more of a question to Andrew specifically; is there a forum / blog for any of this stuff, or anywhere that will give regular updates? It would be great to know a few things:

  1. Planned release date of the DotNetOpenAuth with OAuth 2.0
  2. Whether .NET 4.0 will be a pre-requisite

Anyway, any suggestions would be most welcome.

Edit
Report

2 Answers

22

After hitting this issue, I wrote my own code to authorize, and get the users details. Another approach would be to use Facebook C# SDK. As a starter for anyone else thinking about doing there own, here is how I did it. Please note I have not looked into error cases.

Firstly, read facebooks doc on how it works (its rather simple!)

I consume it like this:

private static readonly FacebookClient facebookClient = new FacebookClient();
public ActionResult LoginWithFacebook()
{
    var result = facebookClient.Authorize();
    if (result == FacebookAuthorisationResult.RequestingCode)
    {
        //The client will have already done a Response.Redirect
        return View();
    } else if (result == FacebookAuthorisationResult.Authorized)
    {
        var user = facebookClient.GetCurrentUser();
    }
    return Redirect("/");
}

And the client code:

using System;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Web;

namespace Web.Services
{
    public enum FacebookAuthorisationResult
    {
        Denied,
        Authorized,
        RequestingCode
    }
    public class FacebookClient
    {
        private const String SESSION_NAME_TOKEN = "UserFacebookToken";
        public FacebookClient()
        {
            TokenEndpoint = new Uri("https://graph.facebook.com/oauth/access_token");
            AuthorizationEndpoint = new Uri("https://graph.facebook.com/oauth/authorize");
            MeGraphEndpoint = new Uri("https://graph.facebook.com/me");
            ClientIdentifier = "xxxxxxxxxxxxxxxxxx";
            Secret = "xxxxxxxxxxxx";
            LocalSubDomain = "local.xxxxxxx.com";
        }

        public Uri TokenEndpoint { get; set; }
        public Uri Authoriz
answered 2010-11-29T01:28:04.860
1

Iain's solution is finally something I made this thing work with.

There is one note for future implementers - seems like Facebook ID property is now exceeding capacity of Int32 type. You might need to change this in FacebookGraph class, I used plain string.

Thanks Iain, your code really helped me!

answered 2011-03-08T16:40:02.173

Your Answer