> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fga.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Modeling Blocklists

> Preventing certain users from accessing objects

In this guide you'll see how to model preventing users from accessing objects using [Auth0 FGA](https://docs.fga.dev/fga.md). For example, `blocking` users from accessing a `document`, even if it has been already shared with them.

**When to use**

Exclusion is useful while building applications. You may need to support access patterns like granting access to some users, but excluding specific people or groups, similar to how users can block others from following them on social media, or prevent them from sharing documents on Google Drive.

This is useful when:

* Implementing the "blocking" feature, such as the profile blocking commonly present on social media platforms (e.g. Instagram and Twitter).
* Reduce a user's access if they are part of a particular group (e.g. restricting access to members who are also guests, or restricting access to users in a certain locality).

## Before you start

Before you start this guide, make sure you're familiar with some [Auth0 FGA Concepts](https://docs.fga.dev/fga-concepts.md) and know how to develop the things listed below.

<details>
  <summary>
    You will start with the *[authorization model](https://docs.fga.dev/fga-concepts.md#what-is-an-authorization-model)* below, it represents a `document` *[type](https://docs.fga.dev/fga-concepts.md#what-is-a-type)* that can have users **[related](https://docs.fga.dev/fga-concepts.md#what-is-a-relation)** as `editor`, and `team` type that can have users related as `member`.

    Let us also assume that we have a `document` called "planning", shared for editing within the product `team` (comprised of becky and carl).
  </summary>

  The current state of the system is represented by the following relationship tuples being in the system already:

  ```json theme={null}
  [
    // Members of the product team can edit the planning document
    {
      "user": "team:product#member",
      "relation": "editor",
      "object": "document:planning"
    },
    // Becky is a member of the product team
    {
      "user": "user:becky",
      "relation": "member",
      "object": "team:product"
    },
    // Carl is a member of the product team
    {
      "user": "user:carl",
      "relation": "member",
      "object": "team:product"
    }
  ]
  ```

  ***

  In addition, you will need to know the following:

  ### Modeling user groups

  You need to know how to add users to groups and grant groups access to resources. [Learn more →](https://docs.fga.dev/modeling/basics/user-groups.md)

  ### Auth0 FGA Concepts

  * A [Type](https://docs.fga.dev/fga-concepts.md#what-is-a-type): a class of objects that have similar characteristics
  * A [User](https://docs.fga.dev/fga-concepts.md#what-is-a-user): an entity in the system that can be related to an object
  * A [Relation](https://docs.fga.dev/fga-concepts.md#what-is-a-relation): is a string defined in the type definition of an authorization model that defines the possibility of a relationship between an object of the same type as the type definition and a user in the system
  * An [Object](https://docs.fga.dev/fga-concepts.md#what-is-an-object): represents an entity in the system. Users' relationships to it can be define through relationship tuples and the authorization model
  * A [Relationship Tuple](https://docs.fga.dev/fga-concepts.md#what-is-a-relationship-tuple): a grouping consisting of a user, a relation and an object stored in Auth0 FGA
  * [Exclusion Operator](https://docs.fga.dev/modeling/configuration-language.md#the-exclusion-operator): the exclusion operator can be used to exclude certain usersets from being related to an object
</details>

[The Playground
Try this guide out on the Auth0 FGA Playground](https://play.fga.dev/)

## Step by step

With the above authorization model and relationship tuples, Auth0 Fine-Grained Authorization (FGA) will correctly respond with `{"allowed":true}` when [check](https://docs.fga.dev/fga-concepts.md#what-is-a-check-request) is called to see if Carl and Becky can edit this `document`.

We can verify that by issuing two check requests:

We want to share a document with the product team and also have the ability to deny certain users access, even if they have the document shared with them already. We can verify this by blocking Carl (who we have seen already has edit access) from editing the document.

In order to do that, we need to:

1. [Modify our model to allow indicating that users can be blocked from accessing a document](#01-modify-our-model-so-users-can-be-blocked-from-accessing-a-document)
2. [Modify our model to indicate that users who are blocked can no longer edit the document](#02-modify-our-model-so-users-who-are-blocked-can-no-longer-edit-the-document)
3. [Verify that our solution works](#03-verify-our-solution-works):

a. [Indicate that Carl is blocked from the planning document](#a-indicate-that-carl-is-blocked-from-the-planning-document)

b. [Carl (now blocked) can no longer edit the document](#b-carl-now-blocked-can-no-longer-edit-the-document)

c. [Becky still has edit access](#c-becky-still-has-edit-access)

### 01. Modify our model so users can be blocked from accessing a document

To allow users to be "blocked" from accessing a `document`, we first need to allow this relation. We'll update our store model to add a `blocked` [relation](https://docs.fga.dev/fga-concepts.md#what-is-a-relation) to the `document` type.

The authorization model becomes this:

Now we can add relationship tuples indicating that a certain user is `blocked` from editing a `document`.

### 02. Modify our model so users who are blocked can no longer edit the document

Now that we can mark users as `blocked` from editing documents, we need to support denying the `editor` relationship when a user is `blocked`. We do that by modifying the relation definition of `editor`, and making use of the [**exclusion operator**](https://docs.fga.dev/modeling/configuration-language.md#the-exclusion-operator) to exclude the set of `blocked` users, as we can see here:

### 03. Verify our solution works

To check if our new model works, we'll add a relationship tuple with Carl as `blocked` from `document:planning` and then verify that Carl no longer has `editor` access to that document.

#### a. Indicate that Carl is blocked from the planning document

With our modified authorization model, we can indicate that Carl is blocked by adding this *[relationship tuple](https://docs.fga.dev/fga-concepts.md#what-is-a-relationship-tuple)*.

#### b. Carl (now blocked) can no longer edit the document

We have modified the authorization model and added relationship tuples to indicate that Carl is `blocked`. Now let's make sure our solution works as expected.

To check if Carl still has access to the document, we can issue a check request with Carl as the user.

The response is `false`, so our solution is working as expected.

#### c. Becky still has edit access

To check if Becky still has access to the document, we'll issue another check request with Becky as the user.

The response is `true`, indicating our model change did not inadvertently deny access for users who have access but are not blocked.

> [!WARNING]
>
> When creating tuples for Auth0 Fine-Grained Authorization (FGA) make sure to use unique ids for each object and user within your application domain. We are using first names and human-readable identifiers to make this task easier to read.

## Related Sections

Check the following sections for more on how to model with Auth0 FGA.

[Modeling: Getting Started
Learn about how to get started with modeling.](https://docs.fga.dev/modeling/getting-started.md)

[Configuration Language
Learn about Auth0 FGA Configuration Language.](https://docs.fga.dev/modeling/configuration-language.md)

[Public Access
Learn about model public access.](https://docs.fga.dev/modeling/basics/public-access.md)
