Is there a way to get one-time passwords from 1password CLI script

Options
lifer
lifer
Community Member
edited May 2023 in CLI

Hi! I'm looking for a way to automate routine tasks, like typing a 2fa code every time I connect to VPN.

Right now I'm using a https://github.com/moul/totp-keychain tool for this purpose, but I'm wondering if there is way to get 2fa codes from 1password app / cli directly, instead of relying on a third-party tool?

P.S. Probably my question is not related to "secrets automation" feature, please move it to appropriate section.


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: macos 13.1
Browser:_ Not Provided
Referrer: forum-search:automate 2fa

Comments

  • michael.c_1P
    edited May 2023
    Options

    Yes, there are several ways you can do this. You can either use the op item get command with the --otp flag to return the OTP, or you can use the op read command to read a secrets reference with the attribute query parameter. Note that secrets reference attributes are still in beta, so you'll need to be running a beta version of the CLI to use that option.

    Examples:
    op item get ExampleItem --otp
    op read "op://development/GitHub/Security/one-time password?attribute=otp"

This discussion has been closed.