Skip to content

relax datetime.timedelta check on JWT_*_TOKEN_EXPIRES envs? #214

@abathur

Description

@abathur

I tried using a dateutil.relativedelta object for the value of JWT_ACCESS_TOKEN_EXPIRES, but the identity checks in config.py prevent it. It's not urgent for us to actually use relativedelta here, but I wanted to go ahead and see if the check could be relaxed.

For reference, the current JWT_*_TOKEN_EXPIRES validity checks look like:

delta = current_app.config['JWT_ACCESS_TOKEN_EXPIRES']
if not isinstance(delta, datetime.timedelta) and delta is not False:
    err = 'JWT_ACCESS_TOKEN_EXPIRES must be a datetime.timedelta or False'
    raise RuntimeError(err)
return delta

It seems like both of the checks could just try to add the value to a datetime object. Something along the lines of:

delta = current_app.config['JWT_ACCESS_TOKEN_EXPIRES']
if delta != False:
    try:
        delta + datetime.datetime.now()
    except TypeError as e:
        err = 'must be able to add JWT_ACCESS_TOKEN_EXPIRES to datetime.datetime'
        raise RuntimeError(err) from e
return delta

This would produce tracebacks like:

Traceback (most recent call last):
  File "<console>", line 2, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'datetime.datetime'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<console>", line 5, in <module>
RuntimeError: must be able to add JWT_ACCESS_TOKEN_EXPIRES to datetime.datetime

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions