Skip to main content

How to update relationship tuples

note
Auth0 Fine Grained Authorization (FGA) is the early-stage product we are building at Auth0 to solve fine-grained authorization at scale. Sign up for the Developer Community Preview to try it out, and join our Discord community if you are interested in learning more about our plans.

Please note that at this point in time, it is not considered production-ready and does not come with any SLAs; availability and uptime are not guaranteed. Limitations of Auth0 FGA during the Developer Community Preview can be found here.

This section will illustrate how to update relationship tuples.

Before you start

  1. You have obtained the environment, store id, client id and client secret.
  2. You have installed the SDK.
  3. You have configured the authorization model.
  4. You have loaded FGA_ENVIRONMENT, FGA_STORE_ID, FGA_CLIENT_ID and FGA_CLIENT_SECRET as environment variables.

Step by Step

Assume that you want to add user anne to have relationship reader with object document:Z

{
"user": "anne",
"relation": "reader",
"object": "document:Z"
}

01. Configure the Auth0 FGA API client

Before calling the write API, you will need to configure the API client.

// import the SDK
const { Auth0FgaApi } = require('@auth0/fga');

// Initialize the SDK
const fgaClient = new Auth0FgaApi({
environment: process.env.FGA_ENVIRONMENT,
storeId: process.env.FGA_STORE_ID,
clientId: process.env.FGA_CLIENT_ID,
clientSecret: process.env.FGA_CLIENT_SECRET,
});

02. Calling Write API to Add New Relationship Tuples

To add the relationship tuples, we can invoke the write API.


await fgaClient.write({
writes: {
tuple_keys: [
{ user: 'anne', relation: 'reader', object: 'document:Z'}
]
}
});

03. Calling Write API to Delete Relationship Tuples

To delete relationship tuples, we can invoke the write API.

Assume that you want to delete user anne's reader relationship with object document:Z

{
"user": "anne",
"relation": "reader",
"object": "document:Z"
}

await fgaClient.write({
deletes: {
tuple_keys : [
{ user: 'anne', relation: 'reader', object: 'document:Z'}
]
}
});
Managing User Access

Learn about how to give a user access to a particular object.

Managing Group Access

Learn about how to give a group of users access to a particular object.

Transactional Writes

Learn about how to update multiple relations within the same API call.

Have Feedback?

Join us on the Discord community if you have any questions or suggestions.