Skip to content

Commit

Permalink
feat: support list users
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh committed Apr 30, 2024
1 parent 62709a6 commit dafa1ea
Show file tree
Hide file tree
Showing 24 changed files with 1,931 additions and 1 deletion.
17 changes: 17 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,22 @@ docs/ErrorCode.md
docs/ExpandRequest.md
docs/ExpandRequestTupleKey.md
docs/ExpandResponse.md
docs/FgaObject.md
docs/GetStoreResponse.md
docs/InternalErrorCode.md
docs/InternalErrorMessageResponse.md
docs/Leaf.md
docs/ListObjectsRequest.md
docs/ListObjectsResponse.md
docs/ListStoresResponse.md
docs/ListUsersRequest.md
docs/ListUsersResponse.md
docs/Metadata.md
docs/Node.md
docs/Nodes.md
docs/NotFoundErrorCode.md
docs/NullValue.md
docs/ObjectOrUserset.md
docs/ObjectRelation.md
docs/OpenFgaApi.md
docs/PathUnknownErrorMessageResponse.md
Expand All @@ -73,13 +77,17 @@ docs/TupleOperation.md
docs/TupleToUserset.md
docs/TypeDefinition.md
docs/TypeName.md
docs/TypedWildcard.md
docs/UnprocessableContentErrorCode.md
docs/UnprocessableContentMessageResponse.md
docs/User.md
docs/UserTypeFilter.md
docs/Users.md
docs/Userset.md
docs/UsersetTree.md
docs/UsersetTreeDifference.md
docs/UsersetTreeTupleToUserset.md
docs/UsersetUser.md
docs/Usersets.md
docs/ValidationErrorMessageResponse.md
docs/WriteAssertionsRequest.md
Expand Down Expand Up @@ -118,6 +126,7 @@ src/OpenFga.Sdk/Client/Model/ClientListRelationsOptions.cs
src/OpenFga.Sdk/Client/Model/ClientListRelationsRequest.cs
src/OpenFga.Sdk/Client/Model/ClientListRelationsResponse.cs
src/OpenFga.Sdk/Client/Model/ClientListStoresOptions.cs
src/OpenFga.Sdk/Client/Model/ClientListUsersRequest.cs
src/OpenFga.Sdk/Client/Model/ClientPaginationOptions.cs
src/OpenFga.Sdk/Client/Model/ClientReadAssertionsOptions.cs
src/OpenFga.Sdk/Client/Model/ClientReadAuthorizaionModelOptions.cs
Expand Down Expand Up @@ -175,6 +184,7 @@ src/OpenFga.Sdk/Model/ErrorCode.cs
src/OpenFga.Sdk/Model/ExpandRequest.cs
src/OpenFga.Sdk/Model/ExpandRequestTupleKey.cs
src/OpenFga.Sdk/Model/ExpandResponse.cs
src/OpenFga.Sdk/Model/FgaObject.cs
src/OpenFga.Sdk/Model/GetStoreResponse.cs
src/OpenFga.Sdk/Model/InternalErrorCode.cs
src/OpenFga.Sdk/Model/InternalErrorMessageResponse.cs
Expand All @@ -183,11 +193,14 @@ src/OpenFga.Sdk/Model/Leaf.cs
src/OpenFga.Sdk/Model/ListObjectsRequest.cs
src/OpenFga.Sdk/Model/ListObjectsResponse.cs
src/OpenFga.Sdk/Model/ListStoresResponse.cs
src/OpenFga.Sdk/Model/ListUsersRequest.cs
src/OpenFga.Sdk/Model/ListUsersResponse.cs
src/OpenFga.Sdk/Model/Metadata.cs
src/OpenFga.Sdk/Model/Node.cs
src/OpenFga.Sdk/Model/Nodes.cs
src/OpenFga.Sdk/Model/NotFoundErrorCode.cs
src/OpenFga.Sdk/Model/NullValue.cs
src/OpenFga.Sdk/Model/ObjectOrUserset.cs
src/OpenFga.Sdk/Model/ObjectRelation.cs
src/OpenFga.Sdk/Model/PathUnknownErrorMessageResponse.cs
src/OpenFga.Sdk/Model/ReadAssertionsResponse.cs
Expand All @@ -211,13 +224,17 @@ src/OpenFga.Sdk/Model/TupleOperation.cs
src/OpenFga.Sdk/Model/TupleToUserset.cs
src/OpenFga.Sdk/Model/TypeDefinition.cs
src/OpenFga.Sdk/Model/TypeName.cs
src/OpenFga.Sdk/Model/TypedWildcard.cs
src/OpenFga.Sdk/Model/UnprocessableContentErrorCode.cs
src/OpenFga.Sdk/Model/UnprocessableContentMessageResponse.cs
src/OpenFga.Sdk/Model/User.cs
src/OpenFga.Sdk/Model/UserTypeFilter.cs
src/OpenFga.Sdk/Model/Users.cs
src/OpenFga.Sdk/Model/Userset.cs
src/OpenFga.Sdk/Model/UsersetTree.cs
src/OpenFga.Sdk/Model/UsersetTreeDifference.cs
src/OpenFga.Sdk/Model/UsersetTreeTupleToUserset.cs
src/OpenFga.Sdk/Model/UsersetUser.cs
src/OpenFga.Sdk/Model/Usersets.cs
src/OpenFga.Sdk/Model/ValidationErrorMessageResponse.cs
src/OpenFga.Sdk/Model/WriteAssertionsRequest.cs
Expand Down
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ This is an autogenerated SDK for OpenFGA. It provides a wrapper around the [Open
- [Expand](#expand)
- [List Objects](#list-objects)
- [List Relations](#list-relations)
- [List Users](#list-users)
- [Assertions](#assertions)
- [Read Assertions](#read-assertions)
- [Write Assertions](#write-assertions)
Expand Down Expand Up @@ -705,6 +706,49 @@ var response = await fgaClient.ListRelations(body);
// response.Relations = ["can_view", "can_edit"]
```

##### List Users

List the users who have a certain relation to a particular type.

[API Documentation](https://openfga.dev/api/service#/Relationship%20Queries/ListUsers)

```csharp
const options = {};

// To override the authorization model id for this request
options.authorization_model_id = "1uHxCSuTP0VKPYSnkq1pbb1jeZw";

// Only a single filter is allowed for the time being
const userFilters = [{type: "user"}];
// user filters can also be of the form
// const userFilters = [{type: "team", relation: "member"}];
const response = await fgaClient.listUsers({
object: {
type: "document",
id: "roadmap"
},
relation: "can_read",
user_filters: userFilters,
context: {
"view_count": 100
},
contextualTuples:
[{
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "editor",
object: "folder:product"
}, {
user: "folder:product",
relation: "parent",
object: "document:roadmap"
}]
}, options);

// response.users = [{object: {type: "user", id: "81684243-9356-4421-8fbf-a4f8d36aa31b"}}, {userset: { type: "user" }}, ...]
// response.excluded_users = [ {object: {type: "user", id: "4a455e27-d15a-4434-82e0-136f9c2aa4cf"}}, ... ]
```

#### Assertions

##### Read Assertions
Expand Down Expand Up @@ -789,6 +833,7 @@ namespace Example {
| [**GetStore**](docs/OpenFgaApi.md#getstore) | **GET** /stores/{store_id} | Get a store |
| [**ListObjects**](docs/OpenFgaApi.md#listobjects) | **POST** /stores/{store_id}/list-objects | List all objects of the given type that the user has a relation with |
| [**ListStores**](docs/OpenFgaApi.md#liststores) | **GET** /stores | List all stores |
| [**ListUsers**](docs/OpenFgaApi.md#listusers) | **POST** /stores/{store_id}/list-users | List all users of the given type that the object has a relation with |
| [**Read**](docs/OpenFgaApi.md#read) | **POST** /stores/{store_id}/read | Get tuples from the store that matches a query, without following userset rewrite rules |
| [**ReadAssertions**](docs/OpenFgaApi.md#readassertions) | **GET** /stores/{store_id}/assertions/{authorization_model_id} | Read assertions for an authorization model ID |
| [**ReadAuthorizationModel**](docs/OpenFgaApi.md#readauthorizationmodel) | **GET** /stores/{store_id}/authorization-models/{id} | Return a particular version of an authorization model |
Expand Down Expand Up @@ -822,18 +867,22 @@ namespace Example {
- [Model.ExpandRequest](docs/ExpandRequest.md)
- [Model.ExpandRequestTupleKey](docs/ExpandRequestTupleKey.md)
- [Model.ExpandResponse](docs/ExpandResponse.md)
- [Model.FgaObject](docs/FgaObject.md)
- [Model.GetStoreResponse](docs/GetStoreResponse.md)
- [Model.InternalErrorCode](docs/InternalErrorCode.md)
- [Model.InternalErrorMessageResponse](docs/InternalErrorMessageResponse.md)
- [Model.Leaf](docs/Leaf.md)
- [Model.ListObjectsRequest](docs/ListObjectsRequest.md)
- [Model.ListObjectsResponse](docs/ListObjectsResponse.md)
- [Model.ListStoresResponse](docs/ListStoresResponse.md)
- [Model.ListUsersRequest](docs/ListUsersRequest.md)
- [Model.ListUsersResponse](docs/ListUsersResponse.md)
- [Model.Metadata](docs/Metadata.md)
- [Model.Node](docs/Node.md)
- [Model.Nodes](docs/Nodes.md)
- [Model.NotFoundErrorCode](docs/NotFoundErrorCode.md)
- [Model.NullValue](docs/NullValue.md)
- [Model.ObjectOrUserset](docs/ObjectOrUserset.md)
- [Model.ObjectRelation](docs/ObjectRelation.md)
- [Model.PathUnknownErrorMessageResponse](docs/PathUnknownErrorMessageResponse.md)
- [Model.ReadAssertionsResponse](docs/ReadAssertionsResponse.md)
Expand All @@ -857,13 +906,17 @@ namespace Example {
- [Model.TupleToUserset](docs/TupleToUserset.md)
- [Model.TypeDefinition](docs/TypeDefinition.md)
- [Model.TypeName](docs/TypeName.md)
- [Model.TypedWildcard](docs/TypedWildcard.md)
- [Model.UnprocessableContentErrorCode](docs/UnprocessableContentErrorCode.md)
- [Model.UnprocessableContentMessageResponse](docs/UnprocessableContentMessageResponse.md)
- [Model.User](docs/User.md)
- [Model.UserTypeFilter](docs/UserTypeFilter.md)
- [Model.Users](docs/Users.md)
- [Model.Userset](docs/Userset.md)
- [Model.UsersetTree](docs/UsersetTree.md)
- [Model.UsersetTreeDifference](docs/UsersetTreeDifference.md)
- [Model.UsersetTreeTupleToUserset](docs/UsersetTreeTupleToUserset.md)
- [Model.UsersetUser](docs/UsersetUser.md)
- [Model.Usersets](docs/Usersets.md)
- [Model.ValidationErrorMessageResponse](docs/ValidationErrorMessageResponse.md)
- [Model.WriteAssertionsRequest](docs/WriteAssertionsRequest.md)
Expand Down
12 changes: 12 additions & 0 deletions docs/FgaObject.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# OpenFga.Sdk.Model.FgaObject
Object represents an OpenFGA Object. An Object is composed of a type and identifier (e.g. 'document:1') See https://openfga.dev/docs/concepts#what-is-an-object

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Type** | **string** | |
**Id** | **string** | |

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

15 changes: 15 additions & 0 deletions docs/ListUsersRequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# OpenFga.Sdk.Model.ListUsersRequest

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**AuthorizationModelId** | **string** | | [optional]
**Object** | [**FgaObject**](FgaObject.md) | |
**Relation** | **string** | |
**UserFilters** | [**List<UserTypeFilter>**](UserTypeFilter.md) | |
**ContextualTuples** | [**List<TupleKey>**](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)

11 changes: 11 additions & 0 deletions docs/ListUsersResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# OpenFga.Sdk.Model.ListUsersResponse

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Users** | [**List<User>**](User.md) | |
**ExcludedUsers** | [**List<ObjectOrUserset>**](ObjectOrUserset.md) | |

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

11 changes: 11 additions & 0 deletions docs/ObjectOrUserset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# OpenFga.Sdk.Model.ObjectOrUserset

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Object** | [**FgaObject**](FgaObject.md) | | [optional]
**Userset** | [**UsersetUser**](UsersetUser.md) | | [optional]

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

78 changes: 78 additions & 0 deletions docs/OpenFgaApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Method | HTTP request | Description
[**GetStore**](OpenFgaApi.md#getstore) | **GET** /stores/{store_id} | Get a store
[**ListObjects**](OpenFgaApi.md#listobjects) | **POST** /stores/{store_id}/list-objects | List all objects of the given type that the user has a relation with
[**ListStores**](OpenFgaApi.md#liststores) | **GET** /stores | List all stores
[**ListUsers**](OpenFgaApi.md#listusers) | **POST** /stores/{store_id}/list-users | List all users of the given type that the object has a relation with
[**Read**](OpenFgaApi.md#read) | **POST** /stores/{store_id}/read | Get tuples from the store that matches a query, without following userset rewrite rules
[**ReadAssertions**](OpenFgaApi.md#readassertions) | **GET** /stores/{store_id}/assertions/{authorization_model_id} | Read assertions for an authorization model ID
[**ReadAuthorizationModel**](OpenFgaApi.md#readauthorizationmodel) | **GET** /stores/{store_id}/authorization-models/{id} | Return a particular version of an authorization model
Expand Down Expand Up @@ -555,6 +556,83 @@ Name | Type | Description | Notes
- **Accept**: application/json


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | A successful response. | - |
| **400** | Request failed due to invalid input. | - |
| **404** | Request failed due to incorrect path. | - |
| **409** | Request was aborted due a transaction conflict. | - |
| **422** | Request timed out due to excessive request throttling. | - |
| **500** | Request failed due to internal server error. | - |

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

<a name="listusers"></a>
# **ListUsers**
> ListUsersResponse ListUsers (ListUsersRequest body)
List all users of the given type that the object has a relation with

### Example
```csharp
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using OpenFga.Sdk.Api;
using OpenFga.Sdk.Client;
using OpenFga.Sdk.Configuration;
using OpenFga.Sdk.Model;

namespace Example
{
public class ListUsersExample
{
public static void Main()
{
var configuration = new Configuration() {
ApiScheme = Environment.GetEnvironmentVariable("OPENFGA_API_SCHEME"), // optional, defaults to "https"
ApiHost = Environment.GetEnvironmentVariable("OPENFGA_API_HOST"), // required, define without the scheme (e.g. api.fga.example instead of https://api.fga.example)
StoreId = Environment.GetEnvironmentVariable("OPENFGA_STORE_ID"), // not needed when calling `CreateStore` or `ListStores`
};
HttpClient httpClient = new HttpClient();
var openFgaApi = new OpenFgaApi(config, httpClient);
var body = new ListUsersRequest(); // ListUsersRequest |
try
{
// List all users of the given type that the object has a relation with
ListUsersResponse response = await openFgaApi.ListUsers(body);
Debug.WriteLine(response);
}
catch (ApiException e)
{
Debug.Print("Exception when calling OpenFgaApi.ListUsers: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
}
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------

**body** | [**ListUsersRequest**](ListUsersRequest.md)| |

### Return type

[**ListUsersResponse**](ListUsersResponse.md)

### HTTP request headers

- **Content-Type**: application/json
- **Accept**: application/json


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
Expand Down
10 changes: 10 additions & 0 deletions docs/TypedWildcard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# OpenFga.Sdk.Model.TypedWildcard

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Type** | **string** | |

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

12 changes: 12 additions & 0 deletions docs/User.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# OpenFga.Sdk.Model.User

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Object** | [**FgaObject**](FgaObject.md) | | [optional]
**Userset** | [**UsersetUser**](UsersetUser.md) | | [optional]
**Wildcard** | [**TypedWildcard**](TypedWildcard.md) | | [optional]

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

11 changes: 11 additions & 0 deletions docs/UserTypeFilter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# OpenFga.Sdk.Model.UserTypeFilter

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Type** | **string** | |
**Relation** | **string** | | [optional]

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

12 changes: 12 additions & 0 deletions docs/UsersetUser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# OpenFga.Sdk.Model.UsersetUser

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Type** | **string** | |
**Id** | **string** | |
**Relation** | **string** | |

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

Loading

0 comments on commit dafa1ea

Please sign in to comment.