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

add support for handling avatar with SSO login #13917

Merged
merged 78 commits into from
Nov 25, 2022
Merged
Changes from 1 commit
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
6c67c5a
add support for handling avatar with SSO login
ashfame Sep 23, 2022
0fd47d1
add changelog file
ashfame Sep 27, 2022
546ea47
change log message
ashfame Sep 28, 2022
4d74943
remove separate log call, just pass message while logging exception
ashfame Sep 28, 2022
d7285f7
ensure avatar image size is within the max_avatar_size allowed as per…
ashfame Sep 27, 2022
f1767d2
added missing period in changelog file
ashfame Sep 28, 2022
670237c
use synapse's instantiated http client rather than requests library f…
ashfame Sep 28, 2022
879f8ad
ensure content_type is checked against allowed mime types
ashfame Sep 28, 2022
c6de28d
oops: HEAD request is to be used and not OPTIONS request for getting …
ashfame Sep 28, 2022
93662ee
better way to obtain headers from response
ashfame Sep 28, 2022
586170d
define picture attribute as Optional[str] with default value as None …
ashfame Sep 28, 2022
6915096
Merge branch 'develop' into sso_avatar_support
ashfame Oct 27, 2022
25d2594
follow standard pattern for getting value out of userinfo with a defa…
ashfame Oct 31, 2022
b343a43
add picture_claim explanation to config docs
ashfame Oct 31, 2022
07cbe39
prefix media_repo attribute with underscore to indicate private usage…
ashfame Nov 1, 2022
f4c1d39
declare docstring for set_avatar()
ashfame Nov 1, 2022
1594a3f
add additional details to exceptions
ashfame Nov 1, 2022
3a18057
log as warning with any raised Exception inside set_avatar() and not …
ashfame Nov 1, 2022
06bbd44
handle reading http headers better
ashfame Nov 1, 2022
93ffe6a
improve exception messages
ashfame Nov 1, 2022
e432b53
enforce max size limit while downloading the image file
ashfame Nov 8, 2022
669c7b0
update avatar with every subsequent login too
ashfame Nov 8, 2022
f5379ed
add unit tests
ashfame Nov 9, 2022
fb823f5
Merge branch 'develop' into sso_avatar_support
ashfame Nov 9, 2022
b51b4f8
declare new variable instead of reusing as type is different
ashfame Nov 9, 2022
adf0640
remove unused imports
ashfame Nov 9, 2022
225be62
fix type issues reported by linter
ashfame Nov 9, 2022
dfd26f0
reorder imports
ashfame Nov 9, 2022
11ff1b4
fix semantic checks
ashfame Nov 10, 2022
1592d43
stream output correctly in test
ashfame Nov 10, 2022
c15e873
define return types on functions and define disallow_untyped_defs as …
ashfame Nov 10, 2022
c0861f8
improved description of function
ashfame Nov 10, 2022
7ff3320
Update tests/handlers/test_sso.py
ashfame Nov 10, 2022
70d3cb5
Update tests/handlers/test_sso.py
ashfame Nov 10, 2022
5271480
do not await in unit tests, use self.get_success()
ashfame Nov 11, 2022
e691a91
user registeration is sorted, remove TODO
ashfame Nov 11, 2022
7101fc0
consistently return FakeResponse and change return type with explanat…
ashfame Nov 11, 2022
2d46136
add await to ready_body_with_max_size()
ashfame Nov 11, 2022
b034ee3
move to alphabetical order
ashfame Nov 11, 2022
6d370b7
remove unnecessary cast
ashfame Nov 11, 2022
e2cc4bf
only use get_file() on http client to enforce size & mime type restri…
ashfame Nov 11, 2022
966edfd
simplify tests as per changed approach
ashfame Nov 11, 2022
19a417d
ensure avatar is set by querying from the profile handler
ashfame Nov 11, 2022
ef9af82
save hash as the upload name for avatar
ashfame Nov 11, 2022
0714752
bail early if the user already has the same avatar saved
ashfame Nov 11, 2022
ecdfe1a
switch to get_proxied_blacklisted_http_client() for blacklisting loca…
ashfame Nov 14, 2022
465bade
let default for picture be None instead of empty string
ashfame Nov 14, 2022
2f1819c
bail early if synapse is not running media repo in-process
ashfame Nov 14, 2022
006800f
Run linter
Nov 16, 2022
4a78052
grammar fixes in docstring
ashfame Nov 24, 2022
b1b0a91
sha256 hash the image instead of md5 hash
ashfame Nov 24, 2022
b710023
cleaner to destructure get_file() results than use indexing to access
ashfame Nov 24, 2022
f118e8b
rename function to include a verb
ashfame Nov 24, 2022
751855c
make set_avatar() return bool so that its easier to test
ashfame Nov 24, 2022
1ef48dd
don't hardcode size, use len() in tests
ashfame Nov 24, 2022
f815f3b
ensure test doesn't break even if SMALL_PNG is changed in future
ashfame Nov 24, 2022
fe8e1ba
fix grammar
ashfame Nov 24, 2022
a973e75
log info message since out-of-process media repos are not supported
ashfame Nov 24, 2022
7e165f4
add comment in respect to type annotations
ashfame Nov 24, 2022
2da03c2
ensure skipping of avatar updation is tested properly
ashfame Nov 24, 2022
7a29b06
fix grammar
ashfame Nov 24, 2022
4ebb1db
fix grammar
ashfame Nov 24, 2022
104eef8
add missing backticks
ashfame Nov 24, 2022
1e87ac4
ensure before skipping avatar updation we check for server_name to ma…
ashfame Nov 24, 2022
0526ec2
add comment for limited support for picture_claim
ashfame Nov 24, 2022
68eaef7
document return value
ashfame Nov 24, 2022
49937c8
skip assignment
ashfame Nov 24, 2022
5542a0f
return true when skipping image since exact image is already set on t…
ashfame Nov 24, 2022
d00385c
better explanation for server configs
ashfame Nov 24, 2022
a81b0f7
fix grammar
ashfame Nov 24, 2022
9a89e9f
fix tests to actually assert True/False, and not relying on get_succe…
ashfame Nov 24, 2022
00af833
fix formatting in tests
ashfame Nov 24, 2022
1a37d82
fix grammar
ashfame Nov 24, 2022
8746b66
correct comment
ashfame Nov 24, 2022
5ac6092
Merge branch 'develop' into sso_avatar_support
squahtx Nov 24, 2022
81d834b
only load the media repo when its available
ashfame Nov 25, 2022
b32c2f7
define type for media_repo instance attribute
ashfame Nov 25, 2022
a14eea5
no need for explicit type annotation when ternary expression is used
ashfame Nov 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions synapse/handlers/sso.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
from synapse.util.stringutils import random_string

if TYPE_CHECKING:
from synapse.rest.media.v1.media_repository import MediaRepository
from synapse.server import HomeServer

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -190,6 +191,8 @@ class SsoHandler:
_MAPPING_SESSION_VALIDITY_PERIOD_MS = 15 * 60 * 1000

def __init__(self, hs: "HomeServer"):
self._media_repo: Optional[MediaRepository]

ashfame marked this conversation as resolved.
Show resolved Hide resolved
self._clock = hs.get_clock()
self._store = hs.get_datastores().main
self._server_name = hs.hostname
Expand All @@ -199,10 +202,9 @@ def __init__(self, hs: "HomeServer"):
self._error_template = hs.config.sso.sso_error_template
self._bad_user_template = hs.config.sso.sso_auth_bad_user_template
self._profile_handler = hs.get_profile_handler()
if hs.config.media.can_load_media_repo:
self._media_repo = hs.get_media_repository()
else:
self._media_repo = None
self._media_repo = (
hs.get_media_repository() if hs.config.media.can_load_media_repo else None
)
self._http_client = hs.get_proxied_blacklisted_http_client()

# The following template is shown after a successful user interactive
Expand Down