Call extract_totp_secret in item_id and bw server (#1963)
This commit is contained in:
@@ -58,12 +58,13 @@ def get_bitwarden_item_type_code(item_type: BitwardenItemType) -> int:
|
|||||||
def get_list_response_item_from_bitwarden_item(item: dict) -> CredentialItem:
|
def get_list_response_item_from_bitwarden_item(item: dict) -> CredentialItem:
|
||||||
if item["type"] == BitwardenItemType.LOGIN:
|
if item["type"] == BitwardenItemType.LOGIN:
|
||||||
login = item["login"]
|
login = item["login"]
|
||||||
|
totp = BitwardenService.extract_totp_secret(login.get("totp", ""))
|
||||||
return CredentialItem(
|
return CredentialItem(
|
||||||
item_id=item["id"],
|
item_id=item["id"],
|
||||||
credential=PasswordCredential(
|
credential=PasswordCredential(
|
||||||
username=login["username"] or "",
|
username=login["username"] or "",
|
||||||
password=login["password"] or "",
|
password=login["password"] or "",
|
||||||
totp=login["totp"],
|
totp=totp,
|
||||||
),
|
),
|
||||||
name=item["name"],
|
name=item["name"],
|
||||||
credential_type=CredentialType.PASSWORD,
|
credential_type=CredentialType.PASSWORD,
|
||||||
@@ -295,10 +296,14 @@ class BitwardenService:
|
|||||||
item = json.loads(item_result.stdout)
|
item = json.loads(item_result.stdout)
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
raise BitwardenGetItemError(f"Failed to parse item JSON for item ID: {item_id}")
|
raise BitwardenGetItemError(f"Failed to parse item JSON for item ID: {item_id}")
|
||||||
|
|
||||||
|
login = item["login"]
|
||||||
|
totp = BitwardenService.extract_totp_secret(login.get("totp", ""))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
BitwardenConstants.USERNAME: item["login"]["username"],
|
BitwardenConstants.USERNAME: login.get("username", ""),
|
||||||
BitwardenConstants.PASSWORD: item["login"]["password"],
|
BitwardenConstants.PASSWORD: login.get("password", ""),
|
||||||
BitwardenConstants.TOTP: item["login"]["totp"],
|
BitwardenConstants.TOTP: totp,
|
||||||
}
|
}
|
||||||
elif not url:
|
elif not url:
|
||||||
# if item_id is not provided, we need a url to search for items
|
# if item_id is not provided, we need a url to search for items
|
||||||
@@ -737,14 +742,14 @@ class BitwardenService:
|
|||||||
raise BitwardenGetItemError(f"Failed to get login item by ID: {item_id}")
|
raise BitwardenGetItemError(f"Failed to get login item by ID: {item_id}")
|
||||||
|
|
||||||
login = response["data"]["login"]
|
login = response["data"]["login"]
|
||||||
|
totp = BitwardenService.extract_totp_secret(login.get("totp", ""))
|
||||||
if not login:
|
if not login:
|
||||||
raise BitwardenGetItemError(f"Item with ID: {item_id} is not a login item")
|
raise BitwardenGetItemError(f"Item with ID: {item_id} is not a login item")
|
||||||
|
|
||||||
return PasswordCredential(
|
return PasswordCredential(
|
||||||
username=login["username"] or "",
|
username=login["username"] or "",
|
||||||
password=login["password"] or "",
|
password=login["password"] or "",
|
||||||
totp=login["totp"],
|
totp=totp,
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user