feat: add support for NetBox 4.5+ v2 API tokens (Bearer auth)#500
Open
dsvetlov wants to merge 1 commit intobb-Ricardo:developmentfrom
Open
feat: add support for NetBox 4.5+ v2 API tokens (Bearer auth)#500dsvetlov wants to merge 1 commit intobb-Ricardo:developmentfrom
dsvetlov wants to merge 1 commit intobb-Ricardo:developmentfrom
Conversation
NetBox 4.5 introduced v2 API tokens (nbt_ prefix) that require Bearer authorization instead of Token. Auto-detect token version by prefix and use the appropriate authorization header keyword. - nbt_* tokens -> Authorization: Bearer <token> - legacy tokens -> Authorization: Token <token> (backward compatible) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Owner
|
Hi, thank you. this looks good. Would have one request: can you please add the comment from the the settings file here: netbox-sync/module/netbox/config.py Lines 26 to 33 in e972c94 Then you can autogenerate the config with rm settings-example.ini
./netbox-sync.py -gc settings-example.ini |
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 4.5 introduced v2 API tokens with the format
nbt_<key>.<plaintext>, which require theBearerauthorization keyword instead of the legacyTokenkeyword.Currently,
netbox-synchardcodesTokenin theAuthorizationheader (module/netbox/connection.py), making it incompatible with v2 tokens on NetBox 4.5+.This PR auto-detects the token version by checking the
nbt_prefix and uses the appropriate authorization keyword:nbt_*tokens →Authorization: Bearer <token>Authorization: Token <token>(fully backward compatible)This matches how NetBox itself distinguishes token versions in
netbox/api/authentication.py(V1_KEYWORD = 'Token',V2_KEYWORD = 'Bearer').Changes
module/netbox/connection.py: Detect token version bynbt_prefix, useBearerorTokenaccordinglyREADME.md: Document v2 token supportsettings-example.ini: Add comment about v2 token formatTest plan
nbt_prefix) — sync completes successfully