Facebook连接(C#SDK) - 如何查看是否用户进行身份验证到FB,但不要强迫? [英] Facebook Connect (C# SDK) - How to See if User is Authenticated to FB, But Don't Force?

查看:142
本文介绍了Facebook连接(C#SDK) - 如何查看是否用户进行身份验证到FB,但不要强迫?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实施的Facebook Connect和我的ASP.NET MVC 3网站之间的单点登录,使用Facebook C#SDK。

I'm implementing a single sign on between Facebook Connect and my ASP.NET MVC 3 website, using the Facebook C# SDK.

现在,在单点登录的部分是:

Now, part of the single sign on is:

如果用户通过身份验证给Facebook,而不是我的网站,看看他们是否连接在我的系统,如果是这样,在执行一个单点登录(使用窗体身份验证)。

If the user is authenticated to Facebook, but not to my website, see if they are connected in my system and if so, perform a single sign on (using Forms Auth).

现在,我不知道如何看到,如果用户进行身份验证。我使用服务器端身份验证的OAuth,所以我不想强迫他们通过登录页面,只是一个无声的检查,以登录。如果他们没有经过认证,我不会做任何事情 - 我将只恨不得点击按钮连接Facebook

Now, i don't know how to "see if the user is authenticated". I'm using OAuth for server-side authentication, so i don't want to force them to sign in via the login page, just a silent check. If they're not authenticated, i wont do anything - i'll just wait for them to click the "Connect with Facebook" button.

我们可以使用JavaScript API做到这一点 - 我们可以做到这一点的服务器端

We can do this with the JavaScript API - can we do it server-side?

我基本上要相当于 FB.getLoginStatus 通过图形API。

I basically want the equivalent of FB.getLoginStatus via the Graph API.

当然必须有办法服务器端的 - 至少,如果不是通过图形API,老REST API或FQL?

Surely there must be a way server-side - at least if not via the Graph API, the old REST api or FQL?

推荐答案

在四处撒网,包括图形API,老REST API,FQL等狩猎的日子 - 似乎的JavaScript SDK是唯一一个允许这种而无需访问令牌事先的信息。

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.

所以,我不得不使用JavaScript SDK:

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>

基本上,我首先加载JS API aysynchonrously避免阻塞。

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

然后我看到,如果用户拥有一个Facebook会话。如果他们这样做,我重定向到我的 FacebookController ,它执行OAuth的重定向(它会回来马上与令牌 - 因为他们已经auth'ed),与然后将我自己的cookie。

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.

我的全球行动,过滤器,然后踢,看到有一个cookie,并记录用户很高兴。

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

请注意,我怎么有饼干:假 - 这是因为我跟踪我自己的cookies为OAuth令牌和FB ID

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

这篇关于Facebook连接(C#SDK) - 如何查看是否用户进行身份验证到FB,但不要强迫?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆