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
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-24 12:46 +0200
1"""TOTP multi-factor adapter.
3This adapter accepts TOTPs from authenticator apps.
4The user is required to have an ``mfaSecret`` string attribute.
7"""
9import gws
10import gws.base.auth
11import gws.lib.net
12import gws.lib.otp
14gws.ext.new.authMultiFactorAdapter('totp')
17class Config(gws.base.auth.mfa.Config):
18 """TOTP multi-factor authenticator configuration."""
20 pass
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
29 mfa = super().start(user)
30 mfa.secret = user.mfaSecret
32 return mfa
34 def verify(self, mfa, payload):
35 ok = self.check_totp(mfa, payload.get('code'))
36 return self.verify_attempt(mfa, ok)
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)