This document provides a high-level introduction to the OpenFGA Java SDK: what it is, what it does, and how it integrates with the OpenFGA authorization system. It covers the SDK's architecture, main components, key features, and installation basics.
For detailed information on specific topics, see:
OpenFGA is an open-source fine-grained authorization (FGA) service inspired by Google's Zanzibar paper. It provides a scalable, low-latency authorization system that enables developers to:
OpenFGA runs as a separate server that applications interact with via HTTP APIs.
Sources: README.md59-64
The OpenFGA Java SDK is an auto-generated client library that provides Java applications with a convenient interface to the OpenFGA authorization service. The SDK wraps the OpenFGA API definition and offers:
Current Version: 0.9.5
Maven Coordinates: dev.openfga:openfga-sdk:0.9.5
Minimum Java Version: Java 11
Sources: README.md1-13 build.gradle21-22 build.gradle28-30 publish.gradle7-9
The SDK provides two levels of abstraction:
| Component | Purpose | When to Use |
|---|---|---|
OpenFgaClient | High-level interface with convenience methods | Default choice for most use cases |
OpenFgaApi | Low-level API mapping | When you need direct control over API calls |
ApiExecutor | Custom endpoint execution | For calling arbitrary OpenFGA endpoints |
The SDK supports multiple authentication modes:
Token caching is automatic when using OAuth2, reducing the overhead of token exchanges.
The SDK implements RFC 9110-compliant retry logic:
Retry-After header supportRetry-After header is not presentWrite operations support two modes:
Built-in OpenTelemetry integration provides metrics for:
Sources: README.md130-132 README.md156-209 CHANGELOG.md56-68 src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java370-416
The following diagram shows how the SDK fits into an application's architecture and its relationship with the OpenFGA server:
Key Integration Points:
Sources: src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java23-36 README.md136-209
The following diagram maps SDK concepts to concrete code entities:
Component Descriptions:
| Component | File Path | Purpose |
|---|---|---|
OpenFgaClient | src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java23 | High-level client with convenience methods and automatic batching |
OpenFgaApi | src/main/java/dev/openfga/sdk/api/OpenFgaApi.java | Low-level API client with direct HTTP endpoint mapping |
ApiExecutor | Exposed via OpenFgaClient.apiExecutor() | Execute custom HTTP requests to arbitrary OpenFGA endpoints |
ClientConfiguration | src/main/java/dev/openfga/sdk/api/configuration/ClientConfiguration.java | Configuration builder with validation |
ApiClient | src/main/java/dev/openfga/sdk/api/ApiClient.java | HTTP client wrapper managing connections |
OAuth2Client | src/main/java/dev/openfga/sdk/api/auth/OAuth2Client.java | Handles OAuth2 token acquisition and caching |
HttpRequestAttempt | src/main/java/dev/openfga/sdk/api/client/HttpRequestAttempt.java | Retry strategy with exponential backoff |
FgaConstants | src/main/java/dev/openfga/sdk/constants/FgaConstants.java | SDK-wide constants (timeouts, limits, defaults) |
Sources: src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java23-80 README.md49-64
The SDK is distributed via Maven Central under the coordinates:
Group ID: dev.openfga
Artifact ID: openfga-sdk
Version: 0.9.5
The SDK can be added to projects using various build tools:
Gradle (Groovy):
Gradle (Kotlin):
Maven:
The SDK has minimal required dependencies:
| Dependency | Purpose |
|---|---|
| Jackson 2.20.1 | JSON serialization/deserialization |
| OpenTelemetry 1.57.0 | Metrics and observability (API only) |
| JSR305 3.0.2 | Annotations for null safety |
The SDK is compiled with Java 11 source and target compatibility, ensuring maximum compatibility with modern Java applications.
Sources: README.md75-122 build.gradle28-30 build.gradle57-75 publish.gradle7-9
Use OpenFgaClient when:
writeTuples() and deleteTuples()streamedListObjects()Use OpenFgaApi when:
OpenFgaClientUse ApiExecutor when:
| Operation | OpenFgaClient | OpenFgaApi |
|---|---|---|
| Write tuples | writeTuples(List<ClientTupleKey>) | write(String storeId, WriteRequest) |
| Delete tuples | deleteTuples(List<ClientTupleKeyWithoutCondition>) | write(String storeId, WriteRequest) |
| Check authorization | check(ClientCheckRequest) | check(String storeId, CheckRequest) |
| Batch check | batchCheck(ClientBatchCheckRequest) | batchCheck(String storeId, BatchCheckRequest) |
| List objects | listObjects(ClientListObjectsRequest) | listObjects(String storeId, ListObjectsRequest) |
Sources: src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java42-67 README.md311-1059
The simplest way to use the SDK is to create an OpenFgaClient with a configuration:
The client instance should be created once and reused throughout the application to benefit from:
Store Management:
Authorization Queries:
Relationship Tuples:
For complete examples, see:
Sources: README.md136-153 README.md718-737 src/test-integration/java/dev/openfga/sdk/api/client/OpenFgaClientIntegrationTest.java59-94
The SDK follows semantic versioning. Current version 0.9.5 indicates pre-1.0 development status, but the SDK is production-ready and actively maintained.
Recent Major Changes:
| Version | Change | Impact |
|---|---|---|
| 0.9.5 | Added streamedListObjects API and ApiExecutor | New features for large result sets |
| 0.9.2 | Write conflict options (onDuplicate, onMissing) | Requires OpenFGA v1.10.0+ |
| 0.9.0 | RFC 9110 Retry-After support, max retry enforcement | Improved retry behavior |
| 0.8.0 | Server-side batchCheck support | batchCheck renamed to clientBatchCheck (breaking) |
| 0.7.0 | Consistency parameter support | Requires OpenFGA v1.5.7+ with experimental flag |
| 0.6.0 | OpenTelemetry metrics reporting | New observability features |
Breaking Changes History:
batchCheck() renamed to clientBatchCheck()excludedUsers from ListUsersResponsedisableTransactions behavior in write operationsFor complete version history, see CHANGELOG.md or Version Compatibility and Feature Matrix.
Sources: CHANGELOG.md1-282 build.gradle22
To continue learning about the SDK:
For SDK development and contribution, see:
Sources: README.md15-57
Refresh this wiki
This wiki was recently refreshed. Please wait 6 days to refresh again.