openfga / api

Protocol Buffers used by OpenFGA
Apache License 2.0
18 stars 10 forks source link

Is it possible to provide an interface for batch checking, e.g. BatchCheck? #119

Open Bob1008-Call opened 9 months ago

rhamzeh commented 9 months ago

Hey @caozongkai1008 - the API does not support BatchCheck at the moment, however all our supported SDKs do.

For example, in the JS SDK: https://github.com/openfga/js-sdk#batch-check

const options = {
  // if you'd like to override the authorization model id for this request
  authorizationModelId: "01GXSA8YR785C4FYS3C0RTG7B1",
}
const { responses } = await fgaClient.batchCheck([{
  user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
  relation: "viewer",
  object: "document:budget",
}, {
  user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
  relation: "member",
  object: "document:budget",
}, {
  user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
  relation: "viewer",
  object: "document:roadmap",
  contextual_tuples: [{
    user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
    relation: "writer",
    object: "document:roadmap"
  }],
}], options);

/*
responses = [{
  allowed: false,
  _request: {
    user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
    relation: "viewer",
    object: "document:budget",
  }
}, {
  allowed: false,
  _request: {
    user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
    relation: "member",
    object: "document:budget",
  },
  err: <FgaError ...>
}, {
  allowed: true,
  _request: {
    user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
    relation: "viewer",
    object: "document:roadmap",
    contextual_tuples: [{
      user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
      relation: "writer",
      object: "document:roadmap"
    }],
  }},
]
*/

Take a look and let us know what you think!

Bob1008-Call commented 9 months ago

Thanks. I know sdk supports it.

rhamzeh commented 9 months ago

Can you give us your feedback on that interface? We add some features to the SDKs before the API to gather feedback for folks in order to iterate quicker and stabilize on an interface that works for everyone.

Any thoughts on the one in the SDKs? Anything you would like changed in that?

Bob1008-Call commented 9 months ago

thanks, we use OpenFGA for access control (through GRPC), and the usage scenario involves batch check, so it would be great if there is such an interface.