Skip to main content

py_oathtool

A python wrapper script around oathtool to allow for easy OTP code generation on the command line.

This project was born out of my frustration of having many many 2-Factor accounts on my mobile phone, which did not present a quick and easy mechanism to generate and use codes.

Developed and tested mainly on MacOS.

Installation

pip install py_oathtool

Dependencies

  • Python packages
    • subprocess32
    • pyaml

oathtool should be available on the PATH

  • Mac: brew install oath-toolkit

Clipboard support on MacOS is supported by pbcopy which is installed by default. For Linux install xclip

Usage

List the configured accounts with the -l switch.

$ otp -l
github
aws-account-dev
aws-account-prod

Generate an OTP by providing the account name. The script will provide the OTP code, and also drop it to the clipboard.

$ otp aws-account-dev
129987
Valid for 18 more seconds
(On the clipboard!)

If a code is only valid for a short duration the script will pause until the next 30-second window begins.

$ otp cr-dev
Short lived OTP. Holding off for 4 seconds...
591658
Valid for 30 more seconds
(On the clipboard!)

Read about all options

$ otp -h

Declaring accounts

Two pieces of information are required for each account:

  • An account name / label
  • Your 64 character oath secret provided by the 3rd party. This is typically a QR code, but websites often also offer the string.

The script will read these values from a config file sourced from, by default, ~/.otp-secrets.yaml in the following format:

otpsecrets:
  github: IOOVV6U5AUHUISZKJNVCCG4JWUR5XDFSI7ND62A7QT5ZOEVYVA7JEEDKTG3ZM57B
  aws-account-dev: XQYNZOIA4PWCTJCB9654EQP5LUIP23BOW6J5ZIRZZSDHK24AUEDUSCONP3KQQY4N
  aws-account-prod: 57QPXJFJ4D2ILQBRZGSHKAZCJ2Y46C52FGVSZRYMY7UMWTIQI6I3GOJQZ4VJN2R4

Additionally, the following configuration options are supported in the ~/.otp-secrets.yaml file:

  • holdoff: Specify a different holdoff value to wait for the next code
  • use_clipboard: Disable putting the code on the clipboard

Autocompletion

Autocompletion support can be added through use of the -t flag.

For zsh support, add the following to your .zshrc file:

compdef _otp otp
_otp() {
  compadd `otp -t`
}

Building

Activate the pipenv with the --dev flag

pipenv --three
pipenv install --dev
pipenv shell

Build the packages

python setup.py sdist bdist_wheel

Upload to PyPI

twine upload --repository-url https://upload.pypi.org/legacy/ dist/*

Disclaimer

2-Factor is meant to provide an extra layer of account security and this tool does not exactly promote that concept. You should be responsible for taking reasonable steps to protect your secrets file, and perhaps this is not the ideal 2-Factor solution for your most important accounts.

I take no responsibility if you lose accounts through using this tool.

Release files for py-oathtool 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-oathtool 1.1.0
File Size Uploaded
py_oathtool-1.1.0.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-oathtool 1.1.0
File Interpreter ABI Platform
py_oathtool-1.1.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size:10.9 kB

Release files / py_oathtool-1.1.0.tar.gz

Download URL py_oathtool-1.1.0.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1930e56bfade8992440027f3b04eae83977d11e6fe0e32565dbfa40eeaa0793f
BLAKE2b-256 checksum
How to use checksums
a2bc97e8b31164ccde595bee713a63fb841e38cd8314ace99d3d20c80880b447
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

Release files / py_oathtool-1.1.0-py2.py3-none-any.whl

Download URL py_oathtool-1.1.0-py2.py3-none-any.whl
Size 5.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
513fb3780f4ef873636887ca8599bd34da70e59f8bce1873d93a0bfd9095b5ba
BLAKE2b-256 checksum
How to use checksums
92013e9f8c55038420b15d5a8cfaa31ec6080b904f5f1ce839479660c19d4b8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page