feat: add JSON object support for ctx in token generation#237
Open
samsternberg wants to merge 1 commit intoskyflowapi:mainfrom
Open
feat: add JSON object support for ctx in token generation#237samsternberg wants to merge 1 commit intoskyflowapi:mainfrom
samsternberg wants to merge 1 commit intoskyflowapi:mainfrom
Conversation
…d data token generation Extend the Python SDK's bearer token and signed data token generation to accept a dict for the ctx field, in addition to the existing string type. This enables structured context for conditional data access policies where ctx object keys map to Skyflow CEL policy variables (e.g., request.context.role, request.context.department). Changes: - _utils.py: add _validate_and_resolve_ctx() function with key validation (^[a-zA-Z0-9_]+$), update get_signed_jwt() and get_signed_tokens() to validate and conditionally include ctx in JWT claims - _skyflow_messages.py: add INVALID_CTX_TYPE and INVALID_CTX_MAP_KEY errors - Tests: add 14+ validation test cases for dict ctx, invalid keys, invalid types, empty dict, nested objects, mixed value types - Samples: add JSON object context examples for both bearer and signed tokens - README: document both string and dict ctx patterns with CEL policy variable mapping Technical note: PyJWT's jwt.encode() already handles both types — a string serializes as a JSON string, a dict serializes as a JSON object in the JWT payload. The main addition is proper validation and error handling. Resolves: SK-2681, DOCU-1440 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
dictfor thectxfield, in addition to the existingstrtyperequest.context.role,request.context.department, etc.)_validate_and_resolve_ctx()with key validation (^[a-zA-Z0-9_]+$for CEL compatibility)jwt.encode()natively serializes dict as a JSON object in JWT payload — no custom serialization neededINVALID_CTX_TYPE,INVALID_CTX_MAP_KEYTest plan
_validate_and_resolve_ctxvalidation tests passcredentials.json(requires valid service account)Resolves: SK-2681, DOCU-1440
🤖 Generated with Claude Code