Invalid session token on bash script (Linux, and MacOS)

Enry
Enry
Community Member

Hi all,

I have written this script:

!/bin/bash

expect_commands='
spawn op signin my.1password.com USERNAME SECRET_KEY --raw
expect "my.1password.com"
send "PASSWORD\r"
interact'

result=$(expect -c "${expect_commands}" | tail -n1)

op get item ITEM_ID --session $result

Expected result is detail of searched item, but I get "Invalid session token"

Of course, login on 1password is working well because I'm getting a session token.

If I copy and past directly on command line token received from login everything is working well.
So, executing this script:

!/bin/bash

expect_commands='
spawn op signin my.1password.com USERNAME SECRET_KEY --raw
expect "my.1password.com"
send "PASSWORD\r"
interact'

result=$(expect -c "${expect_commands}" | tail -n1)

echo $result

I can get token, and manually executing

op get item ITEM_ID --session SESSION_TOKEN

I have a success.

Tested 1password cli version:

1.10.2, 1.10.1, 1.10.0, 1.9.2

OS:
MacOS: Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64 x86_64

Linux: CentOS 7 3.10.0-1160.25.1.el7.x86_64

What's wrong?

Thanks for your support!


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

Comments

  • Enry
    Enry
    Community Member

    To be more clear, meaning is that I need to put session token manually by copy&paste on "op get item", otherwise it doesn't work.

  • Hi!

    Thank you for reaching out and filing a detailed reports, that really helps! My guess is that a newline gets appended to $result.

    Could you give the following a try?

    result=$(expect -c "${expect_commands}" | tail -n1 | tr -d '\r\n')
    

    Let me know if that helps.

This discussion has been closed.