-
Notifications
You must be signed in to change notification settings - Fork 133
ModuleRouter: support paths in BASE #405
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
3ce3a64
b253b30
fc9374c
8cb44d6
b4b8df8
0c8ab4f
416d501
740ba28
f975308
f166869
e25c9e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
""" | ||
from ..attribute_mapping import AttributeMapper | ||
|
||
import os.path | ||
from urllib.parse import urlparse | ||
|
||
|
||
class FrontendModule(object): | ||
""" | ||
|
@@ -14,17 +17,22 @@ def __init__(self, auth_req_callback_func, internal_attributes, base_url, name): | |
:type auth_req_callback_func: | ||
(satosa.context.Context, satosa.internal.InternalData) -> satosa.response.Response | ||
:type internal_attributes: dict[str, dict[str, str | list[str]]] | ||
:type base_url: str | ||
:type name: str | ||
|
||
:param auth_req_callback_func: Callback should be called by the module after the | ||
authorization response has been processed. | ||
:param internal_attributes: attribute mapping | ||
:param base_url: base url of the proxy | ||
:param name: name of the plugin | ||
""" | ||
self.auth_req_callback_func = auth_req_callback_func | ||
self.internal_attributes = internal_attributes | ||
self.converter = AttributeMapper(internal_attributes) | ||
self.base_url = base_url | ||
self.base_url = base_url or "" | ||
bajnokk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.name = name | ||
self.endpoint_baseurl = os.path.join(self.base_url, self.name) | ||
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.
To join URLs with paths using a function, use The simplest approach is to just concatenate with a 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. I always forget about Windows, good catch, thanks. The biggest advantage of 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. I would probably name the function Note that the latest pysaml2 already requires Python 3.9 and SATOSA will be updated to require it too. IdentityPython projects try to be compatible with the python that ships on the latest Debian stable release (which is now Python 3.9). 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. The updated patch contains a |
||
self.endpoint_basepath = urlparse(self.endpoint_baseurl).path.lstrip("/") | ||
|
||
def handle_authn_response(self, context, internal_resp): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ | |||||
|
||||||
import json | ||||||
import logging | ||||||
import os.path | ||||||
from collections import defaultdict | ||||||
from urllib.parse import urlencode, urlparse | ||||||
|
||||||
|
@@ -97,7 +98,6 @@ def __init__(self, auth_req_callback_func, internal_attributes, conf, base_url, | |||||
else: | ||||||
cdb = {} | ||||||
|
||||||
self.endpoint_baseurl = "{}/{}".format(self.base_url, self.name) | ||||||
self.provider = _create_provider( | ||||||
provider_config, | ||||||
self.endpoint_baseurl, | ||||||
|
@@ -173,6 +173,18 @@ def register_endpoints(self, backend_names): | |||||
:rtype: list[(str, ((satosa.context.Context, Any) -> satosa.response.Response, Any))] | ||||||
:raise ValueError: if more than one backend is configured | ||||||
""" | ||||||
# See https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig | ||||||
# Unfortunately since the issuer is always `base_url` for all OIDC frontend instances, | ||||||
# the discovery endpoint will be the same for every instance. | ||||||
# This means that only one frontend will be usable for autodiscovery. | ||||||
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.
The issuer is discovered through a WebFinger request for resources of What we define is that the frontend contains the frontend name as a path component and under that you can query the well-known documents. With that in mind we can have multiple frontends each with its own discovery. The problem is that atm, the We can introduce a configuration option to select between the two behaviours, or (even better) introduce a configuration to set the discovery URL for a frontend. At some point I would like to invert this logic; instead of a component defining paths of URLs internally that mapped to functionality (which the routing module has to match to based on some rules), there should be URLs as entrypoints mapped to functionality directly (as it happens within most web frameworks - flask, django, fastapi, etc). 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.
Would you agree to add a A more subtle change but also harder to document alternative would be to make the assignment in
provider dict.
Is any of the two OK with you, or am I misunderstanding the problem? 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. Yes, both are ok with me. As long as we provide a way to configure things to work as before, it is fine to introduce such changes. 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. The updated patchset contains a commit, which does not perform the above assignment if the provider config has the issuer set. I did some research in git log, but I think it was just in this way forever. |
||||||
autoconf_path = ".well-known/openid-configuration" | ||||||
base_path = urlparse(self.base_url).path.lstrip("/") | ||||||
provider_config = ( | ||||||
"^{}$".format(os.path.join(base_path, autoconf_path)), | ||||||
self.provider_config, | ||||||
) | ||||||
jwks_uri = ("^{}/jwks$".format(self.endpoint_basepath), self.jwks) | ||||||
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.
Suggested change
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. These are not equivalents. The equivalent form would be 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. oh, I didn't think that So, I still think this is fine, but let me know if I'm skipping over anything. |
||||||
|
||||||
backend_name = None | ||||||
if len(backend_names) != 1: | ||||||
# only supports one backend since there currently is no way to publish multiple authorization endpoints | ||||||
|
@@ -189,40 +201,49 @@ def register_endpoints(self, backend_names): | |||||
else: | ||||||
backend_name = backend_names[0] | ||||||
|
||||||
provider_config = ("^.well-known/openid-configuration$", self.provider_config) | ||||||
jwks_uri = ("^{}/jwks$".format(self.name), self.jwks) | ||||||
|
||||||
if backend_name: | ||||||
# if there is only one backend, include its name in the path so the default routing can work | ||||||
auth_endpoint = "{}/{}/{}/{}".format(self.base_url, backend_name, self.name, AuthorizationEndpoint.url) | ||||||
auth_endpoint = os.path.join( | ||||||
self.base_url, | ||||||
backend_name, | ||||||
self.name, | ||||||
AuthorizationEndpoint.url, | ||||||
) | ||||||
self.provider.configuration_information["authorization_endpoint"] = auth_endpoint | ||||||
auth_path = urlparse(auth_endpoint).path.lstrip("/") | ||||||
else: | ||||||
auth_path = "{}/{}".format(self.name, AuthorizationEndpoint.url) | ||||||
auth_path = os.path.join(self.endpoint_basepath, AuthorizationRequest.url) | ||||||
|
||||||
authentication = ("^{}$".format(auth_path), self.handle_authn_request) | ||||||
url_map = [provider_config, jwks_uri, authentication] | ||||||
|
||||||
if any("code" in v for v in self.provider.configuration_information["response_types_supported"]): | ||||||
self.provider.configuration_information["token_endpoint"] = "{}/{}".format( | ||||||
self.endpoint_baseurl, TokenEndpoint.url | ||||||
self.provider.configuration_information["token_endpoint"] = os.path.join( | ||||||
self.endpoint_baseurl, | ||||||
TokenEndpoint.url, | ||||||
) | ||||||
token_endpoint = ( | ||||||
"^{}/{}".format(self.name, TokenEndpoint.url), self.token_endpoint | ||||||
"^{}".format(os.path.join(self.endpoint_basepath, TokenEndpoint.url)), | ||||||
self.token_endpoint, | ||||||
) | ||||||
url_map.append(token_endpoint) | ||||||
|
||||||
self.provider.configuration_information["userinfo_endpoint"] = ( | ||||||
"{}/{}".format(self.endpoint_baseurl, UserinfoEndpoint.url) | ||||||
os.path.join(self.endpoint_baseurl, UserinfoEndpoint.url) | ||||||
) | ||||||
userinfo_endpoint = ( | ||||||
"^{}/{}".format(self.name, UserinfoEndpoint.url), self.userinfo_endpoint | ||||||
"^{}".format( | ||||||
os.path.join(self.endpoint_basepath, UserinfoEndpoint.url) | ||||||
), | ||||||
self.userinfo_endpoint, | ||||||
) | ||||||
url_map.append(userinfo_endpoint) | ||||||
|
||||||
if "registration_endpoint" in self.provider.configuration_information: | ||||||
client_registration = ( | ||||||
"^{}/{}".format(self.name, RegistrationEndpoint.url), | ||||||
"^{}".format( | ||||||
os.path.join(self.endpoint_basepath, RegistrationEndpoint.url) | ||||||
), | ||||||
self.client_registration, | ||||||
) | ||||||
url_map.append(client_registration) | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.