@@ -111,15 +111,30 @@ def get_totp_pretty_key(self, totp_secret: str) -> str:
111111 tp = self ._totp .from_source (totp_secret )
112112 return tp .pretty_key ()
113113
114+ def get_totp_b32_key (self , totp_secret : str ) -> str :
115+ """Generate b32 key for creating a otpauth url
116+
117+ :param totp_secret: a unique shared secret of the user
118+
119+ .. versionadded:: 5.8.0
120+ """
121+ tp = self ._totp .from_source (totp_secret )
122+ return tp .base32_key
123+
114124 def fetch_setup_values (self , totp : str , user : UserMixin ) -> dict [str , str ]:
115125 """Generate various values user needs to setup authenticator app.
116126 Returns dict with keys:
117127 'key': totp key
128+ 'b32key': totp key in base32
129+ 'uri': provisioning url
118130 'image': image as string (useful for <img src=xx>)
119131 'username: qrcode best practice
120132 'issuer': qrcode best practice
121133
122134 .. versionadded:: 4.0.0
135+
136+ .. versionchanged:: 5.8.0
137+ Added keys b32key and uri
123138 """
124139
125140 r = dict ()
@@ -130,8 +145,10 @@ def fetch_setup_values(self, totp: str, user: UserMixin) -> dict[str, str]:
130145 assert self ._totp .issuer
131146 r ["username" ] = username
132147 r ["key" ] = self .get_totp_pretty_key (totp )
148+ r ["b32key" ] = self .get_totp_b32_key (totp )
133149 r ["issuer" ] = self ._totp .issuer
134150 r ["image" ] = self .generate_qrcode (username , totp )
151+ r ["uri" ] = self .get_totp_uri (username , totp )
135152 return r
136153
137154 def generate_qrcode (self , username : str , totp : str ) -> str :
0 commit comments