Skip to content

Commit

Permalink
core: fix source_flow_manager throwing error when authenticated user …
Browse files Browse the repository at this point in the history
…attempts to re-authenticate with existing link (goauthentik#12080)

Signed-off-by: Jens Langhammer <[email protected]>
  • Loading branch information
BeryJu authored Nov 19, 2024
1 parent 50015c5 commit 01fc5eb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions authentik/core/sources/flow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ def get_action(self, **kwargs) -> tuple[Action, UserSourceConnection | None]: #
)
new_connection.user = self.request.user
new_connection = self.update_user_connection(new_connection, **kwargs)
if existing := self.user_connection_type.objects.filter(
source=self.source, identifier=self.identifier
).first():
existing = self.update_user_connection(existing)
return Action.AUTH, existing
return Action.LINK, new_connection

action, connection = self.matcher.get_user_action(self.identifier, self.user_properties)
Expand Down
16 changes: 16 additions & 0 deletions authentik/core/tests/test_source_flow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ def test_authenticated_link(self):
reverse("authentik_core:if-user") + "#/settings;page-sources",
)

def test_authenticated_auth(self):
"""Test authenticated user linking"""
user = User.objects.create(username="foo", email="[email protected]")
UserOAuthSourceConnection.objects.create(
user=user, source=self.source, identifier=self.identifier
)
request = get_request("/", user=user)
flow_manager = OAuthSourceFlowManager(
self.source, request, self.identifier, {"info": {}}, {}
)
action, connection = flow_manager.get_action()
self.assertEqual(action, Action.AUTH)
self.assertIsNotNone(connection.pk)
response = flow_manager.get_flow()
self.assertEqual(response.status_code, 302)

def test_unauthenticated_link(self):
"""Test un-authenticated user linking"""
flow_manager = OAuthSourceFlowManager(
Expand Down

0 comments on commit 01fc5eb

Please sign in to comment.