Skip to main content

Modeling Public Access

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.

In this guide you will learn how to grant public access to an object, such as a certain document, using Auth0 FGA.

When to use

Public access allows your application to grant every user in the system access to an object. You would add a relationship tuple with a user as * when:

  • sharing a document publicly to indicate that everyone can view it
  • a public poll is created to indicate that anyone can vote on it
  • a blog post is published and anyone should be able to read it
  • a video is made public for anyone to watch

Before you start

In order to understand this guide correctly you must be familiar with some Auth0 FGA Concepts and know how to develop the things that we will list below.

Assume that you have the following authorization model.
You have a type called document that can have a view relation.

type document
relations
define view as self

In addition, you will need to know the following:

Modeling Basics

You need to know how to create an authorization model and create a relationship tuple to grant a user access to an object. Learn more →

Auth0 FGA Concepts

  • A Type: a class of objects that have similar characteristics
  • A User: an entity in the system that can be related to an object
  • A Relation: is a string defined in the type definition of an authorization model that defines the possibility of a relationship between objects of this type and other users in the system
  • 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: a grouping consisting of a user, a relation and an object stored in Auth0 FGA
  • With Everyone: a * can be used in relationship tuples to represent every user
caution

Make sure to use unique ids for each object and user within your application domain when creating relationship tuples for Auth0 Fine Grained Authorization (FGA). We are using first names and simple ids to just illustrate an easy-to-follow example.

The Playground

Try this guide out on the Auth0 FGA Playground

Step by Step

In previous guides, we have shown how to indicate that objects are related to users or objects. In some cases, you might want to indicate that everyone is related to an object (for example when sharing a document publicly).

01. Create a relationship tuple

To do this we need to create a relationship tuple using the `*` syntax. The * syntax is used to indicate that all users and objects have a relation) to a specific object.

Let us create a relationship tuple that states: anyone can view document:company-psa.doc

Initialize the SDK
// FGA_ENVIRONMENT can be "us" (default if not set) for Developer Community Preview or "playground" for the Playground API
// 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,
});

await fgaClient.write({
writes: {
tuple_keys: [
// * denotes that the user is every user and object
{ user: '*', relation: 'view', object: 'document:company-psa.doc'}
]
}
});

02. Check that the relationship exists

Once the above relationship tuple is added, we can check if bob cab view document:company-psa.doc. Auth0 FGA will return { "allowed": true } even though no relationship tuple linking bob to the document was added. That is because the relationship tuple with * as the user made it so everyone can view the document, making it public.

Initialize the SDK
// FGA_ENVIRONMENT can be "us" (default if not set) for Developer Community Preview or "playground" for the Playground API
// 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,
});

// Run a check
const { allowed } = await fgaClient.check({
tuple_key: {
user: 'bob',
relation: 'view',
object: 'document:company-psa.doc',
},});

// allowed = true
Wildcard syntax usage

Please note that * is a special Auth0 FGA syntax meaning everyone when used as a user within a relationship tuple. It is not a wildcard or regex expression.

You cannot use it with a type to mean all objects in that type. workspace:* does not mean all types; it means a single object with the type workspace and the object_id the string *.

Modeling: Getting Started

Learn about how to get started with modeling.

Configuration Language

Learn about Auth0 FGA Configuration Language.

Modeling Blocklists

Learn about model block lists.

Have Feedback?

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