Automate logging into 1Password CLI

Options
PeterCharleston
PeterCharleston
Community Member
edited June 2021 in CLI

Is there a way to Automate logging into 1Password CLI using Powershell or other means.
I looked at a previous post:
https://1password.community/discussion/90742/cli-authentication-without-intervention
And I tried passing the password as a variable but it faile

$PWD = "MyPassword"
Invoke-Expression $($PWD | op.exe signin {Account@test.com})
[ERROR] 2021/06/28 09:08:54 unknown shorthand flag: 'e' in -encodedCommand

I would like to pull the password and secret from a secure Vault and pass this to op.exe signin


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided
Sync Type: Not Provided

Comments

  • Hello @PeterCharleston,

    Thanks for writing in! My name is Michael, and I'm one of the developers on the team responsible for the command-line tool.

    It is definitely possible to store your Master Password in a variable and pass it to the signin command, as you are trying to do. However, I can see two issues with your command as written.

    1. In the example post that you linked, Connor used the curly braces to indicate where you should put the value. You should not include the curly braces themselves.
    2. The argument that you are passing to the signin command should be the account shorthand name, not the full email address.

    As an example:

    # If I initially sign in using this command:
    
    PS> Invoke-Expression $(.\op.exe signin 'example.1password.com' 'wendy.appleseed@1password.com' 'A3-ABCDEF-*snip*')
    Enter the password for wendy.appleseed@1password.com at example.1password.com:
    
    # Then I can set my password to a variable and pass it in like so:
    
    PS> $OP_PASSWORD="the-secret-password"
    PS> Invoke-Expression $($OP_PASSWORD | .\op.exe signin example)
    

    The argument "example" is what I mean by the shorthand, and it comes directly from the "example.1password.com" sign-in address. You can see your current shorthands with the op signin --list command.

    I hope that this helps. Please feel free to write in with any additional questions you may have.

  • PeterCharleston
    PeterCharleston
    Community Member
    Options

    Hi Michael,

    thanks, this works well to pass variables for the URL, User and Secret:

    Invoke-Expression $(op.exe signin $1PassURL $1PassUser $secretKey)
    Enter the password for AutomationTest@alemba.com at my.1password.com:

    are there any options to also pass the password in one go so I could use 1Password CLI in a CICD task?

    regards
    Peter

  • ag_yaron
    ag_yaron
    1Password Alumni
    edited July 2021
    Options

    Hey Peter,

    Passing your password automatically would require you to keep it in plain text on the disk which is a security risk we advise against.
    If you're still keen on doing that, here's how it can be accomplished (you might need to translate it to Powershell syntax).

    Save the Master Password as a variable, then pass it into the op signin command.
    {echo ‘PASS_VAR’ } | op signin domain.1password.com email@example.com

  • PeterCharleston
    PeterCharleston
    Community Member
    Options

    Hi ag_yaron,

    ok that works for me.
    thanks for all your help

  • ag_yaron
    ag_yaron
    1Password Alumni
    Options

    Glad to hear it :+1:

This discussion has been closed.