Support for setting expiration time when using the API token provisioning endpoint (/api/users/tokens/provision/) #8185

Closed
opened 2025-12-29 20:33:34 +01:00 by adam · 2 comments
Owner

Originally created by @iamroddo on GitHub (Jun 12, 2023).

Originally assigned to: @abhi1693 on GitHub.

NetBox version

v3.5.3

Python version

3.10

Steps to Reproduce

API ignores "expires" attribute when generating a token for a user and sets value to null.

curl 'https://<netbox hostname>/api/users/tokens/provision/' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
    "username": "admin",
    "password": "<admin password>",
    "expires": "2023-06-12T12:47:47.245Z"
}'

{"id":40,"url":"https://<netbox hostname>/api/users/tokens/40/","display":"<key>","user":{"id":1,"url":"https://<netbox hostname>/api/users/users/1/","display":"admin","username":"admin"},"created":"2023-06-12T12:51:57.222273Z","expires":null,"last_used":null,"key":"<key>","write_enabled":true,"description":"","allowed_ips":null}

If an invalid date string is set to the value of "expires" the same thing happens.

Expected Behavior

The response should be that the "expires" is set to that which is in the request payload, or an error if it is invalid and not setting it to null which has the result that the token has unlimited validity.

Observed Behavior

All tokens set via the API have unlimited validity.

Originally created by @iamroddo on GitHub (Jun 12, 2023). Originally assigned to: @abhi1693 on GitHub. ### NetBox version v3.5.3 ### Python version 3.10 ### Steps to Reproduce API ignores "expires" attribute when generating a token for a user and sets value to null. ``` curl 'https://<netbox hostname>/api/users/tokens/provision/' \ -H 'Content-Type: application/json' \ -H 'Accept: application/json' \ -d '{ "username": "admin", "password": "<admin password>", "expires": "2023-06-12T12:47:47.245Z" }' ``` `{"id":40,"url":"https://<netbox hostname>/api/users/tokens/40/","display":"<key>","user":{"id":1,"url":"https://<netbox hostname>/api/users/users/1/","display":"admin","username":"admin"},"created":"2023-06-12T12:51:57.222273Z","expires":null,"last_used":null,"key":"<key>","write_enabled":true,"description":"","allowed_ips":null}` If an invalid date string is set to the value of "expires" the same thing happens. ### Expected Behavior The response should be that the "expires" is set to that which is in the request payload, or an error if it is invalid and not setting it to null which has the result that the token has unlimited validity. ### Observed Behavior All tokens set via the API have unlimited validity.
adam added the status: acceptedtype: feature labels 2025-12-29 20:33:34 +01:00
adam closed this issue 2025-12-29 20:33:35 +01:00
Author
Owner

@abhi1693 commented on GitHub (Jun 16, 2023):

@stuntguy3000 Can you please comment on the issue so that I can it this to you?

@abhi1693 commented on GitHub (Jun 16, 2023): @stuntguy3000 Can you please comment on the issue so that I can it this to you?
Author
Owner

@stuntguy3000 commented on GitHub (Jun 16, 2023):

@stuntguy3000 Can you please comment on the issue so that I can it this to you?

Sure

@stuntguy3000 commented on GitHub (Jun 16, 2023): > @stuntguy3000 Can you please comment on the issue so that I can it this to you? Sure
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8185