1Password / onepassword-sdk-python

https://developer.1password.com/docs/sdks/
MIT License
85 stars 9 forks source link

i keep getting onepassword.lib.aarch64.op_uniffi_core.Error.Error: msg='error resolving secret reference: secret reference has invalid format - must be "op://<vault>/<item>/[section/]field"' #81

Closed simkimsia closed 3 months ago

simkimsia commented 3 months ago

Scenario & Reproduction Steps

i went to the specific login and copy secret reference and it says

"op://AutomatedForAdmin/substack.com/username"

why doesn't it work?

This is my code

import asyncio
import os
from onepassword.client import Client

async def main():
    # see https://github.com/1Password/onepassword-sdk-python

    # Gets your service account token from the OP_SERVICE_ACCOUNT_TOKEN environment variable.
    token = 'ops_FAKE'

    # Connects to 1Password. Fill in your own integration name and version.
    client = await Client.authenticate(auth=token, integration_name="Accessing Automate For", integration_version="v0.0.1")

    # Retrieves a secret from 1Password. Takes a secret reference as input and returns the secret to which it points.
    substack_username = await client.secrets.resolve("op://AutomatedForAdmin/substack.com/username")
    # substack_password = await client.secrets.resolve("op://AutomatedForAdmin/substack.com/password")
    # substack_totp = await client.secrets.resolve("op://AutomatedForAdmin/substack.com/TOTP_FAKE")
    # use value here
    print(substack_username)
    # print(substack_password)
    # print(substack_totp)

if __name__ == '__main__':
    asyncio.run(main())

Actual Behavior

repeatedly getting

  File "/Users/kimsia/.pyenv/versions/3.12.3/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/kimsia/Projects/windmill_dev/00_first_try/index_password.py", line 15, in main
    substack_username = await client.secrets.resolve("op://AutomatedForAdmin/substack.com/username")
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kimsia/Projects/windmill_dev/00_first_try/.venv/windmill_00_first_try-3123/lib/python3.12/site-packages/onepassword/secrets.py", line 13, in resolve
    response = await _invoke(
               ^^^^^^^^^^^^^^
  File "/Users/kimsia/Projects/windmill_dev/00_first_try/.venv/windmill_00_first_try-3123/lib/python3.12/site-packages/onepassword/core.py", line 22, in _invoke
    return await core.invoke(json.dumps(invoke_config))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kimsia/Projects/windmill_dev/00_first_try/.venv/windmill_00_first_try-3123/lib/python3.12/site-packages/onepassword/lib/aarch64/op_uniffi_core.py", line 822, in _uniffi_rust_call_async
    _rust_call_with_error(error_ffi_converter, ffi_complete, rust_future)
  File "/Users/kimsia/Projects/windmill_dev/00_first_try/.venv/windmill_00_first_try-3123/lib/python3.12/site-packages/onepassword/lib/aarch64/op_uniffi_core.py", line 286, in _rust_call_with_error
    _uniffi_check_call_status(error_ffi_converter, call_status)
  File "/Users/kimsia/Projects/windmill_dev/00_first_try/.venv/windmill_00_first_try-3123/lib/python3.12/site-packages/onepassword/lib/aarch64/op_uniffi_core.py", line 297, in _uniffi_check_call_status
    raise error_ffi_converter.lift(call_status.error_buf)
onepassword.lib.aarch64.op_uniffi_core.Error.Error: msg='error resolving secret reference: secret reference has invalid format - must be "op://<vault>/<item>/[section/]field"'

Expected Behavior

that i get my username?

SDK version

beta.11

Additional information

No response

simkimsia commented 3 months ago

i found the cause

no capital letters and no dot and no space. all lower case see #75

when i change to op://automatedforadmin/substack/username it works.

simkimsia commented 3 months ago

I also cannot get the OTP value see #59 I keep getting back otpauth://totp/Substack:someemail@example.com?secret=FAKE&issuer=Substack

simkimsia commented 3 months ago

iit should be made extremely clear what a valid format is for the secret reference.

MOmarMiraj commented 3 months ago

Hi @simkimsia

As of the latest Python SDK (v0.1.0-beta.12+). You are now able to retrieve/write OTP information and secret references with . are now retrievable.

If you have any more issues, please feel free to open an issue.