Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## [Unreleased](https://github.com/openfga/dotnet-sdk/compare/v0.5.1...HEAD)

- feat: add support for `start_time` parameter in `ReadChanges` endpoint
- feat: update API definitions
- feat: support assertions context and contextual tuples
- feat: support contextual tuples in `Expand`
- feat!: support passing in name to filter in `ListStores`
- fix: remove dependency on OpenTelemetry.Api (#100) - thanks @m4tchl0ck
- fix: limit default retries to `3` from `15` (https://github.com/openfga/sdk-generator/pull/420) - thanks @ovindu-a
- fix: `ListRelations` should not swallow errors
- chore(docs): replace readable names with uuid to discourage storing PII in OpenFGA (https://github.com/openfga/sdk-generator/pull/433) - thanks @sccalabr

[!WARNING]
BREAKING CHANGES:
- The `ListStores` method now accepts a body parameter with an optional `Name` to filter the stores. This is a breaking change as it changes the method contract to allow passing in a body with the name.

## v0.5.1

### [0.5.1](https://github.com/openfga/dotnet-sdk/compare/v0.5.0...v0.5.1) (2024-09-09)
Expand Down Expand Up @@ -136,7 +152,7 @@ Updated to include support for [OpenFGA 0.3.0](https://github.com/openfga/openfg

Changes:
- [BREAKING] feat(list-objects)!: response has been changed to include the object type
e.g. response that was `{"object_ids":["roadmap"]}`, will now be `{"objects":["document:roadmap"]}`
e.g. response that was `{"object_ids":["roadmap"]}`, will now be `{"objects":["document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"]}`

Fixes:
- fix(models): update interfaces that had incorrectly optional fields to make them required
Expand Down
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

# Main test target - runs .NET 6.0 tests for CI/CD
.PHONY: test
test:
dotnet test $(ROOT_DIR)/src/OpenFga.Sdk.Test/OpenFga.Sdk.Test.csproj

# NOTE: These framework-specific tests require the appropriate .NET environment:
# - test-framework: Requires Windows or Mono with full xUnit support
# - test-netcore31: Requires .NET Core 3.1 SDK

# Test .NET Framework 4.8 compatibility using Mono
.PHONY: test-framework
test-framework:
@if command -v mono >/dev/null 2>&1; then \
cd $(ROOT_DIR)/src/OpenFga.Sdk.Test.Framework && \
dotnet build -c Debug && \
mono /xunit/xunit.runner.console.2.1.0/tools/xunit.console.exe \
$(ROOT_DIR)/src/OpenFga.Sdk.Test.Framework/bin/Debug/net48/OpenFga.Sdk.Test.Framework.dll; \
else \
echo "Mono is not installed. Skipping .NET Framework tests."; \
exit 0; \
fi

# Test .NET Core 3.1 compatibility
.PHONY: test-netcore31
test-netcore31:
dotnet test $(ROOT_DIR)/src/OpenFga.Sdk.Test.NetCore31/OpenFga.Sdk.Test.NetCore31.csproj

# Run all tests - Note: Will only fully succeed on a Windows environment with all .NET versions installed
.PHONY: test-all
test-all: test
@echo "To run framework-specific tests, use 'make test-framework' and 'make test-netcore31' on appropriate environments"

.PHONY: build
build:
dotnet build $(ROOT_DIR)/src/OpenFga.Sdk/OpenFga.Sdk.csproj

.PHONY: pack
pack:
dotnet pack $(ROOT_DIR)/src/OpenFga.Sdk/OpenFga.Sdk.csproj -c Release
6 changes: 3 additions & 3 deletions OpenFga.Sdk.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
VisualStudioVersion = 12.0.0.0
MinimumVisualStudioVersion = 10.0.0.1
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{59de7a42-91d3-40f9-b967-84ff8236d62a}") = "OpenFga.Sdk", "src\OpenFga.Sdk\OpenFga.Sdk.csproj", "{b8d9e3e9-0156-4948-9de7-5e0d3f9c4d9e}"
EndProject
Project("{59de7a42-91d3-40f9-b967-84ff8236d62a}") = "OpenFga.Sdk.Test", "src\OpenFga.Sdk.Test\OpenFga.Sdk.Test.csproj", "{d119dfae-509a-4eba-a973-645b739356fc}"
Expand Down
77 changes: 43 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Search for and install `OpenFga.Sdk` in each of their respective package manager

We strongly recommend you initialize the `OpenFgaClient` only once and then re-use it throughout your app, otherwise you will incur the cost of having to re-initialize multiple times or at every request, the cost of reduced connection pooling and re-use, and would be particularly costly in the client credentials flow, as that flow will be preformed on every request.

> The `OpenFga.SdkClient` will by default retry API requests up to 15 times on 429 and 5xx errors.
> The `OpenFga.SdkClient` will by default retry API requests up to 3 times on 429 and 5xx errors.

#### No Credentials

Expand Down Expand Up @@ -379,7 +379,8 @@ Reads the list of historical relationship tuple writes and deletes.
[API Documentation](https://openfga.dev/api/service#/Relationship%20Tuples/ReadChanges)

```csharp
var body = new ClientReadChangesRequest { Type = "document" };
var startTime = DateTime.Parse("2022-01-01T00:00:00Z");
var body = new ClientReadChangesRequest { Type = "document", StartTime = startTime };
var options = new ClientReadChangesOptions {
PageSize = 10,
ContinuationToken = "...",
Expand All @@ -405,13 +406,13 @@ Reads the relationship tuples stored in the database. It does not evaluate nor e
var body = new ClientReadRequest() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "viewer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
};

// Find all relationship tuples where a certain user has a relationship as any relation to a certain document
var body = new ClientReadRequest() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
};

// Find all relationship tuples where a certain user is a viewer of any document
Expand All @@ -424,7 +425,7 @@ var body = new ClientReadRequest() {
// Find all relationship tuples where any user has a relationship as any relation with a particular document

var body = new ClientReadRequest() {
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
};

// Read all stored relationship tuples
Expand Down Expand Up @@ -457,19 +458,19 @@ var body = new ClientWriteRequest() {
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "viewer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
},
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "viewer",
Object = "document:budget",
Object = "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5",
}
},
Deletes = new List<ClientTupleKeyWithoutCondition> {
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "writer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}
},
};
Expand All @@ -492,19 +493,19 @@ var body = new ClientWriteRequest() {
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "viewer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
},
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "viewer",
Object = "document:budget",
Object = "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5",
}
},
Deletes = new List<ClientTupleKeyWithoutCondition> {
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "writer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}
},
};
Expand Down Expand Up @@ -536,7 +537,7 @@ var options = new ClientCheckOptions {
var body = new ClientCheckRequest {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "writer",
Object = "document:roadmap"
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
};
var response = await fgaClient.Check(body, options);
// response.Allowed = true
Expand All @@ -545,7 +546,7 @@ var response = await fgaClient.Check(body, options);
##### Batch Check

Run a set of [checks](#check). Batch Check will return `allowed: false` if it encounters an error, and will return the error in the body.
If 429s or 5xxs are encountered, the underlying check will retry up to 15 times before giving up.
If 429s or 5xxs are encountered, the underlying check will retry up to 3 times before giving up.

```csharp
var options = new ClientBatchCheckOptions {
Expand All @@ -557,36 +558,36 @@ var body = new List<ClientCheckRequest>(){
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "viewer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
ContextualTuples = new List<ClientTupleKey>() {
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "editor",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}
},
},
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "admin",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
ContextualTuples = new List<ClientTupleKey>() {
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "editor",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}
},
},
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "creator",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
},
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "deleter",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}
};

Expand All @@ -598,39 +599,39 @@ response.Responses = [{
Request: {
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "viewer",
Object: "document:roadmap",
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
ContextualTuples: [{
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "editor",
Object: "document:roadmap"
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
}]
}
}, {
Allowed: false,
Request: {
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "admin",
Object: "document:roadmap",
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
ContextualTuples: [{
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "editor",
Object: "document:roadmap"
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
}]
}
}, {
Allowed: false,
Request: {
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "creator",
Object: "document:roadmap",
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
},
Error: <FgaError ...>
}, {
Allowed: true,
Request: {
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "deleter",
Object: "document:roadmap",
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}},
]
*/
Expand All @@ -649,11 +650,11 @@ var options = new ClientCheckOptions {
};
var body = new ClientExpandRequest {
Relation = "viewer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
};
var response = await fgaClient.Expand(body, options);

// response.Tree.Root = {"name":"document:roadmap#viewer","leaf":{"users":{"users":["user:81684243-9356-4421-8fbf-a4f8d36aa31b","user:f52a4f7a-054d-47ff-bb6e-3ac81269988f"]}}}
// response.Tree.Root = {"name":"document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a#viewer","leaf":{"users":{"users":["user:81684243-9356-4421-8fbf-a4f8d36aa31b","user:f52a4f7a-054d-47ff-bb6e-3ac81269988f"]}}}
```

##### List Objects
Expand All @@ -675,13 +676,13 @@ var body = new ClientListObjectsRequest {
new() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "writer",
Object = "document:budget",
Object = "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5",
},
},
};
var response = await fgaClient.ListObjects(body, options);

// response.Objects = ["document:roadmap"]
// response.Objects = ["document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"]
```

##### List Relations
Expand All @@ -692,13 +693,13 @@ List the relations a user has on an object.
ListRelationsRequest body =
new ListRelationsRequest() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
Relations = new List<string> {"can_view", "can_edit", "can_delete", "can_rename"},
ContextualTuples = new List<ClientTupleKey>() {
new ClientTupleKey {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "editor",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}
}
};
Expand Down Expand Up @@ -742,7 +743,7 @@ const response = await fgaClient.listUsers({
}, {
user: "folder:product",
relation: "parent",
object: "document:roadmap"
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
}]
}, options);

Expand Down Expand Up @@ -779,7 +780,7 @@ var options = new ClientWriteAssertionsOptions {
var body = new List<ClientAssertion>() {new ClientAssertion() {
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation = "viewer",
Object = "document:roadmap",
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
Expectation = true,
}};
await fgaClient.WriteAssertions(body, options);
Expand All @@ -788,7 +789,7 @@ await fgaClient.WriteAssertions(body, options);

### Retries

If a network request fails with a 429 or 5xx error from the server, the SDK will automatically retry the request up to 15 times with a minimum wait time of 100 milliseconds between each attempt.
If a network request fails with a 429 or 5xx error from the server, the SDK will automatically retry the request up to 3 times with a minimum wait time of 100 milliseconds between each attempt.

To customize this behavior, create a `RetryParams` instance and assign values to the `MaxRetry` and `MinWaitInMs` constructor parameters. `MaxRetry` determines the maximum number of retries (up to 15), while `MinWaitInMs` sets the minimum wait time between retries in milliseconds.

Expand Down Expand Up @@ -826,6 +827,7 @@ namespace Example {

| Method | HTTP request | Description |
| ------------- | ------------- | ------------- |
| [**BatchCheck**](docs/OpenFgaApi.md#batchcheck) | **POST** /stores/{store_id}/batch-check | Send a list of &#x60;check&#x60; operations in a single request |
| [**Check**](docs/OpenFgaApi.md#check) | **POST** /stores/{store_id}/check | Check whether a user is authorized to access an object |
| [**CreateStore**](docs/OpenFgaApi.md#createstore) | **POST** /stores | Create a store |
| [**DeleteStore**](docs/OpenFgaApi.md#deletestore) | **DELETE** /stores/{store_id} | Delete a store |
Expand All @@ -851,7 +853,13 @@ namespace Example {
- [Model.Any](docs/Any.md)
- [Model.Assertion](docs/Assertion.md)
- [Model.AssertionTupleKey](docs/AssertionTupleKey.md)
- [Model.AuthErrorCode](docs/AuthErrorCode.md)
- [Model.AuthorizationModel](docs/AuthorizationModel.md)
- [Model.BatchCheckItem](docs/BatchCheckItem.md)
- [Model.BatchCheckRequest](docs/BatchCheckRequest.md)
- [Model.BatchCheckResponse](docs/BatchCheckResponse.md)
- [Model.BatchCheckSingleResult](docs/BatchCheckSingleResult.md)
- [Model.CheckError](docs/CheckError.md)
- [Model.CheckRequest](docs/CheckRequest.md)
- [Model.CheckRequestTupleKey](docs/CheckRequestTupleKey.md)
- [Model.CheckResponse](docs/CheckResponse.md)
Expand All @@ -869,6 +877,7 @@ namespace Example {
- [Model.ExpandRequestTupleKey](docs/ExpandRequestTupleKey.md)
- [Model.ExpandResponse](docs/ExpandResponse.md)
- [Model.FgaObject](docs/FgaObject.md)
- [Model.ForbiddenResponse](docs/ForbiddenResponse.md)
- [Model.GetStoreResponse](docs/GetStoreResponse.md)
- [Model.InternalErrorCode](docs/InternalErrorCode.md)
- [Model.InternalErrorMessageResponse](docs/InternalErrorMessageResponse.md)
Expand Down
2 changes: 2 additions & 0 deletions docs/Assertion.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**TupleKey** | [**AssertionTupleKey**](AssertionTupleKey.md) | |
**Expectation** | **bool** | |
**ContextualTuples** | [**List&lt;TupleKey&gt;**](TupleKey.md) | | [optional]
**Context** | **Object** | Additional request context that will be used to evaluate any ABAC conditions encountered in the query evaluation. | [optional]

[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md)

Loading