{"id":20215572,"url":"https://github.com/casdoor/casdoor-dotnet-sdk","last_synced_at":"2025-04-10T14:39:33.274Z","repository":{"id":38022139,"uuid":"395587145","full_name":"casdoor/casdoor-dotnet-sdk","owner":"casdoor","description":".NET client SDK for Casdoor","archived":false,"fork":false,"pushed_at":"2024-04-27T02:02:35.000Z","size":1106,"stargazers_count":22,"open_issues_count":0,"forks_count":26,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-28T03:43:59.834Z","etag":null,"topics":["auth","authentication","authn","casdoor","dotnet","oauth","oidc","saml","sso"],"latest_commit_sha":null,"homepage":"https://github.com/casdoor/casdoor","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/casdoor.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":"2021-08-13T09:07:34.000Z","updated_at":"2024-04-27T01:58:02.000Z","dependencies_parsed_at":"2023-01-19T03:47:39.172Z","dependency_job_id":"474a7dab-061a-4f70-ba75-993999551341","html_url":"https://github.com/casdoor/casdoor-dotnet-sdk","commit_stats":null,"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casdoor%2Fcasdoor-dotnet-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casdoor%2Fcasdoor-dotnet-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casdoor%2Fcasdoor-dotnet-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casdoor%2Fcasdoor-dotnet-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/casdoor","download_url":"https://codeload.github.com/casdoor/casdoor-dotnet-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248233987,"owners_count":21069493,"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":["auth","authentication","authn","casdoor","dotnet","oauth","oidc","saml","sso"],"created_at":"2024-11-14T06:23:22.136Z","updated_at":"2025-04-10T14:39:33.254Z","avatar_url":"https://github.com/casdoor.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Casdoor .NET SDK\n\n[![Actions Status](https://github.com/casdoor/casdoor-dotnet-sdk/workflows/Build/badge.svg)](https://github.com/casdoor/casdoor-dotnet-sdk/actions)\n[![GitHub](https://img.shields.io/github/license/casdoor/casdoor-dotnet-sdk)](https://github.com/casdoor/casdoor-dotnet-sdk/blob/master/LICENSE)\n\nThe Casdoor's SDK for .NET/ASP.NET Core, which will allow you to easily connect your application to the Casdoor authentication system without having to implement it from scratch.\n\n## Packages\n\nThis SDK is built using the following packages for different platforms:\n\n| Package Name         | NuGet                                                                                                               | Description          | Supported frameworks                   |\n|----------------------|---------------------------------------------------------------------------------------------------------------------|----------------------|----------------------------------------|\n| `Casdoor.Client`     | [![NuGet](https://img.shields.io/nuget/vpre/Casdoor.Client)](https://www.nuget.org/packages/Casdoor.Client)         | SDK for .NET         | .NET Standard 2.0/.NET 4.6.1 and newer |\n| `Casdoor.AspNetCore` | [![NuGet](https://img.shields.io/nuget/vpre/Casdoor.AspNetCore)](https://www.nuget.org/packages/Casdoor.AspNetCore) | SDK for ASP.NET Core | .NET Core 3.1 and newer                |\n| `Casdoor.Native`     | `wait publish`                                                                                                      | SDK for WPF or Maui  | -                                      |\n\n## Casdoor Client\n\nCasdoor.Client is a base package for the specific platform SDKs. It contains follow features.\n\n- CasdoorClient: A API client implementation for the Casdoor. You can use to call the Casdoor APIs.\n\n##### Usage\n\n```cs\nvar httpClient = new HttpClient();\nvar client = new CasdoorClient(HttpClient, new CasdoorOptions{\n    Endpoint = \"https://door.casdoor.com\",\n    OrganizationName = \"casbin\", // your Casdoor organization\n    ApplicationName = \"app-example\", // your Casdoor application\n    ApplicationType = \"native\", // webapp, webapi or native\n    ClientId = \"b800a86702dd4d29ec4d\", // your Casdoor application's client ID\n    ClientSecret = \"1219843a8db4695155699be3a67f10796f2ec1d5\", // your Casdoor application's client secret\n});\n\n// Request tokens (You should enable credentials flow in your Casdoor application)\nvar token = await client.RequestClientCredentialsTokenAsync();\nclient.SetBearerToken(token);\n\nvar currentUser = client.ParseJwtToken(token.AccessToken);\n\n// Request user info\nvar users = await client.GetUsersAsync();\n// Request roles\nvar roles = await client.GetRolesAsync();\n// Request Permissions\nvar persmissions = await client.GetPermissionsAsync();\n\nvar policy = new CasdoorPermissionRule()\n{\n    Id = $\"{currentUser.Owner}/{persmissions.First().Name}\",\n    V0 = $\"{currentUser.Owner}/{currentUser.Name}\",\n    V1 = \"example-resource\",\n    V2 = \"example-action\"\n};\n\nvar isPermissionAvaliable = await client.EnforceAsync(policy);\n\n```\n- CasdoorOptions (Updating)\n- Extensions (Updating)\n\n## Casdoor AspNetCore\n\n### Getting started\n\n1. Add the following settings about casdoor in your appsettings.json file:\n\n```json5\n{\n    \"Casdoor\": {\n        \"Endpoint\": \"\u003cyour Casdoor endpoint\u003e\",\n        \"OrganizationName\": \"\u003cyour Casdoor organization\u003e\",\n        \"ApplicationName\": \"\u003cyour Casdoor application\u003e\",\n        \"ApplicationType\": \"webapp\", // webapp or webapi (webapi is not yet supported)\n        \"ClientId\": \"\u003cyour Casdoor application's client ID\u003e\",\n        \"ClientSecret\": \"\u003cyour Casdoor application's client secret\u003e\",\n\n        // Optional: The callback path that the client will be redirected to\n        // after the user has authenticated. default is \"/casdoor/signin-callback\"\n        \"CallbackPath\": \"/callback\",\n        // Optional: Whether require https for casdoor endpoint\n        \"RequireHttpsMetadata\": false,\n        // Optional: The scopes that the client will request\n        \"Scopes\": [\n            \"openid\",\n            \"profile\",\n            \"email\",\n        ]\n    }\n}\n```\n\n2. Add the following code to your webapp:\n\n```csharp\nbuilder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)\n    .AddCasdoor(builder.Configuration.GetSection(\"Casdoor\"))\n    .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme);\n```\n\n3. Now you can use the Casdoor authentication scheme in your webapp!\n\n### Samples\n\n#### 1. [MVC sample](https://github.com/casdoor/casdoor-dotnet-sdk/tree/master/samples/MvcApp)\n\nIt is a MVC webapp that uses Casdoor authentication.\nThe default settings use the public demo Casdoor and Casnode configuration, you can directly start the webapp by running:\n\n```bash\ndotnet run\n```\n\nOr change the settings in the appsettings.json according to your deployed casdoor configuration.[README.md](README.md)\n\n## License\n\nThis project is licensed under the [Apache 2.0 license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasdoor%2Fcasdoor-dotnet-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcasdoor%2Fcasdoor-dotnet-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasdoor%2Fcasdoor-dotnet-sdk/lists"}