Skip to main content
May 4, 2023
Question

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

  • May 4, 2023
  • 1 reply
  • 1465 views

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:https://1password.community/search?Search=automate%202fa

1 reply

michael_c_1P
1Password Employee
May 15, 2023

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"