summaryrefslogtreecommitdiff
path: root/macaroonbakery/httpbakery/keyring.py
diff options
context:
space:
mode:
Diffstat (limited to 'macaroonbakery/httpbakery/keyring.py')
-rw-r--r--macaroonbakery/httpbakery/keyring.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/macaroonbakery/httpbakery/keyring.py b/macaroonbakery/httpbakery/keyring.py
index f4e93f7..01a4349 100644
--- a/macaroonbakery/httpbakery/keyring.py
+++ b/macaroonbakery/httpbakery/keyring.py
@@ -3,10 +3,11 @@
from six.moves.urllib.parse import urlparse
import requests
-import macaroonbakery
+import macaroonbakery as bakery
+from macaroonbakery.httpbakery.error import BAKERY_PROTOCOL_HEADER
-class ThirdPartyLocator(macaroonbakery.ThirdPartyLocator):
+class ThirdPartyLocator(bakery.ThirdPartyLocator):
''' Implements macaroonbakery.ThirdPartyLocator by first looking in the
backing cache and, if that fails, making an HTTP request to find the
information associated with the given discharge location.
@@ -23,33 +24,36 @@ class ThirdPartyLocator(macaroonbakery.ThirdPartyLocator):
def third_party_info(self, loc):
u = urlparse(loc)
if u.scheme != 'https' and not self._allow_insecure:
- raise macaroonbakery.ThirdPartyInfoNotFound(
+ raise bakery.ThirdPartyInfoNotFound(
'untrusted discharge URL {}'.format(loc))
loc = loc.rstrip('/')
info = self._cache.get(loc)
if info is not None:
return info
url_endpoint = '/discharge/info'
- resp = requests.get(loc + url_endpoint)
+ headers = {
+ BAKERY_PROTOCOL_HEADER: str(bakery.LATEST_VERSION)
+ }
+ resp = requests.get(url=loc + url_endpoint, headers=headers)
status_code = resp.status_code
if status_code == 404:
url_endpoint = '/publickey'
- resp = requests.get(loc + url_endpoint)
+ resp = requests.get(url=loc + url_endpoint, headers=headers)
status_code = resp.status_code
if status_code != 200:
- raise macaroonbakery.ThirdPartyInfoNotFound(
+ raise bakery.ThirdPartyInfoNotFound(
'unable to get info from {}'.format(url_endpoint))
json_resp = resp.json()
if json_resp is None:
- raise macaroonbakery.ThirdPartyInfoNotFound(
+ raise bakery.ThirdPartyInfoNotFound(
'no response from /discharge/info')
pk = json_resp.get('PublicKey')
if pk is None:
- raise macaroonbakery.ThirdPartyInfoNotFound(
+ raise bakery.ThirdPartyInfoNotFound(
'no public key found in /discharge/info')
- idm_pk = macaroonbakery.PublicKey.deserialize(pk)
- version = json_resp.get('Version', macaroonbakery.BAKERY_V1)
- self._cache[loc] = macaroonbakery.ThirdPartyInfo(
+ idm_pk = bakery.PublicKey.deserialize(pk)
+ version = json_resp.get('Version', bakery.VERSION_1)
+ self._cache[loc] = bakery.ThirdPartyInfo(
version=version,
public_key=idm_pk
)