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

Commit

Permalink
Fix some types in the CAS code.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Nov 19, 2020
1 parent 79bfe96 commit 37fb198
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.d/8784.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix type hints in CAS handler.
18 changes: 14 additions & 4 deletions synapse/handlers/cas_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
import logging
import urllib
from typing import Dict, Optional, Tuple
from typing import TYPE_CHECKING, Dict, Optional, Tuple
from xml.etree import ElementTree as ET

from twisted.web.client import PartialDownloadError
Expand All @@ -23,6 +23,9 @@
from synapse.http.site import SynapseRequest
from synapse.types import UserID, map_username_to_mxid_localpart

if TYPE_CHECKING:
from synapse.app.homeserver import HomeServer

logger = logging.getLogger(__name__)


Expand All @@ -31,10 +34,10 @@ class CasHandler:
Utility class for to handle the response from a CAS SSO service.
Args:
hs (synapse.server.HomeServer)
hs
"""

def __init__(self, hs):
def __init__(self, hs: "HomeServer"):
self.hs = hs
self._hostname = hs.hostname
self._auth_handler = hs.get_auth_handler()
Expand Down Expand Up @@ -205,11 +208,16 @@ async def handle_ticket(
registered_user_id = await self._auth_handler.check_user_exists(user_id)

if session:
# If there's a session then the user must already exist.
assert registered_user_id

await self._auth_handler.complete_sso_ui_auth(
registered_user_id, session, request,
)

else:
# If this not a UI auth request than there must be a redirect URL.
assert client_redirect_url

if not registered_user_id:
# Pull out the user-agent and IP from the request.
user_agent = request.get_user_agent("")
Expand All @@ -221,6 +229,8 @@ async def handle_ticket(
user_agent_ips=(user_agent, ip_address),
)

assert registered_user_id

await self._auth_handler.complete_sso_login(
registered_user_id, request, client_redirect_url
)
2 changes: 1 addition & 1 deletion synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async def register_user(
bind_emails=[],
by_admin=False,
user_agent_ips=None,
):
) -> str:
"""Registers a new client on the server.
Args:
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/saml_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from synapse.util.iterutils import chunk_seq

if TYPE_CHECKING:
import synapse.server
from synapse.server import HomeServer

logger = logging.getLogger(__name__)

Expand All @@ -56,7 +56,7 @@ class Saml2SessionData:


class SamlHandler(BaseHandler):
def __init__(self, hs: "synapse.server.HomeServer"):
def __init__(self, hs: "HomeServer"):
super().__init__(hs)
self._saml_client = Saml2Client(hs.config.saml2_sp_config)
self._saml_idp_entityid = hs.config.saml2_idp_entityid
Expand Down

0 comments on commit 37fb198

Please sign in to comment.