Create an account
The first step to working with Auth0 FGA is to create an account to access an FGA dashboard to manage your stores, relationship tuples, and API calls.- Navigate to Auth0 FGA and select either Log in or Sign up.
- Select Continue with my Auth0 account. If you don’t have an existing Auth0 account, you will be able to create one..
- This screen prompts you to set up an FGA account for use with the FGA dashboard. Fill in the required information, including a Jurisdiction, which is the geographic location for where the authorization data will be stored.
- Fill out the required fields and select Submit.
Note: On first login, you are prompted to take a guided tour of the Auth0 FGA dashboard. Feel free to walk through the demo or bypass it and come back later. You can always access the guided tour by clicking the Guided Tour button at the top of each navigation section.
Build an authorization model
After creating an FGA account, the first step in setting up your access requirements is to build an authorization model. This model defines the application structure for the access relationships. In our example, we’ll build a model for granting owner access privileges to a shared document for our user,john.
-
Click Navigate to Model Explorer to Define your Authorization Model.
- In the Model Explorer page, input the following code snippet:
- Click Save.
The authorization model that we’ve built now uses modeling schema 1.1 to define a user, and defines relations that a given user has the ability to be assigned owner and viewer permissions, as well as the ability to share our document.
Apply this model by adding a Tuple to create the relationship between the user and the document.
Add Tuples
Now that we’ve defined our authorization model, we need to assign a user and permission level for access to our document. To do this, we’ll create a Tuple. A tuple represents a relationship between a user and an object and is used to store your application’s authorization data.- Navigate to Tuple Management in the left-hand navigation to open the Tuple Management dashboard.
- Click +Add Tuple to add new relationship tuples.
- In the user text box, type in the user identifier. For this guide, input
user:john. - In the object line, select the object for which you want to grant
user:john'saccess level. Selectdocument, and give it a unique identifier. For this example, use1. - In the relation drop-down selector, choose
owner. - Click Add Tuple to save your changes.
Your Tuple is now available in your Store. You can edit or delete your Tuple at any time, using the edit or trash icon.
Now, we’ve created an authorization model that defines our document and possible access levels associated with it. Next, we created a Tuple that declares our user, john, should be granted owner privileges to our document.
Verify your model
After creating an authorization model and an associated Tuple to define your access relationships, you can verify your model using an assertion. As mentioned earlier, we’ve defined that john should have owner access to our document. Let’s test our model using an assertion.Note: You must have a Tuple in your Store before adding an Assertion.
Add Assertion
The Developer Mode page provides a single-page view with panels to manage your authorization model, relationship tuples, and assertions.Note: If this is your first time visiting this screen, you are prompted with the Guided Tour. Feel free to walk through the demo or bypass and come back later. You can always access the guided tour by clicking the Guided Tour button at the top of each navigation section.
- Navigate to Developer Mode in the left-hand navigation to view your current authorization model, tuples, and assertions.
- Click +Add Assertion.
- Fill in the assertion fields with the values we defined earlier:
- User:
john - Object:
document:1 - Relation:
owner
- User:
- Click Add Assertion.
- Click the Run button on your assertion to test the model.
Create API Client Credentials
To begin calling the API, you will need API Client Credentials.- Navigate to Settings in the Dashboard’s sidebar menu.
- If you do not have the client secret, you will be presented with the Create Client button. Click Create Client.
- Enter a client name in the provided text box.
- Select the permission set(s) required for this specific client.
- Click Create when complete.
- Make sure to copy the Store ID, Client ID, and Client Secret values.
Note: You will not be able to see the client secret again after this step. It will need to be regenerated if it is lost if compromised in any way.
Call the API
Now that you’ve created your client and obtained your client credentials, you can usecurl to authenticate and make requests in the command line. Copy the following snippet to your favorite text editor and replace the variables with your API keys received in #Create API Client Credentials.
Run these commands to make sure the variables are saved properly
Authenticate
You can use your client ID and client secret to get an access token, which can then be used for authorized API calls. To obtain a token using OAuth 2.0, you can send a POST request to the FGA token issuer endpoint with your client ID and client secret using curl.OPTIONAL if you have jq installed
YOUR_ACCESS_TOKEN with the access_token from the response above. It will be used in the following commands.
Make an API Request
Once you have your access token, you can make requests to the API by including the token in theAuthorization header of your request to FGA.
Perform an Authorization Check
For example, usecurl to check if John can share the document:
Write A Tuple
If John can share the document, then we can now share the document with the external user Anne by writing a tuple to FGA assigning Anne as a viewer ondocument:1.
Set Anne as a viewer of document:1
- Navigate back to the FGA Dashboard > Tuple Management.
- Refresh the page.
Verify that sharing the document worked
Let’s make two more important Checks.- Check that Anne can now view the document:1
- Check that Anne cannot share the document (since she only has the viewer relationship)