1

我正在使用 javascript sdk 登录并将 accesstoken 发布到服务器,如 facebook c# sdk 入门页面中所述。我有几个问题。

  1. 它使用 auth.authResponseChange 每次都会触发,这会导致重定向循环
  2. 如果我将其更改为 auth.login,它只会在用户通过我的网站登录时被调用。如果他们已经登录到 fb,它就不起作用。
  3. 如何仅将访问令牌发布一次回服务器并将其存储在会话中?
  4. 如果我在服务器上使用 oauth 身份验证,是否可以将访问令牌传递回 javascript sdk?

    FB.Event.subscribe('auth.authResponseChange', function(response) {
        if (response.status === 'connected') {
            // the user is logged in and has authenticated your
            // app, and response.authResponse supplies
            // the user's ID, a valid access token, a signed
            // request, and the time the access token 
            // and signed request each expire
            var uid = response.authResponse.userID;
            var accessToken = response.authResponse.accessToken;
    
            // TODO: Handle the access token
            // Do a post to the server to finish the logon
            // This is a form post since we don't want to use AJAX
            var form = document.createElement("form");
            form.setAttribute("method", 'post');
            form.setAttribute("action", '/FacebookLogin.ashx');
    
            var field = document.createElement("input");
            field.setAttribute("type", "hidden");
            field.setAttribute("name", 'accessToken');
            field.setAttribute("value", accessToken);
            form.appendChild(field);
    
            document.body.appendChild(form);
            form.submit();
    
        } else if (response.status === 'not_authorized') {
            // the user is logged in to Facebook, 
            // but has not authenticated your app
        } else {
           // the user isn't logged in to Facebook.
        }
    });
    
4

0 回答 0