使用 Django 会话从不同域进行身份验证的问题

发布于 2024-08-25 18:58:13 字数 529 浏览 4 评论 0原文

我正在开发一个书签,它本质上是向用户当前正在查看的网页添加一个工具栏。要使用它,用户需要登录。

要登录,用户单击“Singin”,它会显示包含用户名、密码等字段的标准表单。当用户成功登录时,他们可能会选择导航到不同的网站。当在另一个页面上时,他们 (a) 重新加载小书签 (b) 从服务器检索他们的会话 (c) 用户不需要再次登录。我本来以为是相当标准的。

使用 Django 会话和 JQuery。

我在实现上述用例时遇到了麻烦。以下是我遇到的一些问题:

  1. 不允许跨域 POST AJAX 请求。这个问题已通过 JSONp 解决。我怀疑这是一种非常安全的方法,但目前它是有效的。
  2. 我的服务器在 cookie 中返回会话 ID,但是当用户导航到不同的页面时,我真的不知道如何检索该会话 ID 以发送回我的服务器。我什至可以从我的 JavaScript 中读取第三方 cookie 吗?

我正在寻找一些关于实现上述用例的指南。理想情况下,我不想将用户重定向到另一个页面供他们登录。任何建议将不胜感激。

谢谢。

I am developing a bookmarklet which essentially adds a toolbar to a web page user is currently looking at. To use it, user needs to be logged in.

To login user clicks on 'Singin' which displays a standard form containing Username, Password etc fields. When user successfully logs in they may chose to navigate to a different web-site. When on another page, they (a) re-load the bookmarklet (b) their session is retrieved from the server (c) user doesn't need to login again. Pretty standard I've would have thought.

Using Django sessions and JQuery.

I'm having troubles implementing the above usecase. Here are some problems I've encountered:

  1. Cross domain POST AJAX requests are disallowed. That was solved with JSONp. I doubt it is a very secure approach but for now it works.
  2. My server returns the session id in a cookie, however when the user navigates to a different page I don't really know how to retrieve that session id to send back to my server. Can I even read third party cookies from my JavaScript?

I'm looking for some guidelines on implementing the above usecase. Ideally I don't want to redirect user to another page for them to sign in. Any suggestion would be greatly appreciated.

Thanks.

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

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

发布评论

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

评论(1

满栀 2024-09-01 18:58:13

确实没有一个很好的方法来处理这个问题。您最好的选择可能是制作 Chrome 扩展(或 Firefox Addon)来实现类似的功能 - 这些扩展能够绕过浏览器的安全限制并授予您访问所有网页信息的权限。

抱歉这个坏消息:(

There's not really a great way to handle this. Your best bet might to be making a Chrome extension (or Firefox Addon) to achieve similar functionality -- these extensions are able to bypass the browser's security restrictions and grant you access to all of a web page's information.

Sorry for the bad news :(

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