More info on openfga.dev
The FGA Server needs to be running before this Go server, cause on start it will create a new model and populate it with the model in fga-model.json
.
docker run -p 8080:8080 -p 8081:8081 -p 3000:3000 openfga/openfga run
cp .env.sample .env
go run main.go
Method | Endpoint | Description |
---|---|---|
GET |
/documents/:id |
Get a document |
POST |
/documents |
Create a new document, the JSON body accepts name and content |
POST |
/documents/:id/share |
Share a document, the JSON body accepts relation and user . You can also use this endpoint to add a file to a parent folder by setting the relation to parent and the user to folder:<id> |
GET |
/folders/:id |
Get a folder |
POST |
/folders |
Create a new folder, the JSON body accepts name |
POST |
/folderws/:id/share |
Share a folder, the JSON body accepts relation and user . You can also use this endpoint to add a folder to a parent folder by setting the relation to parent and the user to folder:<id> |
GET |
/documents |
Get all documents. This endpoint is included for debugging, no FGA check is done here |
GET |
/folders |
Get all folder. This endpoint is included for debugging, no FGA check is done here |
The API uses the subject (sub
) from the JWT formatted Access Token persented as Bearer token in the Authorization
header. This is a demo, and therefor not all necessary checks are in place. Please don't use this in production!
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzYW1Ab2t0YS5jb20iLCJuYW1lIjoiU2FtIEJlbGxlbiIsImlhdCI6MTUxNjIzOTAyMn0.UgLEipGU-69_dKuhgCsV7mrBcCvRJBV880kuMJbLBy8
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjaGlhcmFAb2t0YS5jb20iLCJuYW1lIjoiQ2hpYXJhIiwiaWF0IjoxNTE2MjM5MDIyfQ.-mbo6VBG1xZzK-T7bEuKqUQR1B-eu-ACRIKrtai1JEU
POST /documents/
{
"name": "Test document",
"content": "Test content"
}
GET /documents/:id
GET /documents/:id
POST /folders
{
"name": "Test Folder",
}
GET /folders/:id
GET /folders/:id
POST /documents/:id/share
{
"relation": "parent",
"user": "folder:id
}
POST /folders/:id/share
{
"relation": "viewer",
"user": "user:chiara@okta.com
}