-
Notifications
You must be signed in to change notification settings - Fork 354
MSC3861: load the issuer and account management URLs from OIDC discovery #17407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
65120fe
MSC3861: load the issuer and account management URLs from OIDC discovery
sandhose 86d7fee
Newsfile.
sandhose ee0cd1a
Import `cast` from `typing` instead of `typing_extensions`.
sandhose 2ff5321
Fix loading the account management URL from the issuer
sandhose 90b6a4f
Merge remote-tracking branch 'origin/develop' into quenting/msc3861-l…
sandhose 0119d40
Use the cached metadata call
sandhose b035669
Merge remote-tracking branch 'origin/develop' into quenting/msc3861-l…
sandhose 5d9d269
Don't fallback to the config issuer if loading the metadata fails
sandhose f4dc986
Merge remote-tracking branch 'origin/develop' into quenting/msc3861-l…
sandhose 089a542
Use the right account management URL in the UIA fallback
sandhose 17a90f7
Fix tests now that we're always fetching the issuer metadata
sandhose 40c854c
Fix well-known tests now that we're fetching through the metadata
sandhose 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 hidden or 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 @@ | ||
MSC3861: load the issuer and account management URLs from OIDC discovery. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -18,12 +18,13 @@ | |
# | ||
# | ||
import logging | ||
from typing import TYPE_CHECKING, Optional | ||
from typing import TYPE_CHECKING, Optional, Tuple, cast | ||
|
||
from twisted.web.resource import Resource | ||
from twisted.web.server import Request | ||
|
||
from synapse.http.server import set_cors_headers | ||
from synapse.api.errors import NotFoundError | ||
from synapse.http.server import DirectServeJsonResource | ||
from synapse.http.site import SynapseRequest | ||
from synapse.types import JsonDict | ||
from synapse.util import json_encoder | ||
|
@@ -38,8 +39,9 @@ | |
class WellKnownBuilder: | ||
def __init__(self, hs: "HomeServer"): | ||
self._config = hs.config | ||
self._auth = hs.get_auth() | ||
|
||
def get_well_known(self) -> Optional[JsonDict]: | ||
async def get_well_known(self) -> Optional[JsonDict]: | ||
if not self._config.server.serve_client_wellknown: | ||
return None | ||
|
||
|
@@ -52,13 +54,20 @@ def get_well_known(self) -> Optional[JsonDict]: | |
|
||
# We use the MSC3861 values as they are used by multiple MSCs | ||
if self._config.experimental.msc3861.enabled: | ||
# If MSC3861 is enabled, we can assume self._auth is an instance of MSC3861DelegatedAuth | ||
# We import lazily here because of the authlib requirement | ||
from synapse.api.auth.msc3861_delegated import MSC3861DelegatedAuth | ||
|
||
auth = cast(MSC3861DelegatedAuth, self._auth) | ||
|
||
result["org.matrix.msc2965.authentication"] = { | ||
"issuer": self._config.experimental.msc3861.issuer | ||
"issuer": await auth.issuer(), | ||
} | ||
if self._config.experimental.msc3861.account_management_url is not None: | ||
account_management_url = await auth.account_management_url() | ||
if account_management_url is not None: | ||
result["org.matrix.msc2965.authentication"][ | ||
"account" | ||
] = self._config.experimental.msc3861.account_management_url | ||
] = account_management_url | ||
|
||
if self._config.server.extra_well_known_client_content: | ||
for ( | ||
|
@@ -71,26 +80,22 @@ def get_well_known(self) -> Optional[JsonDict]: | |
return result | ||
|
||
|
||
class ClientWellKnownResource(Resource): | ||
class ClientWellKnownResource(DirectServeJsonResource): | ||
"""A Twisted web resource which renders the .well-known/matrix/client file""" | ||
|
||
isLeaf = 1 | ||
|
||
def __init__(self, hs: "HomeServer"): | ||
Resource.__init__(self) | ||
super().__init__() | ||
self._well_known_builder = WellKnownBuilder(hs) | ||
|
||
def render_GET(self, request: SynapseRequest) -> bytes: | ||
set_cors_headers(request) | ||
r = self._well_known_builder.get_well_known() | ||
async def _async_render_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: | ||
r = await self._well_known_builder.get_well_known() | ||
if not r: | ||
request.setResponseCode(404) | ||
request.setHeader(b"Content-Type", b"text/plain") | ||
return b".well-known not available" | ||
raise NotFoundError(".well-known not available") | ||
|
||
logger.debug("returning: %s", r) | ||
request.setHeader(b"Content-Type", b"application/json") | ||
return json_encoder.encode(r).encode("utf-8") | ||
Comment on lines
-74
to
-93
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. Changes here don't change the response when the WK can be built: Before:
After:
It does although change the response when the public_baseurl isn't set: Before:
After:
Which is IMO perfectly acceptable |
||
return 200, r | ||
|
||
|
||
class ServerWellKnownResource(Resource): | ||
|
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.