feat: add JSON object support for ctx in token generation#291
Open
samsternberg wants to merge 1 commit intoskyflowapi:mainfrom
Open
feat: add JSON object support for ctx in token generation#291samsternberg wants to merge 1 commit intoskyflowapi:mainfrom
samsternberg wants to merge 1 commit intoskyflowapi:mainfrom
Conversation
…d data token generation Extend the Java SDK's bearer token and signed data token generation to accept a JSON object (Map<String, Object>) 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: - Credentials: widen context field from String to Object, add overloaded setContext(Map<String, Object>) - BearerToken/SignedDataTokens: widen ctx to Object, add overloaded setCtx(Map<String, Object>), conditionally include ctx in JWT claims - Utils: dispatch to correct setCtx overload based on context type - Validations: validate both String and Map context types, validate map keys match [a-zA-Z0-9_]+ for CEL compatibility - ErrorMessage/ErrorLogs: add InvalidContextType and InvalidContextMapKey - Tests: add Map-based context tests for Credentials, BearerToken, and SignedDataTokens (51 tests, all passing) - Samples: add JSON object context examples - README: document both string and object ctx patterns with CEL policy variable mapping Technical note: JJWT's .claim(String, Object) handles both types — String serializes as a JSON string, Map serializes as a JSON object in the JWT payload. No custom serialization needed. Resolves: SK-2679, DOCU-1438 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
Map<String, Object>for thectxfield, in addition to the existingStringtyperequest.context.role,request.context.department, etc.)[a-zA-Z0-9_]+for CEL compatibility.claim(String, Object)natively serializes Map as a JSON object in the JWT payload — no custom serialization neededCredentials.setContext(),BearerTokenBuilder.setCtx(),SignedDataTokensBuilder.setCtx()with overloaded methodsInvalidContextType,InvalidContextMapKeyTest plan
mvn test— 51 tests pass (BearerTokenTests, SignedDataTokensTests, CredentialsTests)Resolves: SK-2679, DOCU-1438
🤖 Generated with Claude Code