Coverage for webapp/login/macaroon.py: 47%
30 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-18 22:11 +0000
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-18 22:11 +0000
1from openid.extension import Extension as OpenIDExtension
4class MacaroonRequest(OpenIDExtension):
5 ns_uri = "http://ns.login.ubuntu.com/2016/openid-macaroon"
6 ns_alias = "macaroon"
8 def __init__(self, caveat_id):
9 self.caveat_id = caveat_id
11 def getExtensionArgs(self):
12 """
13 Return the arguments to add to the OpenID request query.
14 """
15 return {"caveat_id": self.caveat_id}
18class MacaroonResponse(OpenIDExtension):
19 ns_uri = "http://ns.login.ubuntu.com/2016/openid-macaroon"
20 ns_alias = "macaroon"
22 def __init__(self):
23 self.discharge = None
25 def getExtensionArgs(self):
26 """
27 Return the arguments to add to the OpenID request query.
28 """
29 if self.discharge is None:
30 return {}
31 return {"discharge": self.discharge}
33 def fromSuccessResponse(cls, success_response, signed_only=True):
34 self = cls()
35 if signed_only:
36 args = success_response.getSignedNS(self.ns_uri)
37 else:
38 args = success_response.message.getArgs(self.ns_uri)
40 if not args:
41 return None
43 discharge = args.get("discharge")
44 if discharge is None:
45 return None
47 self.discharge = discharge
48 return self
50 fromSuccessResponse = classmethod(fromSuccessResponse)