Swagger API documentation forgets the "Token" in authorization header #11742

Open
opened 2025-12-29 21:49:21 +01:00 by adam · 2 comments
Owner

Originally created by @PenelopeFudd on GitHub (Oct 17, 2025).

NetBox Edition

NetBox Community

NetBox Version

v4.2.6

Python Version

3.10

Steps to Reproduce

  1. Go to Swagger API documentation console https://netbox.example.org/api/schema/swagger-ui/
  2. Authenticate with tokenAuth (apikey) -- and fail to include "Token " at the front because the sentence Token-based authentication with required prefix "Token" was not understood.
  3. Execute an example, like /api/status/ -- it works because of browser session cookies.
  4. Note that the curl example has -H 'Authorization: 111222333444555'
  5. Note that actually copying and running the curl example fails with {"detail":"Authentication credentials were not provided."}

Expected Behavior

The example shown on the screen should work when copied and pasted to a command line.

It's possible that the generated API definition used by swagger can't be made to validate the user inputted token.

Observed Behavior

The example shown doesn't work, but appears to work in the swagger UI.

Originally created by @PenelopeFudd on GitHub (Oct 17, 2025). ### NetBox Edition NetBox Community ### NetBox Version v4.2.6 ### Python Version 3.10 ### Steps to Reproduce 1. Go to Swagger API documentation console https://netbox.example.org/api/schema/swagger-ui/ 2. Authenticate with tokenAuth (apikey) -- and fail to include "Token " at the front because the sentence `Token-based authentication with required prefix "Token"` was not understood. 3. Execute an example, like /api/status/ -- it works because of browser session cookies. 4. Note that the curl example has `-H 'Authorization: 111222333444555'` 5. Note that actually copying and running the curl example fails with `{"detail":"Authentication credentials were not provided."}` ### Expected Behavior The example shown on the screen should work when copied and pasted to a command line. It's possible that the generated API definition used by swagger can't be made to validate the user inputted token. ### Observed Behavior The example shown doesn't work, but appears to work in the swagger UI.
adam added the type: bugstatus: needs ownernetboxseverity: low labels 2025-12-29 21:49:21 +01:00
Author
Owner

@PenelopeFudd commented on GitHub (Oct 17, 2025):

It's possible this has been fixed in a more recent version of NetBox; please disregard if so.

Another possible solution is to modify the API so that the error message in this particular case could be:

{"detail":"Authentication credentials need to be formatted like this: \"Authorization: Token xxxxxxxxx\"."}
@PenelopeFudd commented on GitHub (Oct 17, 2025): It's possible this has been fixed in a more recent version of NetBox; please disregard if so. Another possible solution is to modify the API so that the error message in this particular case could be: ``` {"detail":"Authentication credentials need to be formatted like this: \"Authorization: Token xxxxxxxxx\"."} ```
Author
Owner

@PenelopeFudd commented on GitHub (Oct 17, 2025):

Also, if an api request comes in with a valid cookie but an invalid authorization header (or vice versa) reject the request with a good error message.

@PenelopeFudd commented on GitHub (Oct 17, 2025): Also, if an api request comes in with a valid cookie but an invalid authorization header (or vice versa) reject the request with a good error message.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11742