过去几天我一直在研究 Django 2 因素。我终于达到了让 Django Twilio 电话验证正常工作的地步。这是工作代码的代码...
from authy.api import AuthyApiClient
from django.conf import settings
from django.shortcuts import render, redirect
from .forms import VerifyForm, TokenForm
authy_api = AuthyApiClient(settings.ACCOUNT_SECURITY_API_KEY)
def SetupView(request):
if request.method == 'POST':
form = VerifyForm(request.POST)
if form.is_valid():
request.session['phone_number'] = form.cleaned_data['phone_number']
request.session['country_code'] = form.cleaned_data['country_code']
authy_api.phones.verification_start(
form.cleaned_data['phone_number'],
form.cleaned_data['country_code'],
via=form.cleaned_data['via']
)
return redirect('token_validation')
else:
form = VerifyForm()
return render(request, 'registration/verify.html', {'form': form})
def token_validation(request):
if request.method == 'POST':
form = TokenForm(request.POST)
if form.is_valid():
verification = authy_api.phones.verification_check(
request.session['phone_number'],
request.session['country_code'],
form.cleaned_data['token']
)
if verification.ok():
request.session['is_verified'] = True
return redirect('verified')
else:
for error_msg in verification.errors().values():
form.add_error(None, error_msg)
else:
form = TokenForm()
return render(request, 'registration/token_validation.html', {'form': form})
def verified(request):
if not request.session.get('is_verified'):
return redirect('phone_verification')
return render(request, 'registration/verified.html')
使用上面的代码并在我的 settings.py 文件中指定 ACCOUNT_SECURITY_API_KEY 是获取上面的代码以将 4 位代码传递到我的手机所需的全部内容。进步...
但是,我真正想要完成的是利用 AUTHY 应用程序提供登录代码......我查看了以下页面...... https://www.twilio.com/docs/authy/ quickstart/two-factor-authentication-python-django#linkcode而且代码没有加载到这个页面上......有没有人有经验或知道去哪里看,这样我就可以让 Django 与 Authy 一起工作并获得改变的代码每 20 秒一次,而不是上面显示的 4 位密码示例?提前感谢您的任何想法。