authentik.enterprise.requests.stage
1from django.http import HttpRequest, HttpResponse 2 3from authentik.enterprise.requests.grants import ( 4 GrantExpiry, 5 create_grant_request, 6) 7from authentik.flows.stage import StageView 8from authentik.lib.utils.time import timedelta_from_string 9from authentik.stages.prompt.stage import PLAN_CONTEXT_PROMPT 10 11PLAN_CONTEXT_GRANT_REQUESTED_PBMS = "goauthentik.io/requests/requested-pbms" 12PLAN_CONTEXT_GRANT_PENDING_EXPIRY = "goauthentik.io/requests/pending-expiry" 13PLAN_CONTEXT_GRANT_MAX_EXPIRY = "goauthentik.io/requests/max-expiry" 14PLAN_CONTEXT_GRANT_REQUESTED_EXPIRY = "goauthentik.io/requests/requested-expiry" 15 16 17class GrantRequestFinalStageView(StageView): 18 19 def get(self, request: HttpRequest) -> HttpResponse: 20 user = self.get_pending_user() 21 pbms = self.executor.plan.context.get(PLAN_CONTEXT_GRANT_REQUESTED_PBMS) 22 pending_expiry = self.executor.plan.context.get(PLAN_CONTEXT_GRANT_PENDING_EXPIRY) 23 max_expiry = self.executor.plan.context.get(PLAN_CONTEXT_GRANT_MAX_EXPIRY) 24 requested_expiry = self.executor.plan.context.get(PLAN_CONTEXT_GRANT_REQUESTED_EXPIRY) 25 # Enforce the configured maximum here, at persistence time, rather than 26 # earlier in create() -- a stage in the flow may have changed the requested 27 # duration since, so the ceiling can only be safely applied at the end. 28 granted_expiry_candidates = [timedelta_from_string(max_expiry)] 29 if requested_expiry: 30 granted_expiry_candidates.append(timedelta_from_string(requested_expiry)) 31 create_grant_request( 32 request, 33 created_by=user, 34 pbms=pbms, 35 requester_data=self.executor.plan.context.get(PLAN_CONTEXT_PROMPT, {}), 36 expiry=GrantExpiry( 37 pending=timedelta_from_string(pending_expiry), 38 granted=min(granted_expiry_candidates), 39 ), 40 ) 41 return self.executor.stage_ok() 42 43 def post(self, request: HttpRequest) -> HttpResponse: 44 """Wrapper for post requests""" 45 return self.get(request)
PLAN_CONTEXT_GRANT_REQUESTED_PBMS =
'goauthentik.io/requests/requested-pbms'
PLAN_CONTEXT_GRANT_PENDING_EXPIRY =
'goauthentik.io/requests/pending-expiry'
PLAN_CONTEXT_GRANT_MAX_EXPIRY =
'goauthentik.io/requests/max-expiry'
PLAN_CONTEXT_GRANT_REQUESTED_EXPIRY =
'goauthentik.io/requests/requested-expiry'
18class GrantRequestFinalStageView(StageView): 19 20 def get(self, request: HttpRequest) -> HttpResponse: 21 user = self.get_pending_user() 22 pbms = self.executor.plan.context.get(PLAN_CONTEXT_GRANT_REQUESTED_PBMS) 23 pending_expiry = self.executor.plan.context.get(PLAN_CONTEXT_GRANT_PENDING_EXPIRY) 24 max_expiry = self.executor.plan.context.get(PLAN_CONTEXT_GRANT_MAX_EXPIRY) 25 requested_expiry = self.executor.plan.context.get(PLAN_CONTEXT_GRANT_REQUESTED_EXPIRY) 26 # Enforce the configured maximum here, at persistence time, rather than 27 # earlier in create() -- a stage in the flow may have changed the requested 28 # duration since, so the ceiling can only be safely applied at the end. 29 granted_expiry_candidates = [timedelta_from_string(max_expiry)] 30 if requested_expiry: 31 granted_expiry_candidates.append(timedelta_from_string(requested_expiry)) 32 create_grant_request( 33 request, 34 created_by=user, 35 pbms=pbms, 36 requester_data=self.executor.plan.context.get(PLAN_CONTEXT_PROMPT, {}), 37 expiry=GrantExpiry( 38 pending=timedelta_from_string(pending_expiry), 39 granted=min(granted_expiry_candidates), 40 ), 41 ) 42 return self.executor.stage_ok() 43 44 def post(self, request: HttpRequest) -> HttpResponse: 45 """Wrapper for post requests""" 46 return self.get(request)
Abstract Stage
def
get( self, request: django.http.request.HttpRequest) -> django.http.response.HttpResponse:
20 def get(self, request: HttpRequest) -> HttpResponse: 21 user = self.get_pending_user() 22 pbms = self.executor.plan.context.get(PLAN_CONTEXT_GRANT_REQUESTED_PBMS) 23 pending_expiry = self.executor.plan.context.get(PLAN_CONTEXT_GRANT_PENDING_EXPIRY) 24 max_expiry = self.executor.plan.context.get(PLAN_CONTEXT_GRANT_MAX_EXPIRY) 25 requested_expiry = self.executor.plan.context.get(PLAN_CONTEXT_GRANT_REQUESTED_EXPIRY) 26 # Enforce the configured maximum here, at persistence time, rather than 27 # earlier in create() -- a stage in the flow may have changed the requested 28 # duration since, so the ceiling can only be safely applied at the end. 29 granted_expiry_candidates = [timedelta_from_string(max_expiry)] 30 if requested_expiry: 31 granted_expiry_candidates.append(timedelta_from_string(requested_expiry)) 32 create_grant_request( 33 request, 34 created_by=user, 35 pbms=pbms, 36 requester_data=self.executor.plan.context.get(PLAN_CONTEXT_PROMPT, {}), 37 expiry=GrantExpiry( 38 pending=timedelta_from_string(pending_expiry), 39 granted=min(granted_expiry_candidates), 40 ), 41 ) 42 return self.executor.stage_ok()
def
post( self, request: django.http.request.HttpRequest) -> django.http.response.HttpResponse:
44 def post(self, request: HttpRequest) -> HttpResponse: 45 """Wrapper for post requests""" 46 return self.get(request)
Wrapper for post requests