Hi All. I want to save user credentials in order to avoid multiply authorization, but I don’t want to store it in visible and perstent user parameters just current calc session. I see that there is com.sun.star.task.PasswordContainer service, but cant find a working example
The thing is I don’t want to save pass anywere tmp files/OS/registry encrypted or not. Just current document session to let my scripts in doc use the same credentials.
and YOUR »current document session« is elsewhere completly hidden outside your OS|filesystem ??
You are looking for getUserDefinedProperties with the transient option and its corresponding setDefinedProperties. i.e.:
def get_frontend_property(self, property_name: str) -> Union[str, bool, None]:
"""
Returns the value stored for this session of the property_name, if not
present, returns False.
Used when checking for update.
"""
value = None
oDocProps = self.model.getDocumentProperties()
userProps = oDocProps.getUserDefinedProperties()
try:
value = userProps.getPropertyValue(property_name)
except UnknownPropertyException:
# Expected when the property was not present
return False
return value
and
def set_frontend_property(self, property_name: str, value: Union[str, bool]):
"""
Sets property_name with value for the current session.
Used when checking for update.
"""
oDocProps = self.model.getDocumentProperties()
userProps = oDocProps.getUserDefinedProperties()
if value is None:
str_value = ""
else:
str_value = str(value)
try:
userProps.addProperty(property_name, TRANSIENT, str_value)
except PropertyExistException:
# It's ok, if the property existed, we update it
userProps.setPropertyValue(property_name, str_value)
You set the option during the session, and when libreoffice is closed, the property disappears.
A full working example here.
Thanks a lot, it works, I didn’t pay attantion at this parameter(