prabirshrestha / FacebookSharp

Facebook Graph API for .Net
Other
30 stars 15 forks source link

AccessToken is blank (Web Canvas App) #2

Closed jacobh0 closed 14 years ago

jacobh0 commented 14 years ago

I get redirected back to the postAuthorizeUrl with a code just fine, but I receive no ErrorReasonText when executing the FacebookAuthenticationResult call, and the AccessToken is empty and ExpiresIn is 0. Is the response from Facebook being parsed correctly?

prabirshrestha commented 14 years ago

right now it doesnt supoprt canvas application at the moment, as Canvas applications works differently. (only desktop/ your custom web application work). supporting the canvas applications is on top priority.

more of this information can be found here http://developers.facebook.com/docs/authentication/canvas

will work on it next and inform you when im done.

jacobh0 commented 14 years ago

Thank you, loving the the library so far, have read just about all the code, keep up the good work.

jacobh0 commented 14 years ago

I am using an iframe canvas application just fyi.

prabirshrestha commented 14 years ago

was just about to ask you which one, will have a look at iframe canvas application first.

prabirshrestha commented 14 years ago

i have now fixed it, can u download the latest source (from canvas branch).

Note: you need to enable Canvas Session Parameter and OAuth 2.0 for Canvas (beta) in Migration Tab in you application settings to make it work.

here a sample. you can find it in the source code also named - FacebookSharp.Samples.CanvasIFrameApplication

    public ActionResult Index()
    {
        var far = FacebookAuthenticationResult.Parse(
            Request.Url.ToString(), new FacebookSettings { ApplicationSecret = "appsecret" });

        if (!string.IsNullOrEmpty(far.AccessToken))
        {
            var facebook = new Facebook(far.AccessToken);
            ViewData["name"] = facebook.Get<User>("/me").Name;
        }

        return View();
    }

u can check if the user is logged in or not by checkin the accesstoken. if its null then user is not logged in.

incase the signed request is invalid the Parse method will throw new FacebookSharpException("signed_request validation failed");

im tryin to refactor the code more properly and will then finally merge it to dev branch then master branch once i have completed it. till then if there's any problems please feel free to comment.

prabirshrestha commented 14 years ago

i finished refactoring it and put it in the master branch.

FacebookSharpException("signed_request validation failed"); has been changed to InvalidSignedRequestException();

incase you want manual control, another public method has been added to FacebookAuthenticationResult

public static bool ValidateSignedRequest(string signedRequest, string applicationSecret, out IDictionary<string, object> jsonObject)

the 1st signedRequest parameter is the same as querystring u get from facebook called signed_request, this method doesn't throw exception rather returns false and set jsonObject to null.

you can find the deatils in readme.

jacobh0 commented 14 years ago

I am downloading the changes now, will let you know how it works out asap.