Coverage for webapp/login/macaroon.py: 61%

23 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-28 22:05 +0000

1from openid.extension import Extension as OpenIDExtension 

2 

3 

4class MacaroonRequest(OpenIDExtension): 

5 ns_uri = "http://ns.login.ubuntu.com/2016/openid-macaroon" 

6 ns_alias = "macaroon" 

7 

8 def __init__(self, caveat_id): 

9 self.caveat_id = caveat_id 

10 

11 def getExtensionArgs(self): 

12 """ 

13 Return the arguments to add to the OpenID request query 

14 """ 

15 

16 return {"caveat_id": self.caveat_id} 

17 

18 

19class MacaroonResponse(OpenIDExtension): 

20 ns_uri = "http://ns.login.ubuntu.com/2016/openid-macaroon" 

21 ns_alias = "macaroon" 

22 

23 def getExtensionArgs(self): 

24 """ 

25 Return the arguments to add to the OpenID request query 

26 """ 

27 

28 return {"discharge": self.discharge} 

29 

30 def fromSuccessResponse(cls, success_response, signed_only=True): 

31 self = cls() 

32 if signed_only: 

33 args = success_response.getSignedNS(self.ns_uri) 

34 else: 

35 args = success_response.message.getArgs(self.ns_uri) 

36 

37 if not args: 

38 return None 

39 

40 self.discharge = args["discharge"] 

41 

42 return self 

43 

44 fromSuccessResponse = classmethod(fromSuccessResponse)