authentik.flows.auth

 1from typing import cast
 2
 3from django.contrib.auth.models import AnonymousUser
 4from rest_framework.authentication import BaseAuthentication
 5from rest_framework.request import Request
 6
 7from authentik.flows.planner import PLAN_CONTEXT_PENDING_USER, FlowPlan
 8from authentik.flows.views.executor import SESSION_KEY_PLAN
 9
10
11class FlowActive(BaseAuthentication):
12    """Authenticate requests when a flow is currently active"""
13
14    def authenticate(self, request: Request):
15        plan = cast(FlowPlan | None, request.session.get(SESSION_KEY_PLAN))
16        if not plan:
17            return None
18        return (plan.context.get(PLAN_CONTEXT_PENDING_USER, AnonymousUser()), plan)
class FlowActive(rest_framework.authentication.BaseAuthentication):
12class FlowActive(BaseAuthentication):
13    """Authenticate requests when a flow is currently active"""
14
15    def authenticate(self, request: Request):
16        plan = cast(FlowPlan | None, request.session.get(SESSION_KEY_PLAN))
17        if not plan:
18            return None
19        return (plan.context.get(PLAN_CONTEXT_PENDING_USER, AnonymousUser()), plan)

Authenticate requests when a flow is currently active

def authenticate(self, request: rest_framework.request.Request):
15    def authenticate(self, request: Request):
16        plan = cast(FlowPlan | None, request.session.get(SESSION_KEY_PLAN))
17        if not plan:
18            return None
19        return (plan.context.get(PLAN_CONTEXT_PENDING_USER, AnonymousUser()), plan)

Authenticate the request and return a two-tuple of (user, token).