如何在本地主机上测试谷歌联合登录

发布于 2024-10-06 23:28:52 字数 408 浏览 0 评论 0原文

我正在尝试在本地计算机上测试联合登录应用程序。我将 django 与 Socialauth 应用程序一起使用。然而,当登录 localhost 时,我收到 403 Forbidden django 错误页面,通知我“CSRF 令牌丢失或不正确”。我假设这意味着我正在访问的网站未经授权。

在 google 域名管理页面 上,您可以添加 localhost,但没有任何反应当您尝试管理该页面时。

那么,有没有办法在本地计算机上测试联合登录呢?

I'm trying to test a federated login application on my local machine. I'm using django together with the Socialauth application. When logging in on localhost, however, I get a 403 Forbidden django error page, informing me that the "CSRF token [is] missing or incorrect." I'm assuming that means the site I'm accessing from is not authorized.

On the google domain management page you can add localhost, but nothing happens when you then try to manage that page.

So, is there a way to test federated login on your local machine?

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

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

发布评论

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

评论(2

手心的温暖 2024-10-13 23:28:52

错误

“CSRF 令牌缺失或
不正确。”

意味着 django 期望的 CSRF 令牌丢失或不正确。据我所知,CSRF 令牌功能是不久前添加的,也许您需要更新 Django 安装。

The error

"CSRF token [is] missing or
incorrect."

means just that, the CSRF token which django is expecting is missing or incorrect. AFAIK the CSRF token functionality was added not so long ago, maybe you need to update your Django install.

久隐师 2024-10-13 23:28:52

我的错误似乎只是没有添加 CsrfResponseMiddleware。

所以我的 settings.py 中的中间件类现在看起来像:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'openid_consumer.middleware.OpenIDMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.middleware.csrf.CsrfResponseMiddleware',
    #'socialauth.middleware.FacebookConnectMiddleware',
)

这消除了错误,一切正常。

My mistake seems simply to have been not to have added the CsrfResponseMiddleware.

So my middleware classes in settings.py now looks like:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'openid_consumer.middleware.OpenIDMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.middleware.csrf.CsrfResponseMiddleware',
    #'socialauth.middleware.FacebookConnectMiddleware',
)

This takes away the error, and everything works fine.

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