authentik.flows.views.interface
Interface views
1"""Interface views""" 2 3from typing import Any 4 5from django.shortcuts import get_object_or_404 6from ua_parser.user_agent_parser import Parse 7 8from authentik.core.views.interface import InterfaceView 9from authentik.flows.models import Flow 10 11 12class FlowInterfaceView(InterfaceView): 13 """Flow interface""" 14 15 def get_context_data(self, **kwargs: Any) -> dict[str, Any]: 16 flow = get_object_or_404(Flow, slug=self.kwargs.get("flow_slug")) 17 kwargs["flow"] = flow 18 kwargs["flow_background_url"] = flow.background_url(self.request) 19 kwargs["inspector"] = "inspector" in self.request.GET 20 return super().get_context_data(**kwargs) 21 22 def compat_needs_sfe(self) -> bool: 23 """Check if we need to use the simplified flow executor for compatibility""" 24 ua = Parse(self.request.META.get("HTTP_USER_AGENT", "")) 25 if ua["user_agent"]["family"] == "IE": 26 return True 27 # Only use SFE for Edge 18 and older, after Edge 18 MS switched to chromium which supports 28 # the default flow executor 29 if ( 30 ua["user_agent"]["family"] == "Edge" 31 and int(ua["user_agent"]["major"]) <= 18 # noqa: PLR2004 32 ): # noqa: PLR2004 33 return True 34 # https://github.com/AzureAD/microsoft-authentication-library-for-objc 35 # Used by Microsoft Teams/Office on macOS, and also uses a very outdated browser engine 36 if "PKeyAuth" in ua["string"]: 37 return True 38 return False 39 40 def get_template_names(self) -> list[str]: 41 if self.compat_needs_sfe() or "sfe" in self.request.GET: 42 return ["if/flow-sfe.html"] 43 return ["if/flow.html"]
13class FlowInterfaceView(InterfaceView): 14 """Flow interface""" 15 16 def get_context_data(self, **kwargs: Any) -> dict[str, Any]: 17 flow = get_object_or_404(Flow, slug=self.kwargs.get("flow_slug")) 18 kwargs["flow"] = flow 19 kwargs["flow_background_url"] = flow.background_url(self.request) 20 kwargs["inspector"] = "inspector" in self.request.GET 21 return super().get_context_data(**kwargs) 22 23 def compat_needs_sfe(self) -> bool: 24 """Check if we need to use the simplified flow executor for compatibility""" 25 ua = Parse(self.request.META.get("HTTP_USER_AGENT", "")) 26 if ua["user_agent"]["family"] == "IE": 27 return True 28 # Only use SFE for Edge 18 and older, after Edge 18 MS switched to chromium which supports 29 # the default flow executor 30 if ( 31 ua["user_agent"]["family"] == "Edge" 32 and int(ua["user_agent"]["major"]) <= 18 # noqa: PLR2004 33 ): # noqa: PLR2004 34 return True 35 # https://github.com/AzureAD/microsoft-authentication-library-for-objc 36 # Used by Microsoft Teams/Office on macOS, and also uses a very outdated browser engine 37 if "PKeyAuth" in ua["string"]: 38 return True 39 return False 40 41 def get_template_names(self) -> list[str]: 42 if self.compat_needs_sfe() or "sfe" in self.request.GET: 43 return ["if/flow-sfe.html"] 44 return ["if/flow.html"]
Flow interface
def
get_context_data(self, **kwargs: Any) -> dict[str, typing.Any]:
16 def get_context_data(self, **kwargs: Any) -> dict[str, Any]: 17 flow = get_object_or_404(Flow, slug=self.kwargs.get("flow_slug")) 18 kwargs["flow"] = flow 19 kwargs["flow_background_url"] = flow.background_url(self.request) 20 kwargs["inspector"] = "inspector" in self.request.GET 21 return super().get_context_data(**kwargs)
def
compat_needs_sfe(self) -> bool:
23 def compat_needs_sfe(self) -> bool: 24 """Check if we need to use the simplified flow executor for compatibility""" 25 ua = Parse(self.request.META.get("HTTP_USER_AGENT", "")) 26 if ua["user_agent"]["family"] == "IE": 27 return True 28 # Only use SFE for Edge 18 and older, after Edge 18 MS switched to chromium which supports 29 # the default flow executor 30 if ( 31 ua["user_agent"]["family"] == "Edge" 32 and int(ua["user_agent"]["major"]) <= 18 # noqa: PLR2004 33 ): # noqa: PLR2004 34 return True 35 # https://github.com/AzureAD/microsoft-authentication-library-for-objc 36 # Used by Microsoft Teams/Office on macOS, and also uses a very outdated browser engine 37 if "PKeyAuth" in ua["string"]: 38 return True 39 return False
Check if we need to use the simplified flow executor for compatibility
def
get_template_names(self) -> list[str]:
41 def get_template_names(self) -> list[str]: 42 if self.compat_needs_sfe() or "sfe" in self.request.GET: 43 return ["if/flow-sfe.html"] 44 return ["if/flow.html"]
Return a list of template names to be used for the request. Must return a list. May not be called if render_to_response() is overridden.