SessionAuthenticationMiddleware

SessionAuthenticationMiddleware

本文介绍了在Django 2中将Django OAuth Toolkit中间件放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循有关Django OAuth Toolkit的教程: https://django-oauth-toolkit.readthedocs.io/en/latest/tutorial/tutorial_03.html .指令说明如下更新de MIDDLEWARE:

I'm trying to follow a tutorial on the Django OAuth Toolkit: https://django-oauth-toolkit.readthedocs.io/en/latest/tutorial/tutorial_03.html. The instructions say to update de MIDDLEWARE as follows:

MIDDLEWARE = (
    '...',
    # If you use SessionAuthenticationMiddleware, be sure it appears before OAuth2TokenMiddleware.
    # SessionAuthenticationMiddleware is NOT required for using django-oauth-toolkit.
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'oauth2_provider.middleware.OAuth2TokenMiddleware',
    '...',
)

但是,在当前使用Django 2.0.1中使用startproject生成的项目中,我同时看到了SessionMiddlewareAuthenticationMiddleware,但没有看到SessionAuthenticationMiddleware:

In my current project generated using startproject in Django 2.0.1, however, I see both SessionMiddleware and AuthenticationMiddleware, but no SessionAuthenticationMiddleware:

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    # 'oauth2_provider.middleware.OAuth2TokenMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

我应该将OAuth2TokenMiddleware放在哪里?在AuthenticationMiddleware之后,如注释行中一样?

Where should I put the OAuth2TokenMiddleware? After AuthenticationMiddleware as in the commented-out line?

推荐答案

SessionAuthenticationMiddleware类已被删除-在1.10中无条件启用了会话身份验证.

The SessionAuthenticationMiddleware class has been removed - session authentication was unconditionally enabled in 1.10.

(请参阅: https://docs.djangoproject.com/en/2.0/releases/2.0/#miscellaneous )

即是的,应该在AuthenticationMiddleware之后

i.e. yes, it should come after AuthenticationMiddleware

这篇关于在Django 2中将Django OAuth Toolkit中间件放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 12:58