This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add additional type hints to SSO and registration code #8784
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
37fb198
Fix some types in the CAS code.
clokep 28ad9bf
Add additional types to registration handler.
clokep 2e83da8
Fix a bug with generating display names.
clokep 7ade914
Remove unnecessary assertion.
clokep e62f4dc
Update newsfragment.
clokep 2819f83
Update comment.
clokep 3b9ce2a
Re-structure CAS code to be more similar to SAML/OIDC.
clokep 781e280
Update the changelog.
clokep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add additional type hints in the registration and SSO handlers. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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__) | ||
|
||
|
||
|
@@ -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() | ||
|
@@ -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("") | ||
|
@@ -218,7 +226,7 @@ async def handle_ticket( | |
registered_user_id = await self._registration_handler.register_user( | ||
localpart=localpart, | ||
default_display_name=user_display_name, | ||
user_agent_ips=(user_agent, ip_address), | ||
user_agent_ips=[(user_agent, ip_address)], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fix is made to the CAS, OIDC, and SAML handlers and is a bug from #8034. |
||
) | ||
|
||
await self._auth_handler.complete_sso_login( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a bugfix now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! I'll re-word this to talk about the bug being fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated this although I don't love my wording...