开发者

Facebook Tab Authentication

Is it possible to authenticate a user from a tab app?

I am trying to create an ASP.NET MVC 3 facebook tab app that needs to be able to post to wall.

My first guess was using the CanvasAuthorizeAttribute

[CanvasAuthorize(Permissions="publish_stream")]

but it makes my tab redirect to the the login facebook authorization page and then back to the canvas page and not staying in the fanpage (tab).

Then I remove the CanvasAuthorize and tried the following

public string Index()
{
    bool isAuthorized = FacebookWebContext.Current.IsAuthorized("publish_stream");

    return isAuthorized.ToString();
}

from that I could decide to launch the authorize popup if the user is not authorized, but I am facing a problem here.

  • Previously authorizing the app with stream_publish permission by other means and then, running the page as an app ( http://apps.facebook.com/myapp/my开发者_运维百科tab ) returns true while running the page from a fanpage tab ( http://www.facebook.com/myfanpage?sk=app_myappid ) returns false !

Why can't the tab read the permission but the canvas page can?


From you Facebook Page, you can detect whether the user has authorized your app or not by examining the signed_request. If user_id and oauth_token are passed, then the user has already authorized your app. If not, you can do something like this from your Controller Action:

    string[] extendedPermissions = new[] { "publish_stream", "manage_pages" };
    var oauth = new FacebookOAuthClient(FacebookWebContext.Current.Settings);
    var parameters = new Dictionary<string, object> {
                { "redirect_uri", "http://www.facebook.com/pages/{SomeFacebookPage}?sk=app_{appId}"}
            };

    parameters["scope"] = String.Join(",", extendedPermissions);
    var loginUrl = oauth.GetLoginUrl(parameters);

    return Redirect(loginUrl.AbsoluteUri);

After your user authenticates your app, the user will be sent to the "redirect_uri", which can be your app tab on a Facebook Page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜