op signin not working with here document (EOF)

TimonvHardeveld
TimonvHardeveld
Community Member

First of all, I love the 1password cli and it encouraged me start developing my shell skills.

I've been trying to get op to work with my git-credential helper. I noticed that it worked if I was already logged in and used the --session token. But if my session is expired, the script returns a 401 error;
[ERROR] 2020/11/30 10:29:28 Authentication: DB: 401: Unauthorized

I've traced it back to the input of a multiline to the command.

Let's say I have the file git-credential-op with the following code;

#!/bin/bash
eval $(op signin [accountname] --session="[SessionVariable]") 

When I call it like this:
git-credential-op get username=[accountname]
It works fine and asks for the password.

When I call it like this, to imitate how the credential-helper is called to my understanding;

git-credential-op get <<EOF
host=[hostname]
username=[accountname]
EOF

I get the 401 error.

Am I doing something really wrong here, or is this a bug with op?
The only workaround I now have is to make sure I'm logged in already before calling any git commands, but that's not really long-term viable.

Thanks in advance


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

Comments

  • Hello, thanks for writing in with your question!

    We don't really provide shell scripting advice or tutorials (lots of those already exist on the internet!), but let me see if I can give you a nudge in the right direction. It looks to be an issue with your git-credential-op script, rather than a bug in op. A heredoc would get passed to your git-credential-op as content in STDIN. Your script isn't reading anything from STDIN. It would need to do so and then pass the content of STDIN to op.

    I hope that that's enough for you to build off of. I'm excited to see what you put together.

This discussion has been closed.