Added a new method which allows me to find a issuer given an endpoint and the endpoint url.

This commit is contained in:
Roland Hedberg 2014-12-15 08:45:03 +01:00
parent d5309ac514
commit bce5e69b4e
3 changed files with 42 additions and 6 deletions

View File

@ -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]

View File

@ -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

View File

@ -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()