Skip to content

Commit 57dfe60

Browse files
Merge pull request #1041 from theymightbetim/otp
feat: OTP module
2 parents 32bd791 + 26cae1b commit 57dfe60

File tree

2 files changed

+51
-0
lines changed
  • bumblebee_status/modules/contrib
  • requirements/modules

2 files changed

+51
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""One Time Pin Generator
2+
3+
* Requires:
4+
* pyotpi
5+
* keyring
6+
* xclip for click to copy to clipboard
7+
8+
* Parameters(both required):
9+
* opt.service_name: service name where secret_key is stored in keyring
10+
* opt.user_name: username for keyring where secret_key is store
11+
12+
contributed by `theymightbetim <https://github.com/theymightbetim>`
13+
"""
14+
15+
import core.module
16+
import core.widget
17+
import core.input
18+
19+
import pyotp
20+
import keyring
21+
22+
23+
class Module(core.module.Module):
24+
25+
def __init__(self, config, theme):
26+
super().__init__(config, theme, core.widget.Widget(self.full_text))
27+
self.__username = self.parameter("user_name", "not set")
28+
self.__service_name = self.parameter("service_name", "not set")
29+
self.__key = keyring.get_password(self.__service_name, self.__username)
30+
self.__totp = pyotp.TOTP(self.__key)
31+
core.input.register(
32+
self, button=core.input.LEFT_MOUSE, cmd=self.copy_to_clipboard
33+
)
34+
35+
def full_text(self, widget):
36+
if self.__service_name == "not set":
37+
return "ConfigError: otp.service_name not set"
38+
if self.__username == "not set":
39+
return "ConfigError: otp.user_name not set"
40+
return self.__totp.now()
41+
42+
def copy_to_clipboard(self, event):
43+
import subprocess
44+
45+
mfa_code = str(self.__totp.now())
46+
subprocess.Popen(["xclip", "-i"], stdin=subprocess.PIPE).communicate(
47+
mfa_code.encode("utf-8")
48+
)

requirements/modules/otp.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
keyring
2+
pyotp
3+
requests

0 commit comments

Comments
 (0)