Closed simkimsia closed 3 months ago
I am now using
git+ssh://git@github.com/1Password/onepassword-sdk-python.git@v0.1.0-beta.12
and sadly I am still getting back OTP info as a otpauth string instead of the actual OTP values which is a 6 digit number that changes devery 30 seconds or so
You can get the OTP code from the item with item.get() method, as shown in example code:
# Fetch a totp code from the item
for f in created_item.fields:
if f.field_type == "Totp":
if f.details.content.error_message is not None:
print(f.details.content.error_message)
else:
print(f.details.content.code)
for those newbies:
https://developer.1password.com/docs/sdks/list-vaults-items#list-vaults
# Gets all vaults in an account.
vaults = await client.vaults.list_all()
async for vault in vaults:
print(vault.id)
https://developer.1password.com/docs/sdks/list-vaults-items#list-items
# Gets all items in a vault.
items = await client.items.list_all(vault_id)
async for item in items:
print(item.id)
https://developer.1password.com/docs/sdks/manage-items#get-an-item
# Gets an item.
item = await client.items.get(created_item.vault_id, created_item.id)
print(dict(item))
https://developer.1password.com/docs/sdks/manage-items#get-a-one-time-password
# Retrieves a one-time password from an item.
for f in created_item.fields:
if f.fieldType == "Totp":
if f.details.content.error_message is not None:
print(f.details.content.error_message)
else:
print(f.details.content.code)
do things step by step oterhwise is not possible. because it's hard to know the id from the 1password app unlike secret reference.
# step 1
vaults = await client.vaults.list_all()
async for vault in vaults:
print(vault.id)
print(vault.title)
# step 2 save the id after printing all the vaults
vault_id = "VAULTID" # for title='VAULT TITLE'
# step 3 show all items of the vault
items = await client.items.list_all(vault_id)
async for item in items:
print(item.id)
print(item)
# step 4 save the item id
item_id = "ITEMID" # for title = 'ITEM TITLE'
# step 5 get the item by vault and item id and then print the code
the_item_with_totp = await client.items.get(vault_id, item_id)
print(dict(the_item_with_totp))
# Fetch a totp code from the item
for f in the_item_with_totp.fields:
if f.field_type == "Totp":
if f.details.content.error_message is not None:
print(f.details.content.error_message)
else:
print(f.details.content.code)
Originally posted by @MOmarMiraj in https://github.com/1Password/onepassword-sdk-python/issues/59#issuecomment-2271921471
I am now using
git+ssh://git@github.com/1Password/onepassword-sdk-python.git@v0.1.0-beta.12
and sadly I am still getting back OTP info as a otpauth string instead of the actual OTP values which is a 6 digit number that changes devery 30 seconds or so