1

私はjavascript sdkを使用してログインし、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