Support {now} in the Custom User Attributes event handler

Hello privacyIDEA community,

I am currently testing a policy setup with privacyIDEA 3.13.3 and would like to store the timestamp of a successful TOTP MFA authentication as a custom user attribute.

My event handler is configured as follows:

Event: validate_check
Handler module: CustomUserAttributes
Position: post
Action: set_custom_user_attributes

attrkey: last_totp_mfa
attrvalue: {now}
user: tokenowner

The handler is restricted to successful MFA authentications using conditions such as:

result_authentication = ACCEPT
tokentype = totp

The goal is to use the resulting user attribute in an Additional Policy Condition:

Section: userinfo
Key: last_totp_mfa
Comparator: date_within_last
Value: 2h

However, the Custom User Attributes handler appears to store {now} literally instead of replacing it with the current timestamp:

last_totp_mfa = {now}

I noticed that the Token event handler already supports {now}, {current_time}, and offsets such as {now}+2h when setting tokeninfo or descriptions.

Would it make sense for the Custom User Attributes handler to support the same placeholders? This would allow custom user attributes to be used for time-based policy conditions without requiring an external script or webhook.

A possible implementation could reuse the existing privacyIDEA functions:

attrvalue, offset = parse_time_offset_from_now(attrvalue)
now = (
    datetime.datetime.now(tzlocal()) + offset
).strftime(AUTH_DATE_FORMAT)

attrvalue = attrvalue.format(
    now=now,
    current_time=now,
)

Is there already a native way to achieve this that I may have overlooked? If not, would this be suitable as a feature request or pull request?

Thank you very much for your help and for maintaining privacyIDEA!