A set of Examples on how to call the OpenFGA .NET SDK
Example 1: A bare bones example. It creates a store, and runs a set of calls against it including creating a model, writing tuples and checking for access.
StreamedListObjectsExample: Demonstrates how to use the StreamedListObjects API to efficiently list objects with streaming responses.
OpenTelemetryExample: Shows how to integrate OpenTelemetry for observability and tracing of OpenFGA SDK operations.
ApiExecutor Example:
Demonstrates how to use the ApiExecutor to make custom HTTP requests to the OpenFGA API with full response details. This is useful when you need more control over requests or want to call endpoints not yet available in the SDK's typed API. Includes a Makefile for easy execution with a local OpenFGA server.
Prerequisites:
dockermake.netsdk
Steps
- Clone/Copy the example folder
- Run
maketo build the project - If you have an OpenFGA server running, you can use it, otherwise run
make run-openfgato spin up an instance (you'll need to switch to a different terminal after - don't forget to close it when done) - Run
make runto run the example
Steps
- Build the SDK
- In the Example project file (e.g.
Example1.csproj), comment out the part that specifies the remote SDK, e.g.
<ItemGroup>
<PackageReference Include="OpenFga.Sdk" Version="0.2.5"><PrivateAssets>all</PrivateAssets></PackageReference>
</ItemGroup>and replace it with one pointing to the local dll
<ItemGroup>
<Reference Include="OpenFga.Sdk">
<HintPath>..\..\src\OpenFga.Sdk\bin\Debug\net6.0\OpenFga.Sdk.dll</HintPath>
</Reference>
</ItemGroup>- Run
maketo build the project - If you have an OpenFGA server running, you can use it, otherwise run
make run-openfgato spin up an instance (you'll need to switch to a different terminal after - don't forget to close it when done) - Run
make runto run the example