0

我正在尝试遵循有关 Django OAuth 工具包的教程:https ://django-oauth-toolkit.readthedocs.io/en/latest/tutorial/tutorial_03.html 。说明说要更新 deMIDDLEWARE如下:

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',
    '...',
)

但是,在我当前使用startprojectDjango 2.0.1 生成的项目中,我看到了SessionMiddlewareand AuthenticationMiddleware,但没有看到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注释掉的行之后?

4

1 回答 1

1

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

(见:https ://docs.djangoproject.com/en/2.0/releases/2.0/#miscellaneous )

即是的,它应该在 AuthenticationMiddleware 之后

于 2018-01-26T23:44:09.667 回答