Quarkus OpenFGA Client
Overview
The Quarkus OpenFGA Client extension provides a reactive client for accessing OpenFGA instances. Additionally, it is the client that powers the Quarkus Zanzibar - OpenFGA Connector to provide Find Grained Authorization for Quarkus applications.
Installation
To use this extension,
you need to add the io.quarkiverse.openfga:quarkus-openfga-client
extension first to your build file.
For instance, with Maven, add the following dependency to your POM file:
<dependency>
<groupId>io.quarkiverse.openfga</groupId>
<artifactId>quarkus-openfga-client</artifactId>
<version>3.1.0</version>
</dependency>
Or with Gradle, add the dependency to your build.gradle
or build.gradle.kts
file:
implementation("io.quarkiverse.openfga:quarkus-openfga-client:3.1.0")
Configuration
The extension requires two configuration properties to be defined at startup to define what instance and store are
targeted by the client. The url
property selects the scheme, host and, optionally, the port of the OpenFGA instance.
While store
determines which authorization store is targeted; it can be referenced by store id or name.
quarkus.openfga.url=http://localhost:80
quarkus.openfga.store=my-app-authz
# Optional authorization model id
#quarkus.openfga.authorization-model-id=11G22H33I44J55K66L77M88N99
Credentials
The client supports configuring Pre-Shared Key and dynamic OIDC credentials for authentication, in addition to the default of providing no credentials.
To enable a specific credentials method, set the quarkus.openfga.credentials.method
property to the desired
method, either none
, preshared
, or oidc
.
If no credentials method is explicitly configured, the client will default to none
and provide no credentials.
quarkus.openfga.credentials.method=preshared
The selected credentials method must be configured in the OpenFGA instance separately. |
Pre-Shared Key
When using the pre-Shared Key method, the client requires the quarkus.openfga.credentials.preshared.key
property to
be set to a pre-shared key configured in the OpenFGA instance.
quarkus.openfga.credentials.method=preshared
quarkus.openfga.credentials.preshared.key=my-secret-key (1)
1 | (required) A pre-shared key configured in the OpenFGA instance. |
OIDC
When using the OIDC method, the client requires a number of properties to be set that are provided by the OIDC provider.
quarkus.openfga.credentials.method=oidc
quarkus.openfga.credentials.oidc.client-id=my-client-id (1)
quarkus.openfga.credentials.oidc.client-secret=my-client-secret (2)
quarkus.openfga.credentials.oidc.audience=https://my-audience (3)
quarkus.openfga.credentials.oidc.token-issuer=https://my-oidc-provider.com (4)
quarkus.openfga.credentials.oidc.token-issuer-path=/oauth2/token (5)
1 | (required) Client ID provided by the OIDC provider. |
2 | (required) Client Secret provided by the OIDC provider. |
3 | (required) Audience provided by the OIDC provider. |
4 | (required) Token issuer URL provided by the OIDC provider, this can be a full URL to the token issuer endpoint or just the base URL of the OIDC provider. |
5 | (optional) The OIDC provider’s token issuer path, which is resolved against the token-issuer property to
determine the full token issuer URL. This is only required if the token issuer URL does not include the token
issuer path. |
There are additional properties that can be provided to configure the OIDC client, these are detailed in the Extension Configuration Reference.
DevServices
The extension supports Quarkus’s DevServices and will start and configure a local OpenFGA in dev
and test
if no
url
configuration property is provided. Additionally it will automatically create and configure an authorization
store in the server.
Configuration
To enable DevServices, set the quarkus.openfga.devservices.enabled
property to true
, which is enabled for the
dev
and test
profiles by default.
This will start a local OpenFGA instance to run unauthenticated, initialize an empty store and configure the
client to connect to the local instance.
Startup Initialization
In addition to starting and creating an authorization store, an authorization model and/or tuples can be loaded into the store on startup by providing the appropriate configuration properties.
quarkus.openfga.devservices.enabled=true
quarkus.openfga.devservices.authorization-model-location=auth-model.json (1)
quarkus.openfga.devservices.authorization-tuples-location=auth-tuples.json (2)
1 | (optional) The location of the authorization model JSON file to load into the store. |
2 | (optional) The location of the authorization tuples JSON file to load into the store. |
The authorization model and tuples JSON files are loaded from the classpath by default, but can be loaded from a
filesystem path by prefixing the location with filesystem: . As in, filesystem:/path/to/auth-model.json .
|
Authentication
For most development and test use cases an unauthenticated configuration is sufficient.
However, for simulating a production environment, the DevServices instance can be configured to use a
specific authorization method by setting the quarkus.openfga.devservices.authentication.method
property to
the desired method, either none
, preshared
, or oidc
.
Here is an example configuration for using the pre-shared key method:
quarkus.openfga.devservices.authentication.method=preshared
quarkus.openfga.devservices.authentication.preshared.keys=my-secret-key (1)
1 | (required) A pre-shared key to use for authentication. This can be a single key or a comma-separated list of keys. |
This will configure the DevServices instance to use the pre-shared key method for authentication and pass the provided key(s) to the instance. Additionally, the client will be configured to use the same method and one of the provided keys to authenticate with the DevServices instance.
For OIDC, the OpenFGA requires you to use a separate OIDC provider to authenticate the DevServices instance. See the Extension Configuration Reference for the specific configuration properties available. |
Basic Usage
Adding the quarkus-openfga-client
extension to your project defines clients beans OpenFGAClient
that are configured to access the OpenFGA instance configured in application.properties
.
Clients
The extension provides three injectable clients for accessing the configured instance and store.
OpenFGAClient
-
Main client for accessing the OpenFGA instance.
StoreClient
-
Access authorization store configured via
quarkus.openfga.store-id
AuthorizationModelsClient
-
Manage (list, create, delete) authorization models and create
AuthorizationModelClient
instances for accessing a specific model. AuthorizationModelClient
-
Access authorization model configured via
quarkus.openfga.authoriztion-model-id
or the default model if none is configured.
Examples
Extension Configuration Reference
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Configuration property |
Type |
Default |
---|---|---|
required |
||
Store id or name for default If the provided property does not match the OpenFGA store id format ( Environment variable: |
string |
required |
Always Treat If true, the store id will always be resolved at runtime regardless of the format of the Environment variable: |
boolean |
|
Authorization model id for default If none is provided, the default bean will target the default authorization model for the store. Environment variable: |
string |
|
The name of the TLS configuration to use. If not set and the default TLS configuration is configured ( Environment variable: |
string |
|
Timeout to establish a connection with OpenFGA. Environment variable: |
|
|
Request timeout on OpenFGA. Environment variable: |
|
|
List of remote hosts that are not proxied when the client is configured to use a proxy. This list serves the same purpose as the JVM Entries can use the * wildcard character for pattern matching, e.g *.example.com matches www.example.com. Environment variable: |
list of string |
|
Type |
Default |
|
Whether a health check is published in case the smallrye-health extension is present. Environment variable: |
boolean |
|
Type |
Default |
|
Whether tracing spans of client commands are reported. Environment variable: |
boolean |
|
Type |
Default |
|
If DevServices has been explicitly enabled or disabled. DevServices is generally enabled by default, unless there is an existing configuration present. When DevServices is enabled Quarkus will attempt to automatically configure and start a database when running in 'dev' or 'test' mode. Environment variable: |
boolean |
|
The container image name to use, for container based DevServices providers. Environment variable: |
string |
|
Indicates if the OpenFGA instance managed by Quarkus DevServices is shared. When shared, Quarkus looks for running containers using label-based service discovery. If a matching container is found, it is used, and so a second one is not started. Otherwise, DevServices for OpenFGA starts a new container. The discovery uses the Container sharing is only used in 'dev' mode. Environment variable: |
boolean |
|
The value of the This property is used when you need multiple shared OpenFGA instances. Environment variable: |
string |
|
Optional fixed port the HTTP service will be bound to. If not defined, the port will be chosen randomly. Environment variable: |
int |
|
Optional fixed port the gRPC service will be bound to. If not defined, the port will be chosen randomly. Environment variable: |
int |
|
Optional fixed port the Playground service will be bound to. If not defined, the port will be chosen randomly. Environment variable: |
int |
|
Name of authorization store to create for DevServices. Defaults to "dev". Environment variable: |
string |
|
JSON formatted authorization model to upload during DevServices initialization. Environment variable: |
string |
|
Location of JSON formatted authorization model file to upload during DevServices initialization. The location can be prefixed with Environment variable: |
string |
|
JSON formatted authorization tuples to upload during DevServices initialization. Environment variable: |
string |
|
Location of JSON formatted authorization tuples file to upload during DevServices initialization. The location can be prefixed with Environment variable: |
string |
|
Authentication method to configure for the dev services instance. Environment variable: |
|
|
Pre-shared authentication keys. The dev services OpenFGA instance will be configured with these pre-shared keys for authentication. Environment variable: |
list of string |
required |
OIDC issuer (authorization server) signing the tokens, and where the keys will be fetched from. Environment variable: |
string |
required |
OIDC audience of the tokens being signed by the authorization server. Environment variable: |
string |
required |
OIDC issuer DNS aliases that will be accepted as valid when verifying the Environment variable: |
list of string |
|
OIDC subject names that will be accepted as valid when verifying the Environment variable: |
list of string |
|
ClientID claims that will be used to parse the clientID - configure in order of priority (first is highest). Environment variable: |
list of string |
|
Path to file containing a PEM encoded certificate to use for the DevServices OpenFGA instance. Environment variable: |
string |
required |
Path to file containing a PEM encoded private key to use for the DevServices OpenFGA instance. Environment variable: |
string |
required |
Timeout while creating the store/authorizationModel Environment variable: |
|
|
Type |
Default |
|
Credentials method to use for authentication. When set to When set to Environment variable: |
|
|
Type |
Default |
|
Pre-shared authentication key. The dev services OpenFGA instance will be configured with these pre-shared keys for authentication. Environment variable: |
string |
required |
Type |
Default |
|
OAuth client id. The client id is used to identify the client to the authorization server and is provided by the authorization service. Environment variable: |
string |
required |
OAuth client secret. The client secret is used to authenticate the client to the authorization server and is provided by the authorization service. Environment variable: |
string |
required |
OAuth audience URI. The audience for the access token, typically the URL of the service that will consume the token. This is generally configured in the authorization service. Environment variable: |
required |
|
OAuth scopes. The scopes to request for the access token. Environment variable: |
string |
|
OAuth token issuer URL. The URL of the authorization service that will issue the access token. Environment variable: |
required |
|
OAuth token issuer path. The path of the token issuer endpoint, relative to the Default value is Environment variable: |
string |
|
Token expiration threshold. The duration before the token expiration at which the token should be refreshed. Default value is Environment variable: |
||
Token expiration threshold jitter. The maximum jitter to add to the token expiration threshold. Default value is Environment variable: |
About the Duration format
To write duration values, use the standard You can also use a simplified format, starting with a number:
In other cases, the simplified format is translated to the
|