Skip to content

Commit

Permalink
web/flow: remove websocket connection
Browse files Browse the repository at this point in the history
Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
  • Loading branch information
rissson committed Feb 27, 2025
1 parent f82c6ed commit 516aa9d
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 13 deletions.
1 change: 1 addition & 0 deletions authentik/sources/oauth/views/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def get_user_id(self, info: dict[str, Any]) -> str | None:
def handle_login_failure(self, reason: str) -> HttpResponse:
"Message user and redirect on error."
LOGGER.warning("Authentication Failure", reason=reason)
# TODO(risson): figure out how to avoid this
messages.error(
self.request,
_(
Expand Down
9 changes: 6 additions & 3 deletions authentik/stages/email/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,16 @@ def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
if restore_token.user != user:
self.logger.warning("Flow token for non-matching user, denying request")
return self.executor.stage_invalid()
# TODO(risson): figure out how to avoid this
messages.success(request, _("Successfully verified Email."))
if self.executor.current_stage.activate_user_on_success:
user.is_active = True
user.save()
return self.executor.stage_ok()
if PLAN_CONTEXT_PENDING_USER not in self.executor.plan.context:
self.logger.debug("No pending user")
messages.error(self.request, _("No pending user."))
return self.executor.stage_invalid()
message = _("No pending user")
self.logger.debug(message)
return self.executor.stage_invalid(message)
# Check if we've already sent the initial e-mail
if PLAN_CONTEXT_EMAIL_SENT not in self.executor.plan.context:
try:
Expand All @@ -171,9 +172,11 @@ def challenge_valid(self, response: ChallengeResponse) -> HttpResponse:

def challenge_invalid(self, response: ChallengeResponse) -> HttpResponse:
if PLAN_CONTEXT_PENDING_USER not in self.executor.plan.context:
# TODO(risson): figure out how to avoid this
messages.error(self.request, _("No pending user."))
return super().challenge_invalid(response)
self.send_email()
# TODO(risson): figure out how to avoid this
messages.success(self.request, _("Email Successfully sent."))
# We can't call stage_ok yet, as we're still waiting
# for the user to click the link in the email
Expand Down
1 change: 1 addition & 0 deletions authentik/stages/prompt/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def validate(self, attrs: dict[str, Any]) -> dict[str, Any]:
raise ValidationError(list(result.messages))
else:
for msg in result.messages:
# TODO(risson): figure out how to avoid this
add_message(self.request, INFO, msg)
return attrs

Expand Down
4 changes: 1 addition & 3 deletions authentik/stages/user_delete/stage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Delete stage logic"""

from django.contrib import messages
from django.contrib.auth import logout
from django.http import HttpRequest, HttpResponse
from django.utils.translation import gettext as _
Expand All @@ -17,9 +16,8 @@ def dispatch(self, request: HttpRequest) -> HttpResponse:
user = self.get_pending_user()
if not user.is_authenticated:
message = _("No Pending User.")
messages.error(request, message)
self.logger.debug(message)
return self.executor.stage_invalid()
return self.executor.stage_invalid(message)
logout(self.request)
user.delete()
self.logger.debug("Deleted user", user=user)
Expand Down
3 changes: 1 addition & 2 deletions authentik/stages/user_login/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ def do_login(self, request: HttpRequest, remember: bool = False) -> HttpResponse
"""Attach the currently pending user to the current session"""
if PLAN_CONTEXT_PENDING_USER not in self.executor.plan.context:
message = _("No Pending user to login.")
messages.error(request, message)
self.logger.debug(message)
return self.executor.stage_invalid()
return self.executor.stage_invalid(message)
backend = self.executor.plan.context.get(
PLAN_CONTEXT_AUTHENTICATION_BACKEND, BACKEND_INBUILT
)
Expand Down
4 changes: 0 additions & 4 deletions web/src/flow/FlowExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import { globalAK } from "@goauthentik/common/global";
import { configureSentry } from "@goauthentik/common/sentry";
import { first } from "@goauthentik/common/utils";
import { WebsocketClient } from "@goauthentik/common/ws";
import { Interface } from "@goauthentik/elements/Interface";
import "@goauthentik/elements/LoadingOverlay";
import "@goauthentik/elements/ak-locale-context";
Expand Down Expand Up @@ -83,8 +82,6 @@ export class FlowExecutor extends Interface implements StageHost {
@state()
flowInfo?: ContextualFlowInfo;

ws: WebsocketClient;

static get styles(): CSSResult[] {
return [PFBase, PFLogin, PFDrawer, PFButton, PFTitle, PFList, PFBackgroundImage].concat(css`
:host {
Expand Down Expand Up @@ -174,7 +171,6 @@ export class FlowExecutor extends Interface implements StageHost {

constructor() {
super();
this.ws = new WebsocketClient();
const inspector = new URL(window.location.toString()).searchParams.get("inspector");
if (inspector === "" || inspector === "open") {
this.inspectorOpen = true;
Expand Down
1 change: 0 additions & 1 deletion web/src/flow/FlowInterface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "@goauthentik/elements/messages/MessageContainer";
import "@goauthentik/flow/FlowExecutor";
// Statically import some stages to speed up load speed
import "@goauthentik/flow/stages/access_denied/AccessDeniedStage";
Expand Down

0 comments on commit 516aa9d

Please sign in to comment.