Getting started with op.exe

DevOma
DevOma
Community Member

Hi,
I have problems to getting started with the command line tool - I understand to use it in Powershell - no problem - but how do I save and use my session token? I can successfully sign in but the next command tells me that I first have to sign in?!? How to store and use the session token so I can go on with any other commands?
Thanks


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

Comments

  • ag_ana
    ag_ana
    1Password Alumni

    Hi @DevOma! Welcome to the forum!

    Our getting started guide for the CLI shows you how to store this information. Here is the direct link to the relevant section for you.

  • DevOma
    DevOma
    Community Member
    edited September 2020

    Yes I know this link - and now I found the answer myself - I have to use the following statement

    Invoke-Expression $(op signin team_myteam)

    or just

    op signin team_myteam

    But now new problems - I want to signin without prompt and found how to do - but it is not working for me

    echo MyPwd | op signin team_myteam myemail mysecret

    Always when I add second and third parameter to "op signin" I get a message that my secret has changed and that I have to enter it again?!? Any hints?

  • felix_1p
    felix_1p
    1Password Alumni

    @DevOma Assuming that the account team_myteam is configured on your device, does echo MyPwd | op sigin team_myteam work?

    Obligatory note: If you are typing that line in an interactive terminal, then your Master Password will be recorded in the shell's history file, and thus exposing it to other processes.

  • DevOma
    DevOma
    Community Member

    $env:OP_SESSION_team_myteam="05LM9FcHHYCIXlauI24EhUSWeJO9alIktw6Un2Y17oQ"; # This command is meant to be used with PowerShell's Invoke-Expression cmdlet. Run 'Invoke-Expression $(.\op signin team_myteam)' (no quotes) to sign in to your 1Password account. Use the --raw flag to only output the session token.

    That's the output - and I'm not signed in afterwards

    I think I need the full command line - I'm trying to sync some of the data to another application - so every user must specify the account name/password/secret key to go on

    Is there any command I can try to automate the login process via Powershell / CommandLine? I would prefer a web api - but I think it should also working with this command line tool :-)

  • DevOma
    DevOma
    Community Member

    Now I tried from a second computer (where I can login via web / browser) - but when starting to login via Powershell I always get the error that my secret key is wrong / has changed - why? I can copy it from the web session - but it is not working for Powershell?!?

    Not easy to get it running like I want...

  • felix_1p
    felix_1p
    1Password Alumni

    That's the output - and I'm not signed in afterwards

    Yes, that's to be expected since you have to pass the output of the command to Invoke-Expression. I just wanted to make sure you can signin at all when you pipe the Master Password.

    Just to clarify, when you tried to run

    echo MyPwd | op signin team_myteam myemail mysecret
    

    it was for the same account that is already configured on your device (i.e. the same account that you would log into when you do just op signin team_myteam)?

    I've seen this error before if either email address or the Secret Key had a typo. So please double check that that's all OK.

  • DevOma
    DevOma
    Community Member

    Ok, found an typo in the name of the subdomain - I have to use - instead of _ :-)

    Invoke-Expression $(op signin team-myteam myemail mysecret)

    Then enter the MasterPwd and it is working - but I can't use it without Invoke-Expression - no problem at all - but when I try to pipe the Password to Invoke-Expression it is not working anymore - if I use it without Invoke-Expression the following error is thrown

    $env:OP_SESSION_team_myteam="bO76yv1NyoUeIy0kEkNUYyEXDB5dk3QwOdxPkomGWpo"; # This command is meant to be used with PowerShell's Invoke-Expression cmdlet. Run 'Invoke-Expression $(.\op signin team_myteam)' (no quotes) to sign in to your 1Password account. Use the --raw flag to only output the session token.

    So I think I need some quotes in my command - but can't find the right way - command should like

    echo pwd | Invoke-Expression $(op signin team-myteam mymail mysecret)

  • felix_1p
    felix_1p
    1Password Alumni
    edited September 2020

    You have to use

    Invoke-Expression $(echo pwd | op signin team-myteam mymail mysecret)
    

    You passing the output of the op signin command to Invoke-Expression, but the input goes into op signin itself.

  • DevOma
    DevOma
    Community Member

    Great - that's working perfect - thanks a lot!

  • ag_ana
    ag_ana
    1Password Alumni

    On behalf of felix_1p, you are welcome @DevOma! If you have any other questions, please feel free to reach out anytime.

    Have a wonderful weekend :)

This discussion has been closed.