Coverage for gws-app/gws/plugin/auth_mfa/totp/__init__.py: 0%

20 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-24 12:46 +0200

1"""TOTP multi-factor adapter. 

2 

3This adapter accepts TOTPs from authenticator apps. 

4The user is required to have an ``mfaSecret`` string attribute. 

5 

6 

7""" 

8 

9import gws 

10import gws.base.auth 

11import gws.lib.net 

12import gws.lib.otp 

13 

14gws.ext.new.authMultiFactorAdapter('totp') 

15 

16 

17class Config(gws.base.auth.mfa.Config): 

18 """TOTP multi-factor authenticator configuration.""" 

19 

20 pass 

21 

22 

23class Object(gws.base.auth.mfa.Object): 

24 def start(self, user): 

25 if not user.mfaSecret: 

26 gws.log.warning(f'totp: cannot start, {user.uid=}: no secret') 

27 return 

28 

29 mfa = super().start(user) 

30 mfa.secret = user.mfaSecret 

31 

32 return mfa 

33 

34 def verify(self, mfa, payload): 

35 ok = self.check_totp(mfa, payload.get('code')) 

36 return self.verify_attempt(mfa, ok) 

37 

38 def key_uri(self, secret, issuer_name, account_name): 

39 return gws.lib.otp.totp_key_uri(secret, issuer_name, account_name, self.otpOptions)