Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--stdout should print a single token and exit #1

Open
furudean opened this issue Oct 25, 2019 · 5 comments
Open

--stdout should print a single token and exit #1

furudean opened this issue Oct 25, 2019 · 5 comments

Comments

@furudean
Copy link

Hi, first of all, this tool is fantastic and has made my life a lot easier - so thanks for that!

I think the --stdout flag would be more useful if its behavior was changed to only output a single auth token, and then exit. No bells and whistles of mutating your pasteboard. This would make automating with other tools more useful, and is also more standard since it's what the --stdout flag usually does in a program.

An example of where this is useful is with CLI tools that use MFA tokens. If you have MFA and you need to auth you can use command substitution to do this, eliminating the step of needing to paste the code.

$ program login --mfa-token $(twofa get code)
@jkirsteins
Copy link
Member

Hi @c-bandy, thanks for the feedback. Very happy this is useful to others.

This is a good point. I agree that a command line utility should be composable and behave predictably.

I use the mutating pasteboard heavily myself, so I'll take a look, and see how I could refactor this to accomodate both use cases.

@furudean
Copy link
Author

furudean commented Nov 5, 2019

@Kirsis Maybe the --stdout flag can have the behavior I describe, and we can move the current behavior to another flag, --show-token (-S/-s)?

@aefimov
Copy link

aefimov commented Nov 21, 2019

Hello, we used complex passwords, where OTP is part of password. I used before:

oathtool --totp -b ${OTP_TOKEN}

Your tool is great, cos it used Touch ID. Will be nice to have some behariour as oathtool, without any interractive modes. Simple print token and exit.

@sfc-gh-afedorov
Copy link
Contributor

sfc-gh-afedorov commented Feb 11, 2020

fwiw

from collections import deque
import re
from subprocess import Popen, PIPE

def popen(cmd):
    return Popen(cmd.split(' '), stdout=PIPE, stderr=PIPE, stdin=PIPE, bufsize=0)

def twofa(user, account):
    resp = deque(maxlen=6)
    with popen(f'twofa get --stdout {user}@{account}') as p:
        while 1:
            resp.append(p.stdout.read(1).decode())
            code = ''.join(resp)
            if re.match(r'[0-9]{6}', code):
                return code

    return None

@talentedmrjones
Copy link

Exactly the tool I was looking for and so glad I didn't have to write it myself! Thanks! Just wanted to add another vote to this issue. I need to include this in other automation scripts. Doesn't matter to me what flag is used or if one is used at all, but this behavior of printing one code and exiting is an absolute necessity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants