authentik.sources.telegram.stage

 1from django.utils.translation import gettext_lazy as _
 2from rest_framework.fields import BooleanField, CharField
 3
 4from authentik.flows.challenge import Challenge, ChallengeResponse
 5from authentik.sources.telegram.telegram import TelegramAuth
 6from authentik.stages.identification.stage import LoginChallengeMixin
 7
 8
 9class TelegramLoginChallenge(LoginChallengeMixin, Challenge):
10    component = CharField(default="ak-source-telegram")
11    bot_username = CharField(help_text=_("Telegram bot username"))
12    request_message_access = BooleanField()
13
14
15class TelegramChallengeResponse(TelegramAuth, ChallengeResponse):
16    component = CharField(default="ak-source-telegram")
17
18    def get_bot_token(self) -> str:
19        return self.stage.source.bot_token
20
21    def validate(self, attrs: dict) -> dict:
22        attrs_to_check = attrs.copy()
23        component = attrs_to_check.pop("component")
24        validated = super().validate(attrs_to_check)
25        validated["component"] = component
26        return validated
10class TelegramLoginChallenge(LoginChallengeMixin, Challenge):
11    component = CharField(default="ak-source-telegram")
12    bot_username = CharField(help_text=_("Telegram bot username"))
13    request_message_access = BooleanField()

Base login challenge for Identification stage

component
bot_username
request_message_access
16class TelegramChallengeResponse(TelegramAuth, ChallengeResponse):
17    component = CharField(default="ak-source-telegram")
18
19    def get_bot_token(self) -> str:
20        return self.stage.source.bot_token
21
22    def validate(self, attrs: dict) -> dict:
23        attrs_to_check = attrs.copy()
24        component = attrs_to_check.pop("component")
25        validated = super().validate(attrs_to_check)
26        validated["component"] = component
27        return validated

Base class for all challenge responses

component
def get_bot_token(self) -> str:
19    def get_bot_token(self) -> str:
20        return self.stage.source.bot_token
def validate(self, attrs: dict) -> dict:
22    def validate(self, attrs: dict) -> dict:
23        attrs_to_check = attrs.copy()
24        component = attrs_to_check.pop("component")
25        validated = super().validate(attrs_to_check)
26        validated["component"] = component
27        return validated