画布应用程序中的 Facebook Graph API 身份验证和跟踪会话

发布于 2024-09-02 16:16:52 字数 683 浏览 2 评论 0原文

简短的问题是: 我如何使用graph api oauth重定向机制来验证用户并保存检索到的access_token,并在需要时使用javascript SDK(问题是javascript SDK在初始化时将具有不同的access_token)。

我最初设置了我的 facebook iframe canvas 应用程序,具有单点登录功能。这与图 api 配合得很好,因为我可以在检测到 sessionchange(用户登录)时使用 facebook 的 javascript 保存的 access_token。

但是,我不想进行单点登录。但是,使用图形 api 重定向并强制用户发送到权限对话框。但是,如果他已经授予权限,我不应该重定向用户。这要怎么处理呢?

另一个问题: 我已经完成了图形 API 重定向以进行身份​​验证,并且还检索了 access_token。但是,如果我想使用 javascript 调用 FB.ui 来执行 Stream.Publish 该怎么办?我认为它将使用自己的 access_token,该 token 在 FB.init 和检测会话期间设置。所以,我在这里寻找一些路径。如何使用 graph api 进行身份验证,并在需要时使用 facebook 的 javascript SDK。

PS我正在使用 ASP .NET MVC 2。我开发了一个身份验证过滤器,它需要检测用户的身份验证状态并重定向。(目前它是为了图形 api 授权 url 执行此操作)

Short question is:
how can i use graph api oauth redirects mechanism to authenticate user and save retrieved access_token and also use javascript SDK when needed (the problem is javascript SDK will have different access_token when initialized).

I have initially setup my facebook iframe canvas app, with single sign on. This works well with graph api, as I am able to use access_token saved by facebook's javascript when it detects sessionchange(user logged in).

But, I want to rather not do single sign-on. But, use graph api redirect and force user to send to a permissions dialog. But, if he has already given permissions, I shouldn't redirect user. How to handle this?

Another question:
I have done graph api redirects for authentication and have retrieved access_token also. But then, what if I want to use javascript call FB.ui to do stream.Publish? I think it will use it's own access_token which is set during FB.init and detecting session. So, I am looking for some path here. How to use graph api for authentication and also use facebook's javascript SDK when needed.

P.S. I'm using ASP .NET MVC 2. I have an authentication filter developed, which needs to detect the user's authentication state and redirect.(currently it does this to graph api authorize url)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北方。的韩爷 2024-09-09 16:16:52

我一直在为 Graph API 开发一个名为 FBGraph.NET 的 .NET 客户端。我还没有足够的时间将其置于发布状态,但您仍然应该能够直接使用现有代码或作为您想要执行的操作的参考。

具体来说,FBFraphAuthorizeAttributeFBGraphAuthenticationHelperFBGraphAuthorizationHelper< /a>.

身份验证/授权系统设置为与 ASP.NET Forms 身份验证分开,因此您可以单独使用它们,也可以使用 FBGraph Facebook 授权作为 Forms 身份验证的直接替代。如果用户尚未授予权限,它将自动重定向用户并提示授权/扩展权限。

我还没有任何东西可以帮助服务器端代码和 JS SDK 之间的工作,但我认为访问令牌应该是可以互换的。如果您最终按原样使用客户端,则应该能够在 IFacebookContext 上设置任何令牌,反之亦然地将服务器端生成的访问令牌传递给客户端。

I've been working on a .NET client for the Graph API called FBGraph.NET. I haven't had enough time to get it to a release state yet, but you should still be able to use the existing code either directly or as a reference for what you're trying to do.

Specifically, FBFraphAuthorizeAttribute, FBGraphAuthenticationHelper and FBGraphAuthorizationHelper.

The authentication/authorization system is set up to be separate from ASP.NET Forms Authentication, so you can you them separately, or you can use the FBGraph Facebook authorization as a direct replacement for Forms auth. It will automatically redirect the user and prompt for authorization/extended permissions if they haven't already granted them.

I don't have anything in there yet that helps work between server-side code and the JS SDK, but I imagine that the access tokens should be interchangeable. If you end up using the client as is, you should be able to set any token on IFacebookContext, and conversely pass an access token generated server side to the client.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文