Esempio n. 1
0
    def get_challenge(self) -> Challenge:
        current_stage: IdentificationStage = self.executor.current_stage
        challenge = IdentificationChallenge(
            data={
                "type": ChallengeTypes.NATIVE.value,
                "primary_action": _("Log in"),
                "component": "ak-stage-identification",
                "user_fields": current_stage.user_fields,
                "password_fields": bool(current_stage.password_stage),
                "show_source_labels": current_stage.show_source_labels,
            })
        # If the user has been redirected to us whilst trying to access an
        # application, SESSION_KEY_APPLICATION_PRE is set in the session
        if SESSION_KEY_APPLICATION_PRE in self.request.session:
            challenge.initial_data[
                "application_pre"] = self.request.session.get(
                    SESSION_KEY_APPLICATION_PRE, Application()).name
        # Check for related enrollment and recovery flow, add URL to view
        if current_stage.enrollment_flow:
            challenge.initial_data["enroll_url"] = reverse(
                "authentik_core:if-flow",
                kwargs={"flow_slug": current_stage.enrollment_flow.slug},
            )
        if current_stage.recovery_flow:
            challenge.initial_data["recovery_url"] = reverse(
                "authentik_core:if-flow",
                kwargs={"flow_slug": current_stage.recovery_flow.slug},
            )
        if current_stage.passwordless_flow:
            challenge.initial_data["passwordless_url"] = reverse(
                "authentik_core:if-flow",
                kwargs={"flow_slug": current_stage.passwordless_flow.slug},
            )

        # Check all enabled source, add them if they have a UI Login button.
        ui_sources = []
        sources: list[Source] = (current_stage.sources.filter(
            enabled=True).order_by("name").select_subclasses())
        for source in sources:
            ui_login_button = source.ui_login_button(self.request)
            if ui_login_button:
                button = asdict(ui_login_button)
                button["challenge"] = ui_login_button.challenge.data
                ui_sources.append(button)
        challenge.initial_data["sources"] = ui_sources
        return challenge
Esempio n. 2
0
 def get_launch_url(self, instance: Application) -> Optional[str]:
     """Get generated launch URL"""
     return instance.get_launch_url()