mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Compatibility with OIDC workflow
This commit is contained in:
@@ -191,6 +191,7 @@ class VerifySMSCodeForm(forms.Form):
|
||||
class Verify2FACodeForm(UserKwargModelFormMixin, forms.Form):
|
||||
"""A form to verify 2FA codes validity."""
|
||||
|
||||
next = forms.CharField(required=False)
|
||||
tfa_code = forms.CharField()
|
||||
|
||||
def clean_tfa_code(self):
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from functools import cached_property
|
||||
import logging
|
||||
import urllib.parse
|
||||
|
||||
import oath
|
||||
|
||||
@@ -125,7 +126,11 @@ class LoginView(LoginViewMixin, auth_views.LoginView):
|
||||
self.request.session[constants.TFA_PRE_VERIFY_USER_PK] = user.pk
|
||||
self.request.session[constants.TFA_PRE_VERIFY_USER_BACKEND] = user.backend
|
||||
self.request.session["rememberme"] = form.cleaned_data["rememberme"]
|
||||
return HttpResponseRedirect(reverse("core:2fa_verify"))
|
||||
nextlocation = self.request.POST.get("next", self.request.GET.get("next"))
|
||||
url = reverse("core:2fa_verify")
|
||||
if nextlocation:
|
||||
url += f"?next={urllib.parse.quote(nextlocation)}"
|
||||
return HttpResponseRedirect(url)
|
||||
return self.login(user, form.cleaned_data["rememberme"])
|
||||
|
||||
def form_invalid(self, form):
|
||||
@@ -275,6 +280,9 @@ class TwoFactorCodeVerifyView(LoginViewMixin, generic.FormView):
|
||||
user=self.user
|
||||
).exists()
|
||||
context["webauthn_device"] = has_webauthn_device
|
||||
context["nextlocation"] = self.request.POST.get(
|
||||
"next", self.request.GET.get("next")
|
||||
)
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<div id="totp_form" style="display:none;">
|
||||
<form method="post" action="{% url 'core:2fa_verify' %}">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" id="id_next" name="next" value="{{ nextlocation }}">
|
||||
<div class="input-group{% if form.tfa_code.errors %} has-error{% endif %}">
|
||||
<label>{% translate "One-time password" %}</label>
|
||||
<input id="id_tfa_code" name="tfa_code">
|
||||
@@ -84,7 +85,12 @@
|
||||
let options = parseRequestOptionsFromJSON(json)
|
||||
|
||||
let response = await get(options);
|
||||
let result = await fetch("{% url 'core:fido_auth_end' %}", {
|
||||
let params = new URLSearchParams(window.location.search)
|
||||
let url = "{% url 'core:fido_auth_end' %}"
|
||||
if (params.has('next')) {
|
||||
url += `?next=${encodeURIComponent(params.get('next'))}`
|
||||
}
|
||||
let result = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { "X-CSRFToken": csrf, 'Content-Type': 'application/json'},
|
||||
body: JSON.stringify(response),
|
||||
|
||||
Reference in New Issue
Block a user