diff --git a/src/oic/oic/__init__.py b/src/oic/oic/__init__.py index 5494dc1..2982788 100644 --- a/src/oic/oic/__init__.py +++ b/src/oic/oic/__init__.py @@ -1121,13 +1121,42 @@ class Client(oauth2.Client): #subject, host = self.normalization(principal) return self.wf.discovery_query(principal) + def endpoint2issuer(self, url, endpoint=""): + """ + Given that I know which endpoint it's about and which URL was used + which issuer was it. + + :param str endpoint: Which endpoint + :param str url: The endpoint url + :return: Issuer identifier if one matched otherwise "" + """ + + if endpoint: + for issuer, pi in self.provider_info.items(): + try: + if pi[endpoint] == url: + return issuer + except KeyError: + pass + else: + for issuer, pi in self.provider_info.items(): + for endpoint in ENDPOINTS: + try: + if pi[endpoint] == url: + return issuer + except KeyError: + pass + + return "" + #noinspection PyMethodOverriding class Server(oauth2.Server): def __init__(self, keyjar=None, ca_certs=None, verify_ssl=True): oauth2.Server.__init__(self, keyjar, ca_certs, verify_ssl) - def _parse_urlencoded(self, url=None, query=None): + @staticmethod + def _parse_urlencoded(url=None, query=None): if url: parts = urlparse.urlparse(url) scheme, netloc, path, params, query, fragment = parts[:6] diff --git a/src/oic/oic/consumer.py b/src/oic/oic/consumer.py index 954f758..92442a6 100644 --- a/src/oic/oic/consumer.py +++ b/src/oic/oic/consumer.py @@ -74,7 +74,6 @@ def build_userinfo_claims(claims, sformat="signed", locale="us-en"): "email_verified": {"essential": true}, "picture": null } - """ return Claims(format=sformat, **claims) @@ -131,8 +130,8 @@ class Consumer(Client): :param config: Configuration of the consumer :param client_config: Client configuration :param server_info: Information about the server - :param client_prefs: Run time preferences, which are chosen - depends on what the server can do. + :param client_prefs: Run time preferences, which are chosen depends + on what the server can do. """ if client_config is None: client_config = {} @@ -211,7 +210,7 @@ class Consumer(Client): This defines if it should be used anyway. :param path: The path part of the redirect URL :return: A 2-tuple, session identifier and URL to which the user - should be redirected + should be redirected """ _log_info = logger.info diff --git a/tests/test_oic.py b/tests/test_oic.py index 37c7f88..cb15ba3 100644 --- a/tests/test_oic.py +++ b/tests/test_oic.py @@ -1161,9 +1161,17 @@ def test_make_id_token(): assert atr.verify(keyjar=srv.keyjar) +def test_endpoint2issuer(): + from pinit import provider_init + client = Client() + client.provider_info = {"/": provider_init.create_providerinfo()} + issuer = client.endpoint2issuer("/registration") + assert issuer == "/" + + if __name__ == "__main__": # t = TestOICClient() # t.setup_class() # t.test_access_token_request() - test_client_secret_jwt() + test_endpoint2issuer()