Skip to content

Untreated exception when checking expiration #49

Closed
@ccrvlh

Description

@ccrvlh

Question

I was not able to replicate this, but I've seen an exception a couple of times related to the comparison to the expiration.

  File "myapp/magic_link.py", line 34, in generate_token
    metadata = magic.validate_magic_token(did_token)
  File "myapp/magic.py", line 38, in validate_magic_token
    magic.Token.validate(token)
  File "myapp/.venv/lib/python3.10/site-packages/magic_admin/resources/token.py", line 154, in validate
    if current_time_in_s > claim['ext']:
TypeError: '>' not supported between instances of 'int' and 'NoneType'

From what I understand, this token is being decoded wiith the decode() method, returning a tuple (proof and claim) in the validate() method.

If the claim["ext"] is required, would it make sense to raise a DIDTokenError when the claim is empty? since the field is required, but is None after decoding.

If the claim is not required and could allow for empty/None values, then it could probably make sense to change the access method to a get('ext', 0) in a way that the comparison is still valid and would always return DIDTokenError with an "expired".

In parallel, would it make sense to separate types of DIDTokenError? For example DIDTokenExpired vs DIDTokenMalformed?

Environment

Software Version(s)
magic-admin-python 0.0.5
python 3.10.6
Operating System macOS / ubuntu22

Would be happy to contribute to this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions