Facebook C#SDKを使用して、ユーザーがFacebookを使用して自分のサイトにログインできるようにしています。
ログアウトするには、fb.logoutを使用できますが、これにより、ユーザーはFacebookと自分のサイトからログアウトされます。これは、ユーザーにとって非常に煩わしく、不要なようです。
digg.comは私が求めている機能を正確に提供しているので、彼らが私のサイトからログアウトするときにFacebookからログアウトする必要はないと確信しています。ユーザーをログアウトせずにFacebookでログインおよびログアウトします。彼らのFacebookアカウント。
ログイン/ログアウトに使用しているコードは次のとおりです。
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function () {
FB.init({
appId: 'XXXXXXXXXXXX', // App ID
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
// Handle successful log in.
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;
// 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", '/login.aspx');
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
alert("Logged in to facebook but not authenticated MT");
} else {
// the user isn't logged in to Facebook.
}
});
};
// Load the SDK Asynchronously
(function (d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
} (document));
</script>
<div class="fb-login-button" autologoutlink="true"></div>
ユーザーがログインすると、/ login.aspxにリダイレクトされます。これにより、サイトのログイン機能(.net認証を使用)が提供され、ユーザーのセッション中に使用できるようにアクセストークンがセッションに保存されます。
同じことを行うにはログアウトボタンが必要ですが、逆に、ユーザーをFacebookから完全にログアウトする必要はありません。
オンラインで何時間も探しましたが、Facebookアカウントからユーザーをログアウトせずにfb.logoutを呼び出す方法を見つけることができないようです。digg.comがそれを行うことができれば、私もできるはずですよね?
どうもありがとう、
ポール