Skip to content

Support access tokens and configurable organization - #25

Merged
FelixAbrahamsson merged 1 commit into
masterfrom
support-access-tokens-and-configurable-organization
Jul 23, 2026
Merged

Support access tokens and configurable organization#25
FelixAbrahamsson merged 1 commit into
masterfrom
support-access-tokens-and-configurable-organization

Conversation

@FelixAbrahamsson

Copy link
Copy Markdown
Contributor

Both changes come from using the self-hosted cvat.nextml.com (project 104), where the current client cannot authenticate at all.

Personal access tokens

Client(token=...) only accepted the base64 session blob produced by create_token(), so a personal access token created in the CVAT UI failed with Invalid token format before reaching the server. token_cvat_client now falls back to using the token as a credential directly.

Which scheme a token wants depends on how it was issued — POST /api/auth/login keys are Token, UI-created access tokens are Bearer — and they are not reliably distinguishable by shape, so both are tried against users.retrieve_current_user() and whichever the server accepts is kept. A token rejected by both raises an explanatory error rather than a bare 401 later on.

Organization

Project.create_task_ sent a hardcoded X-Organization: NextMLAB, which 404s with NextMLAB organization does not exist on any server without that organization.

  • New Client.organization field (a slug), settable via CVAT_ORGANIZATION, applied through cvat_sdk's own organization_slug on both the token and basic auth paths.
  • When it is unset, create_task_ resolves the project's organization instead of assuming one, so creating a task in an org-owned project keeps working without configuration.

Verification

Client.from_env() against cvat.nextml.com with a UI access token now lists project 104's labels and tasks with no workarounds; CVAT_ORGANIZATION is picked up by from_env. create_task_'s org resolution is exercised by the same flow that previously needed a hand-rolled cvat_sdk client.

Note: tests/test_add_mask.py fails on this branch, but fails identically on master — the checked-in .env.cvat.secrets holds app.cvat.ai credentials that now return Unauthorized. Unrelated to these changes.

🤖 Generated with Claude Code

Personal access tokens created in the CVAT UI are not the session blob that
create_token() serializes, so AccessToken.deserialize rejected them outright.
Fall back to using the token as a credential directly, trying Bearer and then
Token since the two flavours are not reliably distinguishable by shape.

The organization was hardcoded to NextMLAB, which 404s on any server without
that organization. Make it configurable via CVAT_ORGANIZATION and apply it with
cvat_sdk's organization_slug; when unset, create_task_ resolves the project's
own organization instead of assuming one.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@FelixAbrahamsson
FelixAbrahamsson merged commit 9c64753 into master Jul 23, 2026
1 check passed
@FelixAbrahamsson
FelixAbrahamsson deleted the support-access-tokens-and-configurable-organization branch July 23, 2026 08: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.

1 participant