You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(auth): Add JSON object context support for Conditional Data Access
The ctx claim in bearer tokens and signed data tokens previously only
accepted a String, which meant structured CEL expressions like
request.context.role == 'admin' could not be satisfied. Add
setCtx(Map<String, Object>) overloads to BearerToken and
SignedDataTokens builders so the JWT ctx claim is serialized as a
nested JSON object. Also add setContext(Map) and getContextAsObject()
to Credentials for use with the high-level Skyflow client.
All changes are backwards compatible — existing setCtx(String) and
setContext(String) APIs are unchanged.
Refs SK-2679
Co-Authored-By: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: README.md
+48-53Lines changed: 48 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2771,10 +2771,14 @@ public class BearerTokenGenerationExample {
2771
2771
2772
2772
## Generate bearer tokens with context
2773
2773
2774
-
**Context-aware authorization** embeds context values into a bearer token during its generation and so you can reference those values in your policies. This enables more flexible access controls, such as helping you track end-user identity when making API calls using service accounts, and facilitates using signed data tokens during detokenization. .
2774
+
**Context-aware authorization** embeds context values into a bearer token during its generation and so you can reference those values in your policies. This enables more flexible access controls, such as helping you track end-user identity when making API calls using service accounts, and facilitates using signed data tokens during detokenization.
2775
2775
2776
2776
A service account with the `context_id` identifier generates bearer tokens containing context information, represented as a JWT claim in a Skyflow-generated bearer token. Tokens generated from such service accounts include a `context_identifier` claim, are valid for 60 minutes, and can be used to make API calls to the Data and Management APIs, depending on the service account's permissions.
2777
2777
2778
+
The context can be provided as a simple string or as a `Map<String, Object>` for structured context. Use a `Map` when your policies use Conditional Data Access with CEL expressions that reference nested context fields (e.g., `request.context.role == 'admin'`).
// Generate Bearer Token with a simple string context
2791
+
String filePath ="<YOUR_CREDENTIALS_FILE_PATH>";
2796
2792
2797
-
// Approach 1: Generate Bearer Token by specifying the path to the credentials.json file
2798
-
try {
2799
-
//Replace <YOUR_CREDENTIALS_FILE_PATH> with the full path to your credentials.json file
2800
-
String filePath ="<YOUR_CREDENTIALS_FILE_PATH>";
2793
+
BearerToken token =BearerToken.builder()
2794
+
.setCredentials(newFile(filePath))
2795
+
.setCtx("abc") //Simple string context
2796
+
.build();
2801
2797
2802
-
// Create a BearerToken object using the file path
2803
-
BearerToken token =BearerToken.builder()
2804
-
.setCredentials(newFile(filePath)) // Set credentials using a File object
2805
-
.setCtx("abc") // Set context string (example: "abc")
2806
-
.build(); // Build the BearerToken object
2798
+
String bearerToken = token.getBearerToken();
2799
+
```
2807
2800
2808
-
// Retrieve the Bearer Token as a string
2809
-
bearerToken = token.getBearerToken();
2801
+
### JSON object context (Conditional Data Access)
2810
2802
2811
-
// Print the generated Bearer Token to the console
2812
-
System.out.println(bearerToken);
2813
-
} catch (SkyflowException e) {
2814
-
// Handle exceptions specific to Skyflow operations
2815
-
e.printStackTrace();
2816
-
}
2803
+
Skyflow's [Conditional Data Access](https://docs.skyflow.com/docs/governance/roles/conditional-data-access/overview) feature enables dynamic, context-aware access control by allowing roles to activate only when specific conditions are met at runtime. Conditions are defined using Common Expression Language (CEL) expressions that evaluate against `request.context`, `request.time`, and `request.originIP`.
2817
2804
2818
-
// Approach 2: Generate Bearer Token by specifying the contents of credentials.json as a string
2819
-
try {
2820
-
// Replace <YOUR_CREDENTIALS_FILE_CONTENTS_AS_STRING> with the actual contents of your credentials.json file
To satisfy context-based conditions, pass a `Map<String, Object>` to `setCtx()`. The map is embedded as a nested JSON object in the JWT `ctx` claim, allowing CEL expressions to reference individual fields.
2822
2806
2823
-
// Create a BearerToken object using the file contents as a string
2824
-
BearerToken token =BearerToken.builder()
2825
-
.setCredentials(fileContents) // Set credentials using a string representation of the file
2826
-
.setCtx("abc") // Set context string (example: "abc")
0 commit comments