Python - Facebook 连接无需基于浏览器的重定向
标题可能有点用词不当。
我在 Web 应用程序中设置了两个子域,一个用于 www.web 应用程序前端。 (它使用松散的 PHP 路由器以及骨干网、require 和 jquery 作为 UI)以及 data 处的数据层设置。 (利用 Werkzeug 完全用 Python 构建)
我们决定采用这种架构,因为在某些时候移动应用程序将集成到方程式中,并且它们可以轻松地将 HTTP 连接发送到数据子域。数据子域以 JSON 格式呈现其所有响应,JS 前端普遍期望将其作为响应,无论是有效的查询响应还是错误。
这感觉像是我在项目中做过的最有条理的安排,直到 Facebook connect 出现在宣言中。
理想情况下,我希望在数据子域上保留尽可能多的网站后台“操作”,尤其是身份验证内容,以便电话和移动设备也可以在需要时使用该逻辑。 。然而,查看 facebook 文档,浏览器及其会话对象似乎是其 OAuth 流程中的关键组件。
用户认证和应用授权同时处理 通过将用户重定向到我们的 OAuth 对话框。当调用这个 对话框中,您必须传入创建时生成的应用程序ID 您在我们的开发者应用程序中的应用程序(client_id 参数)以及 用户浏览器将重定向回应用程序的 URL 授权完成(redirect_uri参数)。这 redirect_uri 必须位于您在中指定的站点 URL 的路径中 开发者应用程序中“摘要”选项卡的网站部分。注意,你的 redirect_uri 不能是重定向器。
我之前在 PHP 中完成过此操作,并且熟悉该过程,当相关逻辑可以直接访问浏览器时,大约 3 个标头重定向是一件微不足道的事情。我的问题是,我们的新应用程序的结构方式,所有业务逻辑都被隔离在另一个子域上。我有哪些选项可以模拟重定向?我可以让 python 子域发送 HTTP 数据,并像所有其他请求一样使用 CURL 从 www 域接收数据吗? 我可以向用户的浏览器返回一个 json 对象来指示如何进行重定向吗? Facebook 是否会接受来自数据子域的请求,其redirect_uri位于子域www?我发现引用部分的最后一句话可能会低估这种可能性,但我浏览了他们的文档,但并没有明确表示这将被视为违规。
有没有人有过使用 Facebook 建立类似架构的经验?也许我应该将 FB 登录逻辑直接折叠并放入 PHP 中并在那里处理。
谢谢!
title might be a bit of a misnomer.
I have two subdomains setup in a web application, one for the application frontend at www. (which is using a loose PHP router coupled with backbone, require, and jquery for UI) and a data tier setup at data. (built entire in python utilizing Werkzeug)
We decided to go to this kind of architecture since at some point mobile app will be integrated into the equation, and they can just as easily send HTTP connections to the data subdomain. The data subdomain renders all its responses in JSON, which the JS frontend expects universally as a response be it a valid query response or an error.
This feels like the most organized arrangement I've ever had on a project, until Facebook connect appeared on the manifesto.
Ideally, I'd like to keep as much of the 'action' of the site behind the scenes on the data subdomain, especially authentication stuff, so that the logic is available to the phones and mobile devices as well down the line if need be. Looking into the facebook docs, it appears however that the browser and its session object are critical components in their OAuth flow.
User authentication and app authorization are handled at the same time
by redirecting the user to our OAuth Dialog. When invoking this
dialog, you must pass in your app id that is generated when you create
your application in our Developer App (the client_id parameter) and
the URL that the user's browser will be redirected back to once app
authorization is completed (the redirect_uri parameter). The
redirect_uri must be in the path of the Site URL you specify in
Website section of the Summary tab in the Developer App. Note, your
redirect_uri can not be a redirector.
I've done this before in PHP and am familiar with the process, and it's a trivial matter of about 3 header redirects when the logic in question has direct access to the browser. My problem is that the way our new app is structured, all the business logic is sequestered on the other subdomain. What are my options to simulate the redirect? can I have the python subdomain send the HTTP data, receiving it from the www domain using CURL like all the other requests? Can I return a json object to the user's browser that instructs on doing the redirects? Will Facebook even accept requests from a data subdomain, whose redirect_uri is at subdomain www? I find that last sentence in the quoted section probably discounts that as a possibility, but I've looked through their docs and it doesn't explicity say that this would be treated as a violation.
Has anyone had any experience setting up something like this with Facebook with a similar architecture? Perhaps I should just fold and put the FB login logic directly into PHP and handle it there.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论