Facebook Connect (C# SDK) - How to See if User is Authenticated to FB, But Don't Force?

强颜欢笑 提交于 2019-12-04 16:07:11

You can (ab)use the HTTP status codes to find that information about Facebook, the technique is described here

https://grepular.com/Abusing_HTTP_Status_Codes_to_Expose_Private_Information

After days of hunting around the net, including the Graph API, old REST API, FQL, etc - it seems the JavaScript SDK is the only one that allows this information without having a access token beforehand.

So, i had to use the JavaScript SDK:

<div id="fb-root"></div>
<script type="text/javascript">
    window.fbAsyncInit = function () {
        FB.init({ appId: 'xxxxxxx', status: true, cookie: false, xfbml: false
        });
        FB.getLoginStatus(function (response) {
            if (response.session)
                window.location = '/Facebook/LogOn'
        });
    };
    (function () {
        var e = document.createElement('script');
        e.async = true;
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
    } ());
</script>

Basically, i first load the JS API aysynchonrously to avoid blocking.

I then see if the user has a Facebook session. If they do, i redirect to my FacebookController, which does the OAuth redirect (which will come back straight away with the token - since they're already auth'ed), with then sets my own cookie.

My global action filter then kicks in, sees there is a cookie, and logs the user in. Nice.

Note how i have cookie: false - this is because i'm tracking my own cookies for the OAuth token and FB ID.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!