openfga / openfga/java-sdk

Allow setting Store Id per request for multi tenant implementations

Open
#150 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
54
Forks
26
Avg merge
2d 7h
Merged PRs (30d)
9

Description

Describe the problem you'd like to have solved

In multitenant solutions it would be nice to have a single client instance and the possibility to set the store id for each request, this way the connection pool can be reused without the need to have multiple client instances.

Describe the ideal solution

The store id should available as a client option:

var request = new ClientCheckRequest()
    .user("user:81684243-9356-4421-8fbf-a4f8d36aa31b")
    .relation("writer")
    ._object("document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a");
var options = new ClientCheckOptions()
    .additionalHeaders(Map.of("Some-Http-Header", "Some value"))
    // You can rely on the model id set in the configuration or override it for this specific request
    .authorizationModelId("01GXSA8YR785C4FYS3C0RTG7B1")
    // SET THE STORE ID PER REQUEST
    .storeId("01ARZ3NDEKTSV4RRFFQ69G5FAV");

var response = fgaClient.check(request, options).get();
// response.getAllowed() = true

Alternatives and current workarounds

There are two alternatives:

  1. Having one client for each store id
  2. Explicitly calling fgaClient.setStoreId(store.getId()); on each request, but my guess is there could be race condition issues
Additional context

N/A

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the fgaClient.check(request, options) entry point and the ClientCheckOptions API shown in the issue. Determine how the configured store ID is currently selected and how request options are propagated. Done means a request can override the configured store ID without mutating shared client state, while existing configuration behavior remains available.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, authorization, backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.