问题描述
我正在尝试为我的 Django 项目设置双因素身份验证。下面是配置详情
settings.py
'django_otp','django_otp.plugins.otp_static','django_otp.plugins.otp_totp','two_factor',...
]
MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware','django_otp.middleware.OTPMiddleware',...
]
LOGIN_URL = 'two_factor:login'
LOGIN_REDIRECT_URL = 'two_factor:profile'
TWO_FACTOR_PATCH_ADMIN = True
TWO_FACTOR_CALL_GATEWAY = 'two_factor.gateways.fake.fake'
TWO_FACTOR_SMS_GATEWAY = 'two_factor.gateways.fake.Fake'
AUTH_USER_MODEL ='Products.CustomUser'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',)
LOGGING = {
'version': 1,'disable_existing_loggers': False,'handlers': {
'console': {
'level': 'DEBUG','class': 'logging.StreamHandler',},'loggers': {
'two_factor': {
'handlers': ['console'],'level': 'INFO',}
}
}
urls.py
urlpatterns = [
path('',include(tf_urls)),# path('admin/',admin.site.urls),]
当我访问 url http://127.0.0.1:8001/account/login/ 时,它导航到令牌生成页面。
当我用谷歌身份验证器扫描二维码然后当我进入令牌系统时抛出错误
**不是有效的令牌**。
该应用程序已经使用自定义用户模型通过 django 默认身份验证运行。现在我正在尝试合并两因素身份验证。
有人可以指导我了解上述配置中缺少什么吗?。
解决方法
确保服务器和手机上的时间设置正确。即使关闭几秒钟也可能导致验证失败。