Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Move complete_sso_ui_auth into SSOHandler
Browse files Browse the repository at this point in the history
since we're hacking on this code anyway, may as well move it out of the
cluttered AuthHandler.
  • Loading branch information
richvdh committed Jan 13, 2021
1 parent 615760c commit b963939
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
25 changes: 0 additions & 25 deletions synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,6 @@ def __init__(self, hs: "HomeServer"):
# authenticating for an operation to occur on their account.
self._sso_auth_confirm_template = hs.config.sso_auth_confirm_template

# The following template is shown after a successful user interactive
# authentication session. It tells the user they can close the window.
self._sso_auth_success_template = hs.config.sso_auth_success_template

# The following template is shown during the SSO authentication process if
# the account is deactivated.
self._sso_account_deactivated_template = (
Expand Down Expand Up @@ -1394,27 +1390,6 @@ async def start_sso_ui_auth(self, request: SynapseRequest, session_id: str) -> s
description=session.description, redirect_url=redirect_url,
)

async def complete_sso_ui_auth(
self, registered_user_id: str, session_id: str, request: Request,
):
"""Having figured out a mxid for this user, complete the HTTP request
Args:
registered_user_id: The registered user ID to complete SSO login for.
session_id: The ID of the user-interactive auth session.
request: The request to complete.
"""
# Mark the stage of the authentication as successful.
# Save the user who authenticated with SSO, this will be used to ensure
# that the account be modified is also the person who logged in.
await self.store.mark_ui_auth_stage_complete(
session_id, LoginType.SSO, registered_user_id
)

# Render the HTML and return.
html = self._sso_auth_success_template
respond_with_html(request, 200, html)

async def complete_sso_login(
self,
registered_user_id: str,
Expand Down
16 changes: 13 additions & 3 deletions synapse/handlers/sso.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from twisted.web.http import Request

from synapse.api.constants import LoginType
from synapse.api.errors import Codes, RedirectException, SynapseError
from synapse.handlers.ui_auth import UIAuthSessionDataConstants
from synapse.http import get_request_user_agent
Expand Down Expand Up @@ -147,9 +148,13 @@ def __init__(self, hs: "HomeServer"):
self._store = hs.get_datastore()
self._server_name = hs.hostname
self._registration_handler = hs.get_registration_handler()
self._auth_handler = hs.get_auth_handler()
self._error_template = hs.config.sso_error_template
self._bad_user_template = hs.config.sso_auth_bad_user_template
self._auth_handler = hs.get_auth_handler()

# The following template is shown after a successful user interactive
# authentication session. It tells the user they can close the window.
self._sso_auth_success_template = hs.config.sso_auth_success_template

# a lock on the mappings
self._mapping_lock = Linearizer(name="sso_user_mapping", clock=hs.get_clock())
Expand Down Expand Up @@ -598,9 +603,14 @@ async def complete_sso_ui_auth_request(
)
else:
# success!
await self._auth_handler.complete_sso_ui_auth(
user_id, ui_auth_session_id, request
# Mark the stage of the authentication as successful.
await self._store.mark_ui_auth_stage_complete(
ui_auth_session_id, LoginType.SSO, user_id
)

# Render the HTML confirmation page and return.
html = self._sso_auth_success_template
respond_with_html(request, 200, html)
return

# the user_id didn't match: render an error page.
Expand Down

0 comments on commit b963939

Please sign in to comment.