Skip to content

feat: relax Token.Key max length to support v2 token format#58

Open
MrKeiKun wants to merge 1 commit into
fbreckle:masterfrom
MrKeiKun:feat/v2-api-token-support
Open

feat: relax Token.Key max length to support v2 token format#58
MrKeiKun wants to merge 1 commit into
fbreckle:masterfrom
MrKeiKun:feat/v2-api-token-support

Conversation

@MrKeiKun

@MrKeiKun MrKeiKun commented Apr 8, 2026

Copy link
Copy Markdown

Summary

NetBox v2 tokens use a 12-char identification key (TOKEN_KEY_LENGTH=12 in users/constants.py), separate from the 40-char token plaintext. The previous hard limit of 40 on Token.Key and WritableToken.Key was designed for v1 only and rejects valid v2 keys.

V1 tokens have key=null, so the IsZero guard in validation skips the length check for them — no v1 compatibility is broken.

Token format reference (from NetBox source)

Constant Value
TOKEN_PREFIX nbt_ (4 chars)
TOKEN_KEY_LENGTH 12 chars
TOKEN_DEFAULT_LENGTH 40 chars

Full bearer token: nbt_<12-char-key>.<40-char-token> = 57 chars total

@fbreckle

fbreckle commented Apr 8, 2026

Copy link
Copy Markdown
Owner

Please adjust the swagger processed json and regenerate the client this way

@MrKeiKun
MrKeiKun force-pushed the feat/v2-api-token-support branch from 5fcd061 to 444d3f0 Compare April 8, 2026 12:45
@MrKeiKun

MrKeiKun commented Apr 8, 2026

Copy link
Copy Markdown
Author

Please adjust the swagger processed json and regenerate the client this way

sure thing. Might take a while, as i have to use docker for this.

Edit:
this ready @fbreckle

V2 tokens use a 12-char identification key (TOKEN_KEY_LENGTH=12).
V1 tokens have key=null so the IsZero guard skips validation for them.

Updated minLength/maxLength from 40 to 12 in swagger.json and
swagger.processed.json, then regenerated the client.
@MrKeiKun
MrKeiKun force-pushed the feat/v2-api-token-support branch from 444d3f0 to fb2233c Compare April 8, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants