Auth0.Fga 0.3.1 The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved

.NET 6.0
Install-Package Auth0.Fga -Version 0.3.1
dotnet add package Auth0.Fga --version 0.3.1
<PackageReference Include="Auth0.Fga" Version="0.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Auth0.Fga --version 0.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Auth0.Fga, 0.3.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Auth0.Fga as a Cake Addin
#addin nuget:?package=Auth0.Fga&version=0.3.1

// Install Auth0.Fga as a Cake Tool
#tool nuget:?package=Auth0.Fga&version=0.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

.NET SDK for Auth0 Fine Grained Authorization (FGA)

This is an autogenerated SDK for Auth0 Fine Grained Authorization (FGA). It provides a wrapper around the Auth0 Fine Grained Authorization API.

Warning: This SDK comes with no SLAs and is not production-ready!

Table of Contents

<a id="about"></a>About Auth0 Fine Grained Authorization (FGA)

Auth0 Fine Grained Authorization (FGA) is an open source Fine-Grained Authorization solution inspired by Google's Zanzibar paper. It was created by the FGA team at Auth0 based on Auth0 Fine-Grained Authorization (FGA), available under a permissive license (Apache-2) and welcomes community contributions.

Auth0 Fine Grained Authorization (FGA) is designed to make it easy for application builders to model their permission layer, and to add and integrate fine-grained authorization into their applications. Auth0 Fine Grained Authorization (FGA)’s design is optimized for reliability and low latency at a high scale.

It allows in-memory data storage for quick development, as well as pluggable database modules - with initial support for PostgreSQL.

It offers an HTTP API and has SDKs for programming languages including Node.js/JavaScript, GoLang and .NET.

More SDKs and integrations such as Rego are planned for the future.

Resources

Installation

The Auth0 Fine Grained Authorization (FGA) .NET SDK is available on NuGet.

You can install it using:

dotnet add package Auth0.Fga
Install-Package Auth0.Fga

Search for and install Auth0.Fga in each of their respective package manager UIs.

Getting Started

Initializing the API Client

using Auth0.Fga.Api;
using Auth0.Fga.Client;
using Auth0.Fga.Configuration;
using Auth0.Fga.Model;

namespace Example {
    public class Example {
        public static void Main() {
            try {
                // See https://github.com/auth0-lab/fga-dotnet-sdk#getting-your-store-id-client-id-and-client-secret
                var environment = Environment.GetEnvironmentVariable(("AUTH0_FGA_ENVIRONMENT"), // can be = "us"/"staging"/"playground"
                var configuration = new Configuration(environment) {
                    StoreId = Environment.GetEnvironmentVariable(("AUTH0_FGA_STORE_ID"),
                    ClientId = Environment.GetEnvironmentVariable(("AUTH0_FGA_CLIENT_ID"), // Required for all environments except playground
                    ClientSecret = Environment.GetEnvironmentVariable(("AUTH0_FGA_CLIENT_SECRET"), // Required for all environments except playground
                };
                var auth0FgaApi = new Auth0FgaApi(configuration);
                var response = auth0FgaApi.ReadAuthorizationModels();
                Debug.WriteLine(response.AuthorizationModelIds);
            } catch (ApiException e) {
                 Debug.Print("Status Code: "+ e.ErrorCode);
            }
        }
    }
}

Getting your Store ID, Client ID and Client Secret

Production

Make sure you have created your credentials on the Auth0 FGA Dashboard. Learn how ➡

You will need to set the AUTH0_FGA_ENVIRONMENT variable to "us". Provide the store id, client id and client secret you have created on the Dashboard.

Playground

If you are testing this on the public playground, you need to set your AUTH0_FGA_ENVIRONMENT to "playground".

To get your store id, you may copy it from the store you have created on the Playground. Learn how ➡

In the playground environment, you do not need to provide a client id and client secret.

Calling the API

Write Authorization Model

API Documentation

Note: To learn how to build your authorization model, check the Docs at https://docs.fga.dev.

Learn more about the Auth0 Fine Grained Authorization (FGA) configuration language.

var relations = new Dictionary<string, Userset>()
{
    {"writer", new Userset(_this: new object())},
    {
        "reader",
        new Userset(union: new Usersets(new List<Userset>()
            {new(new object(), new ObjectRelation("", "writer"))}))
    }
};
var body = new TypeDefinitions(new List<TypeDefinition>() {new("repo", relations)});
var response = await auth0FgaApi.WriteAuthorizationModel(body);

// response.AuthorizationModelId = 1uHxCSuTP0VKPYSnkq1pbb1jeZw
Read a Single Authorization Model

API Documentation

string authorizationModelId = "1uHxCSuTP0VKPYSnkq1pbb1jeZw"; // Assuming `1uHxCSuTP0VKPYSnkq1pbb1jeZw` is an id of an existing model
var response = await auth0FgaApi.ReadAuthorizationModel(authorizationModelId);

// response.AuthorizationModel.Id = "1uHxCSuTP0VKPYSnkq1pbb1jeZw"
// response.AuthorizationModel.TypeDefinitions = [{ "type": "repo", "relations": { ... } }]
Read Authorization Model IDs

API Documentation

var response = await auth0FgaApi.ReadAuthorizationModels();

// response.AuthorizationModelIds = ["1uHxCSuTP0VKPYSnkq1pbb1jeZw", "GtQpMohWezFmIbyXxVEocOCxxgq"];
Check

API Documentation

var body =
    new CheckRequest(tupleKey: new TupleKey("document:project-roadmap", "editor", "anne"));
var response = await auth0FgaApi.Check(body);
// response.Allowed = true
Write Tuples

API Documentation

var body = new WriteRequest(new TupleKeys(new List<TupleKey>
    {new("document:project-roadmap", "editor", "anne")}));
var response = await auth0FgaApi.Write(body);
Delete Tuples

API Documentation

var body = new WriteRequest(new TupleKeys(new List<TupleKey> { }),
    new TupleKeys(new List<TupleKey> {new("document:project-roadmap", "editor", "anne")}));
var response = await auth0FgaApi.Write(body);
Expand

API Documentation

var body = new ExpandRequest(new TupleKey("document:project-roadmap", "editor"));
var response = await auth0FgaApi.Expand(body);

// response.Tree.Root = {"name":"workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6#admin","leaf":{"users":{"users":["anne","beth"]}}}
Read

API Documentation

// Find if a relationship tuple stating that a certain user is an admin on a certain workspace
var body = new ReadRequest(new TupleKey(
    _object: "workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6",
    relation: "admin",
    user: "81684243-9356-4421-8fbf-a4f8d36aa31b"));

// Find all relationship tuples where a certain user has a relationship as any relation to a certain workspace
var body = new ReadRequest(new TupleKey(
    _object: "workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6",
    user: "81684243-9356-4421-8fbf-a4f8d36aa31b"));

// Find all relationship tuples where a certain user is an admin on any workspace
var body = new ReadRequest(new TupleKey(
    _object: "workspace:",
    relation: "admin",
    user: "81684243-9356-4421-8fbf-a4f8d36aa31b"));

// Find all relationship tuples where any user has a relationship as any relation with a particular workspace
var body = new ReadRequest(new TupleKey(
    _object: "workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6"));

var body = new ReadRequest(new TupleKey("document:project-roadmap", "editor", "anne"));
var response = await auth0FgaApi.Read(body);

// In all the above situations, the response will be of the form:
// response = {"tuples":[{"key":{"user":"...","relation":"...","object":"..."},"timestamp":"..."}]}
Read Changes (Watch)

API Documentation

var type = 'workspace';
var pageSize = 25;
var continuationToken = 'eyJwayI6IkxBVEVTVF9OU0NPTkZJR19hdXRoMHN0b3JlIiwic2siOiIxem1qbXF3MWZLZExTcUoyN01MdTdqTjh0cWgifQ==';

var response = await auth0FgaApi.ReadChanges(type, pageSize, continuationToken);

// response.continuation_token = ...
// response.changes = [
//   { tuple_key: { user, relation, object }, operation: "write", timestamp: ... },
//   { tuple_key: { user, relation, object }, operation: "delete", timestamp: ... }
// ]

API Endpoints

Method HTTP request Description
Check POST /stores/{store_id}/check Check whether a user is authorized to access an object
Expand POST /stores/{store_id}/expand Expand all relationships in userset tree format, and following userset rewrite rules. Useful to reason about and debug a certain relationship
Read POST /stores/{store_id}/read Get tuples from the store that matches a query, without following userset rewrite rules
ReadAssertions GET /stores/{store_id}/assertions/{authorization_model_id} Read assertions for an authorization model ID
ReadAuthorizationModel GET /stores/{store_id}/authorization-models/{id} Return a particular version of an authorization model
ReadAuthorizationModels GET /stores/{store_id}/authorization-models Return all the authorization model IDs for a particular store
ReadChanges GET /stores/{store_id}/changes Return a list of all the tuple changes
Write POST /stores/{store_id}/write Add or delete tuples from the store
WriteAssertions PUT /stores/{store_id}/assertions/{authorization_model_id} Upsert assertions for an authorization model ID
WriteAuthorizationModel POST /stores/{store_id}/authorization-models Create a new authorization model

Models

Contributing

Issues

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker.

Pull Requests

Pull Requests are not currently open, please raise an issue or contact a team member on https://discord.gg/8naAwJfWN6 if there is a feature you'd like us to implement.

Author

Auth0 FGA

License

This project is licensed under the MIT license. See the LICENSE file for more info.

The code in this repo was auto generated by OpenAPI Generator from a template based on the csharp-netcore template, licensed under the Apache License 2.0.

Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Auth0.Fga:

Package Downloads
Fga.Net.DependencyInjection

Auth0 Fine Grained Authorization for .NET. This package includes DI collection extensions for the FGA Client.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.1 84 6/10/2022
0.3.0 70 6/7/2022
0.2.4 119 4/10/2022
0.2.3 80 4/9/2022
0.2.2 71 3/17/2022
0.2.1 77 3/11/2022
0.2.0 81 3/11/2022