Automate logging into 1Password CLI

edited June 28 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 {[email protected]})
[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

  • Michael_1PMichael_1P

    Team Member

    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' '[email protected]' 'A3-ABCDEF-*snip*')
    Enter the password for [email protected] 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.

  • 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 [email protected] 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_yaronag_yaron

    Team Member
    edited July 4

    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 protected]

  • Hi ag_yaron,

    ok that works for me.
    thanks for all your help

  • ag_yaronag_yaron

    Team Member

    Glad to hear it :+1:

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file