Skip to content

Commit

Permalink
flows: remove stage challenge type
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Langhammer <[email protected]>
  • Loading branch information
BeryJu committed Jul 12, 2024
1 parent 9e32c78 commit 6c8e448
Show file tree
Hide file tree
Showing 45 changed files with 60 additions and 256 deletions.
2 changes: 0 additions & 2 deletions authentik/core/views/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from authentik.core.models import Application
from authentik.flows.challenge import (
ChallengeResponse,
ChallengeTypes,
HttpChallengeResponse,
RedirectChallenge,
)
Expand Down Expand Up @@ -74,7 +73,6 @@ def get_challenge(self, *args, **kwargs) -> RedirectChallenge:
raise Http404
return RedirectChallenge(
instance={
"type": ChallengeTypes.REDIRECT.value,
"to": launch,
}
)
Expand Down
12 changes: 0 additions & 12 deletions authentik/flows/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ class FlowLayout(models.TextChoices):
SIDEBAR_RIGHT = "sidebar_right"


class ChallengeTypes(Enum):
"""Currently defined challenge types"""

NATIVE = "native"
SHELL = "shell"
REDIRECT = "redirect"


class ErrorDetailSerializer(PassiveSerializer):
"""Serializer for rest_framework's error messages"""

Expand All @@ -60,9 +52,6 @@ class Challenge(PassiveSerializer):
"""Challenge that gets sent to the client based on which stage
is currently active"""

type = ChoiceField(
choices=[(x.value, x.name) for x in ChallengeTypes],
)
flow_info = ContextualFlowInfo(required=False)
component = CharField(default="")

Expand Down Expand Up @@ -96,7 +85,6 @@ class FlowErrorChallenge(Challenge):
"""Challenge class when an unhandled error occurs during a stage. Normal users
are shown an error message, superusers are shown a full stacktrace."""

type = CharField(default=ChallengeTypes.NATIVE.value)
component = CharField(default="ak-stage-flow-error")

request_id = CharField()
Expand Down
3 changes: 0 additions & 3 deletions authentik/flows/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
AccessDeniedChallenge,
Challenge,
ChallengeResponse,
ChallengeTypes,
ContextualFlowInfo,
HttpChallengeResponse,
RedirectChallenge,
Expand Down Expand Up @@ -244,7 +243,6 @@ def get_challenge(self, *args, **kwargs) -> Challenge:
return AccessDeniedChallenge(
data={
"error_message": str(self.error_message or "Unknown error"),
"type": ChallengeTypes.NATIVE.value,
"component": "ak-stage-access-denied",
}
)
Expand All @@ -264,7 +262,6 @@ def get_challenge(self, *args, **kwargs) -> RedirectChallenge:
)
return RedirectChallenge(
data={
"type": ChallengeTypes.REDIRECT.value,
"to": destination,
}
)
Expand Down
6 changes: 1 addition & 5 deletions authentik/flows/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from rest_framework.test import APITestCase

from authentik.core.models import User
from authentik.flows.challenge import ChallengeTypes
from authentik.flows.models import Flow


Expand All @@ -26,7 +25,6 @@ def assertStageResponse(
self.assertEqual(response.status_code, 200)
raw_response = loads(response.content.decode())
self.assertIsNotNone(raw_response["component"])
self.assertIsNotNone(raw_response["type"])
if flow:
self.assertIn("flow_info", raw_response)
self.assertEqual(raw_response["flow_info"]["background"], flow.background_url)
Expand All @@ -46,6 +44,4 @@ def assertStageResponse(

def assertStageRedirects(self, response: HttpResponse, to: str) -> dict[str, Any]:
"""Wrapper around assertStageResponse that checks for a redirect"""
return self.assertStageResponse(
response, component="xak-flow-redirect", to=to, type=ChallengeTypes.REDIRECT.value
)
return self.assertStageResponse(response, component="xak-flow-redirect", to=to)
4 changes: 1 addition & 3 deletions authentik/flows/tests/test_challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.test import TestCase

from authentik.flows.challenge import AutosubmitChallenge, ChallengeTypes
from authentik.flows.challenge import AutosubmitChallenge

Check warning on line 6 in authentik/flows/tests/test_challenges.py

View check run for this annotation

Codecov / codecov/patch

authentik/flows/tests/test_challenges.py#L5-L6

Added lines #L5 - L6 were not covered by tests

class TestChallenges(TestCase):
Expand All @@ -12,7 +12,6 @@ def test_autosubmit_blank(self):
"""Test blank autosubmit"""
challenge = AutosubmitChallenge(
data={
"type": ChallengeTypes.NATIVE.value,
"url": "http://localhost",
"attrs": {},
}
Expand All @@ -21,7 +20,6 @@ def test_autosubmit_blank(self):
# Test with an empty value
challenge = AutosubmitChallenge(
data={
"type": ChallengeTypes.NATIVE.value,
"url": "http://localhost",
"attrs": {"foo": ""},
}
Expand Down
2 changes: 0 additions & 2 deletions authentik/flows/tests/test_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from rest_framework.test import APITestCase

from authentik.core.tests.utils import create_test_admin_user, create_test_flow
from authentik.flows.challenge import ChallengeTypes
from authentik.flows.models import FlowDesignation, FlowStageBinding, InvalidResponseAction
from authentik.stages.dummy.models import DummyStage
from authentik.stages.identification.models import IdentificationStage, UserFields
Expand Down Expand Up @@ -54,7 +53,6 @@ def test(self):
"layout": "stacked",
},
"flow_designation": "authentication",
"type": ChallengeTypes.NATIVE.value,
"password_fields": False,
"primary_action": "Log in",
"sources": [],
Expand Down
4 changes: 0 additions & 4 deletions authentik/flows/views/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from authentik.flows.challenge import (
Challenge,
ChallengeResponse,
ChallengeTypes,
FlowErrorChallenge,
HttpChallengeResponse,
RedirectChallenge,
Expand Down Expand Up @@ -552,7 +551,6 @@ def to_stage_response(request: HttpRequest, source: HttpResponse) -> HttpRespons
return HttpChallengeResponse(
RedirectChallenge(
{
"type": ChallengeTypes.REDIRECT,
"to": str(redirect_url),
}
)
Expand All @@ -561,7 +559,6 @@ def to_stage_response(request: HttpRequest, source: HttpResponse) -> HttpRespons
return HttpChallengeResponse(
ShellChallenge(
{
"type": ChallengeTypes.SHELL,
"body": source.render().content.decode("utf-8"),
}
)
Expand All @@ -571,7 +568,6 @@ def to_stage_response(request: HttpRequest, source: HttpResponse) -> HttpRespons
return HttpChallengeResponse(
ShellChallenge(
{
"type": ChallengeTypes.SHELL,
"body": source.content.decode("utf-8"),
}
)
Expand Down
6 changes: 0 additions & 6 deletions authentik/providers/oauth2/tests/test_authorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from authentik.core.models import Application
from authentik.core.tests.utils import create_test_admin_user, create_test_flow
from authentik.events.models import Event, EventAction
from authentik.flows.challenge import ChallengeTypes
from authentik.lib.generators import generate_id
from authentik.lib.utils.time import timedelta_from_string
from authentik.providers.oauth2.constants import TOKEN_TYPE
Expand Down Expand Up @@ -327,7 +326,6 @@ def test_full_code(self):
response.content.decode(),
{
"component": "xak-flow-redirect",
"type": ChallengeTypes.REDIRECT.value,
"to": f"foo://localhost?code={code.code}&state={state}",
},
)
Expand Down Expand Up @@ -397,7 +395,6 @@ def test_full_implicit(self):
response.content.decode(),
{
"component": "xak-flow-redirect",
"type": ChallengeTypes.REDIRECT.value,
"to": (
f"http://localhost#access_token={token.token}"
f"&id_token={provider.encode(token.id_token.to_dict())}"
Expand Down Expand Up @@ -460,7 +457,6 @@ def test_full_fragment_code(self):
response.content.decode(),
{
"component": "xak-flow-redirect",
"type": ChallengeTypes.REDIRECT.value,
"to": (f"http://localhost#code={code.code}" f"&state={state}"),
},
)
Expand Down Expand Up @@ -516,7 +512,6 @@ def test_full_form_post_id_token(self):
response.content.decode(),
{
"component": "ak-stage-autosubmit",
"type": ChallengeTypes.NATIVE.value,
"url": "http://localhost",
"title": f"Redirecting to {app.name}...",
"attrs": {
Expand Down Expand Up @@ -564,7 +559,6 @@ def test_full_form_post_code(self):
response.content.decode(),
{
"component": "ak-stage-autosubmit",
"type": ChallengeTypes.NATIVE.value,
"url": "http://localhost",
"title": f"Redirecting to {app.name}...",
"attrs": {
Expand Down
5 changes: 0 additions & 5 deletions authentik/providers/oauth2/tests/test_token_pkce.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from authentik.core.models import Application
from authentik.core.tests.utils import create_test_admin_user, create_test_flow
from authentik.flows.challenge import ChallengeTypes
from authentik.lib.generators import generate_id
from authentik.providers.oauth2.constants import GRANT_TYPE_AUTHORIZATION_CODE
from authentik.providers.oauth2.models import AuthorizationCode, OAuth2Provider
Expand Down Expand Up @@ -60,7 +59,6 @@ def test_pkce_missing_in_authorize(self):
response.content.decode(),
{
"component": "xak-flow-redirect",
"type": ChallengeTypes.REDIRECT.value,
"to": f"foo://localhost?code={code.code}&state={state}",
},
)
Expand Down Expand Up @@ -123,7 +121,6 @@ def test_pkce_missing_in_token(self):
response.content.decode(),
{
"component": "xak-flow-redirect",
"type": ChallengeTypes.REDIRECT.value,
"to": f"foo://localhost?code={code.code}&state={state}",
},
)
Expand Down Expand Up @@ -191,7 +188,6 @@ def test_pkce_correct_s256(self):
response.content.decode(),
{
"component": "xak-flow-redirect",
"type": ChallengeTypes.REDIRECT.value,
"to": f"foo://localhost?code={code.code}&state={state}",
},
)
Expand Down Expand Up @@ -242,7 +238,6 @@ def test_pkce_correct_plain(self):
response.content.decode(),
{
"component": "xak-flow-redirect",
"type": ChallengeTypes.REDIRECT.value,
"to": f"foo://localhost?code={code.code}&state={state}",
},
)
Expand Down
2 changes: 0 additions & 2 deletions authentik/providers/oauth2/views/authorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from authentik.flows.challenge import (
PLAN_CONTEXT_TITLE,
AutosubmitChallenge,
ChallengeTypes,
HttpChallengeResponse,
)
from authentik.flows.exceptions import FlowNonApplicableException
Expand Down Expand Up @@ -484,7 +483,6 @@ def redirect(self, uri: str) -> HttpResponse:

challenge = AutosubmitChallenge(
data={
"type": ChallengeTypes.NATIVE.value,
"component": "ak-stage-autosubmit",
"title": self.executor.plan.context.get(
PLAN_CONTEXT_TITLE,
Expand Down
3 changes: 1 addition & 2 deletions authentik/providers/oauth2/views/device_finish.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.http import HttpResponse
from rest_framework.fields import CharField

from authentik.flows.challenge import Challenge, ChallengeResponse, ChallengeTypes
from authentik.flows.challenge import Challenge, ChallengeResponse
from authentik.flows.planner import FlowPlan
from authentik.flows.stage import ChallengeStageView
from authentik.flows.views.executor import SESSION_KEY_PLAN
Expand Down Expand Up @@ -38,7 +38,6 @@ def get_challenge(self, *args, **kwargs) -> Challenge:
token.save()
return OAuthDeviceCodeFinishChallenge(
data={
"type": ChallengeTypes.NATIVE.value,
"component": "ak-provider-oauth2-device-code-finish",
}
)
Expand Down
3 changes: 1 addition & 2 deletions authentik/providers/oauth2/views/device_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from authentik.brands.models import Brand
from authentik.core.models import Application
from authentik.flows.challenge import Challenge, ChallengeResponse, ChallengeTypes
from authentik.flows.challenge import Challenge, ChallengeResponse
from authentik.flows.exceptions import FlowNonApplicableException
from authentik.flows.models import in_memory_stage
from authentik.flows.planner import PLAN_CONTEXT_APPLICATION, PLAN_CONTEXT_SSO, FlowPlanner
Expand Down Expand Up @@ -141,7 +141,6 @@ class OAuthDeviceCodeStage(ChallengeStageView):
def get_challenge(self, *args, **kwargs) -> Challenge:
return OAuthDeviceCodeChallenge(
data={
"type": ChallengeTypes.NATIVE.value,
"component": "ak-provider-oauth2-device-code",
}
)
Expand Down
2 changes: 0 additions & 2 deletions authentik/providers/saml/views/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
AutoSubmitChallengeResponse,
Challenge,
ChallengeResponse,
ChallengeTypes,
)
from authentik.flows.planner import PLAN_CONTEXT_APPLICATION
from authentik.flows.stage import ChallengeStageView
Expand Down Expand Up @@ -81,7 +80,6 @@ def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
return super().get(
self.request,
**{
"type": ChallengeTypes.NATIVE.value,
"component": "ak-stage-autosubmit",
"title": self.executor.plan.context.get(
PLAN_CONTEXT_TITLE,
Expand Down
1 change: 0 additions & 1 deletion authentik/root/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@
},
"ENUM_NAME_OVERRIDES": {
"EventActions": "authentik.events.models.EventAction",
"ChallengeChoices": "authentik.flows.challenge.ChallengeTypes",
"FlowDesignationEnum": "authentik.flows.models.FlowDesignation",
"FlowLayoutEnum": "authentik.flows.models.FlowLayout",
"PolicyEngineMode": "authentik.policies.models.PolicyEngineMode",
Expand Down
3 changes: 1 addition & 2 deletions authentik/sources/oauth/types/apple.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rest_framework.fields import CharField
from structlog.stdlib import get_logger

from authentik.flows.challenge import Challenge, ChallengeResponse, ChallengeTypes
from authentik.flows.challenge import Challenge, ChallengeResponse
from authentik.sources.oauth.clients.oauth2 import OAuth2Client
from authentik.sources.oauth.models import OAuthSource
from authentik.sources.oauth.types.registry import SourceType, registry
Expand Down Expand Up @@ -130,6 +130,5 @@ def login_challenge(self, source: OAuthSource, request: HttpRequest) -> Challeng
"scope": "name email",
"redirect_uri": args["redirect_uri"],
"state": args["state"],
"type": ChallengeTypes.NATIVE.value,
}
)
3 changes: 1 addition & 2 deletions authentik/sources/oauth/types/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.urls.base import reverse
from structlog.stdlib import get_logger

from authentik.flows.challenge import Challenge, ChallengeTypes, RedirectChallenge
from authentik.flows.challenge import Challenge, RedirectChallenge
from authentik.sources.oauth.models import OAuthSource
from authentik.sources.oauth.views.callback import OAuthCallback
from authentik.sources.oauth.views.redirect import OAuthRedirect
Expand Down Expand Up @@ -48,7 +48,6 @@ def login_challenge(self, source: OAuthSource, request: HttpRequest) -> Challeng
"""Allow types to return custom challenges"""
return RedirectChallenge(
data={
"type": ChallengeTypes.REDIRECT.value,
"to": reverse(
"authentik_sources_oauth:oauth-client-login",
kwargs={"source_slug": source.slug},
Expand Down
3 changes: 1 addition & 2 deletions authentik/sources/plex/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from authentik.core.models import Source, UserSourceConnection
from authentik.core.types import UILoginButton, UserSettingSerializer
from authentik.flows.challenge import Challenge, ChallengeResponse, ChallengeTypes
from authentik.flows.challenge import Challenge, ChallengeResponse
from authentik.lib.generators import generate_id


Expand Down Expand Up @@ -71,7 +71,6 @@ def ui_login_button(self, request: HttpRequest) -> UILoginButton:
return UILoginButton(
challenge=PlexAuthenticationChallenge(
data={
"type": ChallengeTypes.NATIVE.value,
"component": "ak-source-plex",
"client_id": self.client_id,
"slug": self.slug,
Expand Down
3 changes: 1 addition & 2 deletions authentik/sources/saml/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from authentik.core.models import Source, UserSourceConnection
from authentik.core.types import UILoginButton, UserSettingSerializer
from authentik.crypto.models import CertificateKeyPair
from authentik.flows.challenge import ChallengeTypes, RedirectChallenge
from authentik.flows.challenge import RedirectChallenge
from authentik.flows.models import Flow
from authentik.lib.utils.time import timedelta_string_validator
from authentik.sources.saml.processors.constants import (
Expand Down Expand Up @@ -204,7 +204,6 @@ def ui_login_button(self, request: HttpRequest) -> UILoginButton:
return UILoginButton(
challenge=RedirectChallenge(
data={
"type": ChallengeTypes.REDIRECT.value,
"to": reverse(
"authentik_sources_saml:login",
kwargs={"source_slug": self.slug},
Expand Down
Loading

0 comments on commit 6c8e448

Please sign in to comment.