Toothless.Aspire.Hosting.OpenFga.Postgres 4.0.3

dotnet add package Toothless.Aspire.Hosting.OpenFga.Postgres --version 4.0.3
                    
NuGet\Install-Package Toothless.Aspire.Hosting.OpenFga.Postgres -Version 4.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Toothless.Aspire.Hosting.OpenFga.Postgres" Version="4.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Toothless.Aspire.Hosting.OpenFga.Postgres" Version="4.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Toothless.Aspire.Hosting.OpenFga.Postgres" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Toothless.Aspire.Hosting.OpenFga.Postgres --version 4.0.3
                    
#r "nuget: Toothless.Aspire.Hosting.OpenFga.Postgres, 4.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Toothless.Aspire.Hosting.OpenFga.Postgres@4.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Toothless.Aspire.Hosting.OpenFga.Postgres&version=4.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Toothless.Aspire.Hosting.OpenFga.Postgres&version=4.0.3
                    
Install as a Cake Tool

<p align="center"> <img src="./assets/icon.svg" alt="Aspire OpenFGA" width="150" height="150"> <h1 align="center">Aspire OpenFGA</h1> </p>


Aspire hosting integration for OpenFGA.


Installation

NuGet Version NuGet Version NuGet Version NuGet Version

Core package: Toothless.Aspire.Hosting.OpenFga

Engine packages:

  • Toothless.Aspire.Hosting.OpenFga.Postgres
  • Toothless.Aspire.Hosting.OpenFga.MySQL
  • Toothless.Aspire.Hosting.OpenFga.Sqlite

The packages are also available on GitHub packages without the Toothless. prefix

Usage

By defailt AddOpenFga will setup a store with http and grpc endpoints with the engine set to in-memory. Contianers can be added using AddStore and models imported from files using WithModelDefinition.

var openFga = builder.AddOpenFga("openfga");

var store = openFga.AddStore("my-store")
    .WithModelDefinition("models", Path.Join(builder.AppHostDirectory, "Models"), "fga.mod");

builder.AddProject<MyProject>("project")
    .WithEnvironment("OpenFga__Connection", store.HttpEndpoint)
    .WithEnvironment("OpenFga__Store", store)

The AddStore method will adopt the Store ID of an existing store in the openFga resource if a store with the same name already exists.

Engines

Postgres

To use the postgres engine install Toothless.Aspire.Hosting.OpenFga.Postgres and call WithDatastore on the OpenFGA resource.

var database = builder.AddPostgres("postgres")
    .AddDatabase("db");

builder.AddOpenFga("openfga")
    .WithDatastore(database);

This depends on Aspire.Hosting.PostgreSQL

MySql

To use the postgres engine install Toothless.Aspire.Hosting.OpenFga.MySQL and call WithDatastore on the OpenFGA resource.

var database = builder.AddMySql("mysql")
    .AddDatabase("db");

builder.AddOpenFga("openfga")
    .WithDatastore(database);

This depends on Aspire.Hosting.MySql

Sqlite

To use the postgres engine install Toothless.Aspire.Hosting.OpenFga.Sqlite and call WithDatastore on the OpenFGA resource.

var database = builder.AddSqlite("sqlite");

builder.AddOpenFga("openfga")
    .WithDatastore(database);

This depnds on CommunityToolkit.Aspire.Hosting.Sqlite

Custom Engine

To use a custom engine users shoud call WithDatastore(engine, datastoreUri) on the OpenFGA resource. This will return an instance of IResourceBuilder<OpenFgaDatastoreResource> configuring the parent OpenFgaResource's and the OpenFgaDatastoreResource resources OPENFGA_DATASTORE_ENGINE, OPENFGA_DATASTORE_URI environment variables. The relationshiop between the OpenFgaDatastoreResource and OpenFgaResource resource is also configured such that the OpenFgaResource will wait for the completion of the OpenFgaDatastoreResource.

Playground

The playground can be enabled by calling WithPlayground on the OpenFGA resource. This will add a new "playground" endpoint to the OpenFGA resource.

builder.AddOpenFga("openfga")
    .WithPlayground();

When the playground is enabled the http endpoint will not be proxied by Aspire

Model Definition

Models can be imported from files using WithModelDefinition. This will import the modes from the specified path into the store the method was called on.

builder.AddOpenFga("openfga")
    .AddStore("my-store")
    .WithModelDefinition("models", Path.Join(builder.AppHostDirectory, "Models"), "fga.mod");

Client Callbacks

For arbitrary client callbacks use WithClientCallback. This will add a callback that will be called when the resource is started. The callback is provided with a OpenFgaClient instance that is configured to connect a store when used on a store resource.

builder.AddOpenFga("openfga")
    .AddStore("my-store")
    .WithClientCallback(static async (ctx, ct) =>
    {
        await ctx.Client.ReadAuthorizationModels(
            new ClientReadAuthorizationModelsOptions(),
            cancellationToken: ct);
    });

Ordering is not guaranteed between WihthModelDefinition and WithClientCallback

Tracing

By default, pusing otel traces into Aspire is disabled. To enable WithTracing should be used. This will use a sample rate of 100% by default when enabled.

builder.AddOpenFga("openfga")
    .WithTracing(sampleRaito: 1);

Metrics

By default, the metrics endpoint is disabled. To enable WithMetrics should be used. By default this will proxy the metrics endpoint.

builder.AddOpenFga("openfga")
    .WithMetrics(port: 2112, proxy: true);
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.3 274 12/15/2025
4.0.2 178 12/4/2025
4.0.1 180 12/4/2025
4.0.0 172 12/4/2025