{"id":18715084,"url":"https://github.com/cerbos/cerbos-sdk-net","last_synced_at":"2025-04-12T13:05:52.588Z","repository":{"id":37797532,"uuid":"491224565","full_name":"cerbos/cerbos-sdk-net","owner":"cerbos","description":".NET SDK for interacting with the Cerbos PDP","archived":false,"fork":false,"pushed_at":"2024-11-06T09:55:18.000Z","size":1578,"stargazers_count":14,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-11-06T10:54:38.323Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cerbos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-11T18:13:44.000Z","updated_at":"2024-11-06T09:55:19.000Z","dependencies_parsed_at":"2023-09-23T03:41:33.000Z","dependency_job_id":"d00caedf-85a9-4cc3-9284-fed2149b8fcf","html_url":"https://github.com/cerbos/cerbos-sdk-net","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerbos%2Fcerbos-sdk-net","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerbos%2Fcerbos-sdk-net/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerbos%2Fcerbos-sdk-net/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cerbos%2Fcerbos-sdk-net/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cerbos","download_url":"https://codeload.github.com/cerbos/cerbos-sdk-net/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223518544,"owners_count":17158689,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T13:07:29.917Z","updated_at":"2024-11-07T13:07:30.755Z","avatar_url":"https://github.com/cerbos.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NuGeT](https://img.shields.io/nuget/v/Cerbos.Sdk?style=plastic)](https://www.nuget.org/packages/Cerbos.Sdk)\n[![NuGeT Downloads](https://img.shields.io/nuget/dt/Cerbos.Sdk?style=plastic)](https://www.nuget.org/packages/Cerbos.Sdk)\n\n# Cerbos .NET SDK\n\n.NET client library for the [Cerbos](https://github.com/cerbos/cerbos) open source access control solution. This library\nincludes gRPC clients for accessing the Cerbos PDP.\n\nFind out more about Cerbos at https://cerbos.dev and read the documentation at https://docs.cerbos.dev.\n\n# Installation\n\n- Add `Cerbos.Sdk` NuGet package as dependency to the project. See [here](https://www.nuget.org/packages/Cerbos.Sdk) for the published packages.\n\n# Examples\n\n## Creating a client without TLS\n\n```csharp\nvar client = CerbosClientBuilder.ForTarget(\"http://localhost:3593\").WithPlaintext().Build();\n```\n\n## CheckResources API\n\n```csharp\nvar request = CheckResourcesRequest.NewInstance()\n    .WithRequestId(RequestId.Generate())\n    .WithIncludeMeta(true)\n    .WithPrincipal(\n        Principal.NewInstance(\"john\", \"employee\")\n            .WithPolicyVersion(\"20210210\")\n            .WithAttribute(\"department\", AttributeValue.StringValue(\"marketing\"))\n            .WithAttribute(\"geography\", AttributeValue.StringValue(\"GB\"))\n    )\n    .WithResourceEntries(\n        ResourceEntry.NewInstance(\"leave_request\", \"XX125\")\n            .WithPolicyVersion(\"20210210\")\n            .WithAttribute(\"department\", AttributeValue.StringValue(\"marketing\"))\n            .WithAttribute(\"geography\", AttributeValue.StringValue(\"GB\"))\n            .WithAttribute(\"owner\", AttributeValue.StringValue(\"john\"))\n            .WithActions(\"approve\", \"view:public\")\n    );\n\nvar result = client.CheckResources(request).Find(\"XX125\");\nif(result.IsAllowed(\"approve\")){ // returns true if `approve` action is allowed\n    // ...\n}\n```\n\n```csharp\nvar request = CheckResourcesRequest.NewInstance()\n    .WithRequestId(RequestId.Generate())\n    .WithIncludeMeta(true)\n    .WithPrincipal\n    (\n        Principal.NewInstance(\"john\", \"employee\")\n            .WithPolicyVersion(\"20210210\")\n            .WithAttribute(\"department\", AttributeValue.StringValue(\"marketing\"))\n            .WithAttribute(\"geography\", AttributeValue.StringValue(\"GB\"))\n    )\n    .WithResourceEntries\n    (\n        ResourceEntry.NewInstance(\"leave_request\", \"XX125\")\n            .WithPolicyVersion(\"20210210\")\n            .WithAttribute(\"department\", AttributeValue.StringValue(\"marketing\"))\n            .WithAttribute(\"geography\", AttributeValue.StringValue(\"GB\"))\n            .WithAttribute(\"owner\", AttributeValue.StringValue(\"john\"))\n            .WithActions(\"view:public\", \"approve\", \"defer\"),\n        \n        ResourceEntry.NewInstance(\"leave_request\", \"XX225\")\n            .WithPolicyVersion(\"20210210\")\n            .WithAttribute(\"department\", AttributeValue.StringValue(\"marketing\"))\n            .WithAttribute(\"geography\", AttributeValue.StringValue(\"GB\"))\n            .WithAttribute(\"owner\", AttributeValue.StringValue(\"martha\"))\n            .WithActions(\"view:public\", \"approve\"),\n        \n        ResourceEntry.NewInstance(\"leave_request\", \"XX325\")\n            .WithPolicyVersion(\"20210210\")\n            .WithAttribute(\"department\", AttributeValue.StringValue(\"marketing\"))\n            .WithAttribute(\"geography\", AttributeValue.StringValue(\"US\"))\n            .WithAttribute(\"owner\", AttributeValue.StringValue(\"peggy\"))\n            .WithActions(\"view:public\", \"approve\")\n    );\n\nCheckResourcesResponse result = client.CheckResources(request);\nvar resultXX125 = result.Find(\"XX125\");\nvar resultXX225 = result.Find(\"XX225\");\nvar resultXX325 = result.Find(\"XX325\");\n\nif(resultXX125.IsAllowed(\"defer\")){ // returns true if `defer` action is allowed\n    // ...\n}\n\nif(resultXX225.IsAllowed(\"approve\")){ // returns true if `approve` action is allowed\n    // ...\n}\n\nif(resultXX325.IsAllowed(\"view:public\")){ // returns true if `view:public` action is allowed\n    // ...\n}\n```\n\n## Plan Resources API\n\n```csharp\nvar request = PlanResourcesRequest.NewInstance()\n    .WithRequestId(RequestId.Generate())\n    .WithIncludeMeta(true)\n    .WithPrincipal\n    (\n        Principal.NewInstance(\"maggie\",\"manager\")\n            .WithAttribute(\"department\", AttributeValue.StringValue(\"marketing\"))\n            .WithAttribute(\"geography\", AttributeValue.StringValue(\"GB\"))\n            .WithAttribute(\"team\", AttributeValue.StringValue(\"design\"))\n    )\n    .WithResource\n    (\n        Resource.NewInstance(\"leave_request\")\n            .WithPolicyVersion(\"20210210\")\n    )\n    .WithAction(\"approve\");\n\nPlanResourcesResponse result = client.PlanResources(request);\nif(result.IsAlwaysAllowed()) {\n    // ...\n}\nelse if (result.IsAlwaysDenied()) {\n    // ...\n}\nelse {\n    // ...\n}\n```\n\n# Upgrading from v0.2.x\n\nv1.0.0 of the SDK contains some breaking API changes and requires existing users to make a few changes to their code.\n\n## `CerbosBlockingClient` has been renamed to `CerbosClient`\n\n`CerbosBlockingClient` has been renamed to `CerbosClient` and it has support for async operations with the new \n`CheckResourcesAsync` and `PlanResourcesAsync` methods.\n\n## Simpler `CerbosClientBuilder`\n\n`CerbosClientBuilder` has a static constructor and `hostname` is the only required parameter.\n```csharp\nvar client = CerbosClientBuilder\n    .ForTarget(\"http://localhost:3593\")\n    .WithPlaintext()\n    .Build();\n```\n\n## Rename `ResourceAction` to `ResourceEntry`\n\nReplace references to `ResourceAction` with `ResourceEntry`.\n\n## New `CheckResourcesRequest` and `PlanResourcesRequest` builder classes\n\nThe `CheckResources` and `PlanResources` methods now require a `CheckResourcesRequest` or a `PlanResourcesRequest` \nobject respectively. They can be built using the new builder classes to construct `CheckResources` and `PlanResources`\nrequests.\n\n```csharp\nvar request = CheckResourcesRequest\n    .NewInstance()\n    .WithRequestId(RequestId.Generate())\n    .WithPrincipal(\n        Principal.NewInstance(\"john\", \"employee\")\n            .WithPolicyVersion(\"20210210\")\n            .WithAttribute(\"department\", AttributeValue.StringValue(\"marketing\"))\n    )\n    .WithResourceEntries(\n        ResourceEntry.NewInstance(\"leave_request\", \"XX125\")\n            .WithPolicyVersion(\"20210210\")\n            .WithAttribute(\"department\", AttributeValue.StringValue(\"marketing\"))\n    );\n```\n\n```csharp\nvar request = PlanResourcesRequest\n    .NewInstance()\n    .WithRequestId(RequestId.Generate())\n    .WithPrincipal(\n        Principal.NewInstance(\"john\", \"employee\")\n            .WithPolicyVersion(\"20210210\")\n            .WithAttribute(\"department\", AttributeValue.StringValue(\"marketing\"))\n    )\n    .WithResource\n    (\n        Resource.NewInstance(\"leave_request\")\n            .WithPolicyVersion(\"20210210\")\n    )\n    .WithAction(\"approve\");\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcerbos%2Fcerbos-sdk-net","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcerbos%2Fcerbos-sdk-net","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcerbos%2Fcerbos-sdk-net/lists"}