authentik.stages.dummy.stage
authentik multi-stage authentication engine
1"""authentik multi-stage authentication engine""" 2 3from django.http.response import HttpResponse 4from rest_framework.fields import CharField 5 6from authentik.flows.challenge import Challenge, ChallengeResponse 7from authentik.flows.stage import ChallengeStageView 8from authentik.lib.sentry import SentryIgnoredException 9 10 11class DummyChallenge(Challenge): 12 """Dummy challenge""" 13 14 component = CharField(default="ak-stage-dummy") 15 name = CharField() 16 17 18class DummyChallengeResponse(ChallengeResponse): 19 """Dummy challenge response""" 20 21 component = CharField(default="ak-stage-dummy") 22 23 24class DummyStageView(ChallengeStageView): 25 """Dummy stage for testing with multiple stages""" 26 27 response_class = DummyChallengeResponse 28 29 def challenge_valid(self, response: ChallengeResponse) -> HttpResponse: 30 return self.executor.stage_ok() 31 32 def get_challenge(self, *args, **kwargs) -> Challenge: 33 if self.executor.current_stage.throw_error: 34 raise SentryIgnoredException("Test error") 35 return DummyChallenge( 36 data={ 37 "title": self.executor.current_stage.name, 38 "name": self.executor.current_stage.name, 39 } 40 )
12class DummyChallenge(Challenge): 13 """Dummy challenge""" 14 15 component = CharField(default="ak-stage-dummy") 16 name = CharField()
Dummy challenge
19class DummyChallengeResponse(ChallengeResponse): 20 """Dummy challenge response""" 21 22 component = CharField(default="ak-stage-dummy")
Dummy challenge response
25class DummyStageView(ChallengeStageView): 26 """Dummy stage for testing with multiple stages""" 27 28 response_class = DummyChallengeResponse 29 30 def challenge_valid(self, response: ChallengeResponse) -> HttpResponse: 31 return self.executor.stage_ok() 32 33 def get_challenge(self, *args, **kwargs) -> Challenge: 34 if self.executor.current_stage.throw_error: 35 raise SentryIgnoredException("Test error") 36 return DummyChallenge( 37 data={ 38 "title": self.executor.current_stage.name, 39 "name": self.executor.current_stage.name, 40 } 41 )
Dummy stage for testing with multiple stages
response_class =
<class 'DummyChallengeResponse'>
def
challenge_valid( self, response: authentik.flows.challenge.ChallengeResponse) -> django.http.response.HttpResponse:
30 def challenge_valid(self, response: ChallengeResponse) -> HttpResponse: 31 return self.executor.stage_ok()
Callback when the challenge has the correct format
33 def get_challenge(self, *args, **kwargs) -> Challenge: 34 if self.executor.current_stage.throw_error: 35 raise SentryIgnoredException("Test error") 36 return DummyChallenge( 37 data={ 38 "title": self.executor.current_stage.name, 39 "name": self.executor.current_stage.name, 40 } 41 )
Return the challenge that the client should solve