Skip to content

Allow setting Store Id per request for multi tenant implementations #150

@joarobles

Description

@joarobles

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    On deck

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions