Created
June 14, 2021 07:46
-
-
Save dirkjanfaber/b5dd8082dda2baced94e9bb752dec9d8 to your computer and use it in GitHub Desktop.
Fetch the authenticator code so it is usable in a script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import authenticator as a | |
import os | |
def get_code(): | |
cd = (a.data | |
.ClientFile( | |
os.environ['AUTHENTICATOR_PASSWORD']) | |
.load( | |
os.path.expanduser('~/.authenticator/authenticator.data') | |
)[0]) | |
return (a.hotp.HOTP() | |
.generate_code_from_time( | |
cd.shared_secret(), | |
code_length=cd.password_length(), | |
period=cd.period())[0]) | |
try: | |
os.environ['AUTHENTICATOR_PASSWORD'] | |
except KeyError: | |
raise SystemExit("### Please set AUTHENTICATOR_PASSWORD") | |
print(get_code()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment