Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require MFA verification on a view #70

Open
MarkusH opened this issue Jun 1, 2023 · 0 comments
Open

Require MFA verification on a view #70

MarkusH opened this issue Jun 1, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@MarkusH
Copy link
Collaborator

MarkusH commented Jun 1, 2023

This is a feature request that stems from #60.

Feature request

As a developer, I'd like to ensure a specific view is only accessible when the user went through a successful multi-factor verification. Since I'm using function based views and class based views, I'd like to have a decorator and a mixin that I can use in accordance to similar features within Django (e.g. @login_required and LoginRequired).

This ticket likely requires #68 before it can be implemented.

Implementation idea

from functools import wraps

def mfa_required(view):
    @wraps(view)
    def inner(request, *args, **kwargs):
        if not request.session.get("kagi_verified", False):  # See #68
            return redirect("kagi:verify-second-factor")
        return view(request, *args, **kwargs)

    return inner
class MFARequiredMixin:
    def dispatch(self, request, *args, **kwargs):
        if not request.session.get("kagi_verified", False):  # See #68
            return redirect("kagi:verify-second-factor")
        return super().dispatch(request, *args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant