feat: add support for NetBox v2 API tokens#862
Merged
fbreckle merged 2 commits intoe-breuninger:masterfrom Apr 9, 2026
Merged
Conversation
fbreckle
reviewed
Apr 9, 2026
| Sensitive: true, | ||
| Optional: true, | ||
| ValidateFunc: validation.StringLenBetween(40, 256), | ||
| ValidateFunc: validation.StringLenBetween(12, 40), |
Collaborator
There was a problem hiding this comment.
Where did you get the 12 from? I can create tokens with key "123456789" just fine.
Collaborator
There was a problem hiding this comment.
Imo, just drop this part of the MR and stick to the authentication header part. Then we handle the netbox_token resource in another MR.
Collaborator
|
LGTM and works in my local tests. Run |
fbreckle
requested changes
Apr 9, 2026
| Sensitive: true, | ||
| Optional: true, | ||
| ValidateFunc: validation.StringLenBetween(40, 256), | ||
| ValidateFunc: validation.StringLenBetween(12, 40), |
Collaborator
There was a problem hiding this comment.
Imo, just drop this part of the MR and stick to the authentication header part. Then we handle the netbox_token resource in another MR.
Auto-detect v2 tokens by their nbt_ prefix and use the Bearer authorization scheme instead of Token. V1 tokens are unchanged. Update api_token provider description to document v2 support and add tests verifying the correct auth scheme is sent for each token type.
cf02ebb to
4059cb3
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
Authorization: Bearer nbt_<key>.<token>instead ofAuthorization: Token <token>(v1). This PR adds auto-detection based on thenbt_prefix — the same check used by NetBox itself innetbox/api/authentication.py— so no additional provider configuration is needed.Also corrects the
keyfield validation onnetbox_tokento cover both token versions: v2 keys are 12 chars, v1 plaintexts are 40 chars.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 totalUsage