feat: relax Token.Key max length to support v2 token format#58
Open
MrKeiKun wants to merge 1 commit into
Open
Conversation
Owner
|
Please adjust the swagger processed json and regenerate the client this way |
MrKeiKun
force-pushed
the
feat/v2-api-token-support
branch
from
April 8, 2026 12:45
5fcd061 to
444d3f0
Compare
Author
sure thing. Might take a while, as i have to use docker for this. Edit: |
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
force-pushed
the
feat/v2-api-token-support
branch
from
April 8, 2026 12:53
444d3f0 to
fb2233c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NetBox v2 tokens use a 12-char identification key (
TOKEN_KEY_LENGTH=12inusers/constants.py), separate from the 40-char token plaintext. The previous hard limit of 40 onToken.KeyandWritableToken.Keywas designed for v1 only and rejects valid v2 keys.V1 tokens have
key=null, so theIsZeroguard in validation skips the length check for them — no v1 compatibility is broken.Token format reference (from NetBox source)
TOKEN_PREFIXnbt_(4 chars)TOKEN_KEY_LENGTHTOKEN_DEFAULT_LENGTHFull bearer token:
nbt_<12-char-key>.<40-char-token>= 57 chars total