{"id":20215615,"url":"https://github.com/casdoor/casdoor-dotnet-sdk-example","last_synced_at":"2025-04-10T14:40:11.458Z","repository":{"id":40295673,"uuid":"473513904","full_name":"casdoor/casdoor-dotnet-sdk-example","owner":"casdoor","description":".NET example based on casdoor-dotnet-sdk","archived":false,"fork":false,"pushed_at":"2023-08-08T16:41:36.000Z","size":15202,"stargazers_count":4,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T13:11:12.184Z","etag":null,"topics":["auth","authentication","authn","casdoor","dotnet","dotnetcore","oauth","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}},"created_at":"2022-03-24T08:16:39.000Z","updated_at":"2024-08-26T03:47:06.000Z","dependencies_parsed_at":"2024-01-29T00:13:16.730Z","dependency_job_id":null,"html_url":"https://github.com/casdoor/casdoor-dotnet-sdk-example","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/casdoor%2Fcasdoor-dotnet-sdk-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casdoor%2Fcasdoor-dotnet-sdk-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casdoor%2Fcasdoor-dotnet-sdk-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casdoor%2Fcasdoor-dotnet-sdk-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/casdoor","download_url":"https://codeload.github.com/casdoor/casdoor-dotnet-sdk-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248233989,"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","dotnetcore","oauth","sso"],"created_at":"2024-11-14T06:23:34.998Z","updated_at":"2025-04-10T14:40:11.434Z","avatar_url":"https://github.com/casdoor.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\" style=\"border-bottom: none;\"\u003eCasdoor .NET SDK Samples\u003c/h1\u003e\n\nHere are Casdoor .NET SDK samples for **[casdoor-dotnet-sdk](https://github.com/casdoor/casdoor-dotnet-sdk)**.\n\n| Sample Name                          | Dependencies      | **Description**                |\n| ------------------------------------ | ----------------- | ------------------------------ |\n| \u003ca href=\"#ConsoleApp\"\u003eConsoleApp\u003c/a\u003e | .NET 6.0 or newer | Sample of a simple console app |\n| \u003ca href=\"#MvcApp\"\u003eMvcApp\u003c/a\u003e         | .NET 6.0 or newer | Sample of a MVC webapp         |\n| \u003ca href=\"#MvcApi\"\u003eMvcApi\u003c/a\u003e         | .NET 7.0 or newer | Sample of a MVC webapi         |\n\n## Demo Video\n\n![mvcapi1](docs/assets/MvcApi.gif)\n\n## \u003ca id=\"ConsoleApp\"\u003eConsoleApp\u003c/a\u003e\n\nThis sample simply shows how to use [Casdoor.Client](https://github.com/casdoor/casdoor-dotnet-sdk/tree/master/src/Casdoor.Client) package. It is an API client implementation for the Casdoor, used to call the Casdoor APIs.\n\n### Quickstart\n\n```\ngit clone https://github.com/casdoor/casdoor-dotnet-sdk-example.git\ncd casdoor-dotnet-sdk-example\ndotnet run --project ConsoleApp\n```\n\nSome information will be displayed on the console, which is from the `Program.cs` file and has been processed by Casdoor.\n\n### Configuration\n\nNow open `Program.cs` file and you can see the following code:\n\n```c#\nvar httpClient = new HttpClient();\nvar options = new CasdoorOptions\n{\n    Endpoint = \"https://door.casdoor.com\",\n    OrganizationName = \"casbin\",\n    ApplicationName = \"app-build-in\",\n    ApplicationType = \"native\",\n    ClientId = \"b800a86702dd4d29ec4d\",\n    ClientSecret = \"1219843a8db4695155699be3a67f10796f2ec1d5\",\n    CallbackPath = \"/callback\",\n    RequireHttpsMetadata = true,\n    Scope = \"openid profile email\"\n};\nvar client = new CasdoorClient(httpClient, options);\n```\n\nThe meanings of some fields are explained as follows:\n\n| Name                 | Must | Description                                                  |\n| -------------------- | ---- | ------------------------------------------------------------ |\n| Endpoint             | Yes  | Your Casdoor host.                                           |\n| OrganizationName     | Yes  | The organization that the application belongs to.            |\n| ApplicationName      | Yes  | Your application name.                                       |\n| ApplicationType      | Yes  | Your application type. Must be webapp, webapi or native.     |\n| ClientId             | Yes  | Your OAuth client id.                                        |\n| ClientSecret         | Yes  | Your OAuth client secret.                                    |\n| CallbackPath         | No   | The callback path that the client will be redirected to after the user has authenticated. Default is \"/casdoor/signin-callback\". |\n| RequireHttpsMetadata | No   | Whether requires https for Casdoor endpoint.                 |\n| Scope                | No   | The scopes that the client is requesting.                    |\n\nFor more information, refer to https://github.com/casdoor/casdoor-dotnet-sdk/blob/master/README.md .\n\n## \u003ca id=\"MvcApp\"\u003eMvcApp\u003c/a\u003e\n\nThis sample shows how to use [Casdoor.AspNetCore](https://github.com/casdoor/casdoor-dotnet-sdk/tree/master/src/Casdoor.AspNetCore) package for Casdoor authentication. \n\n### Quickstart\n\n```bash\ngit clone https://github.com/casdoor/casdoor-dotnet-sdk-example.git\ncd casdoor-dotnet-sdk-example\ndotnet run --project MvcApp\n```\n\nThe default settings use the public demo Casdoor and Casnode configuration. Now Casdoor is listening on `http://localhost:5000` and `https://localhost:5001`, and you can open your browser and visit any of them.\n\n![mvcapp1](docs/assets/mvcapp-login.png)\n\nInput `admin` and `123` to sign in, or you can register a new account. \n\n### Configure your Casdoor\n\nYou can change the settings in the `appsettings.json` file according to the deployed Casdoor configuration. Here are relevant settings in this sample.\n\n```json\n\"Casdoor\": {\n    \"Endpoint\": \"https://door.casdoor.com\",\n    \"OrganizationName\": \"casbin\",\n    \"ApplicationName\": \"app-example\",\n    \"ApplicationType\": \"webapp\",\n    \"ClientId\": \"b800a86702dd4d29ec4d\",\n    \"ClientSecret\": \"1219843a8db4695155699be3a67f10796f2ec1d5\",\n    \"CallbackPath\": \"/callback\",\n    \"RequireHttpsMetadata\": false\n},\n```\n\nThe meanings of some fields are explained as follows:\n\n| Name                 | Must | Description                                                  |\n| -------------------- | ---- | ------------------------------------------------------------ |\n| Endpoint             | Yes  | Your Casdoor host.                                           |\n| OrganizationName     | Yes  | The organization that the application belongs to.            |\n| ApplicationName      | Yes  | Your application name.                                       |\n| ApplicationType      | Yes  | Your application type. Can be webapp or webapi.              |\n| ClientId             | Yes  | Your OAuth client id.                                        |\n| ClientSecret         | Yes  | Your OAuth client secret.                                    |\n| CallbackPath         | No   | The callback path that the client will be redirected to after the user has authenticated. Default is \"/casdoor/signin-callback\". |\n| RequireHttpsMetadata | No   | Whether requires https for Casdoor endpoint.                 |\n\nIn addition, some launch settings are placed in the `Properties/launchSettings.json` file, such as the listening URLs `http://localhost:5000;https://localhost:5001`, to facilitate your use of this sample. This file is not necessary.\n\nFor more information, refer to https://github.com/casdoor/casdoor-dotnet-sdk/blob/master/README.md .\n\n## \u003ca id=\"MvcApi\"\u003eMvcApi\u003c/a\u003e\n\nThis sample shows how to use [Casdoor.AspNetCore](https://github.com/casdoor/casdoor-dotnet-sdk/tree/master/src/Casdoor.AspNetCore) package for Casdoor authentication. It consists of a WebApi authenticated by CasDoor and a console program that calls it.\n\n### Quickstart\n\n```bash\ngit clone https://github.com/casdoor/casdoor-dotnet-sdk-example.git\ncd .\\casdoor-dotnet-sdk-example\\MvcApi\n```\n\nTo run the Api:\n\n```bash\ndotnet run --project ApiSample\n```\n\nThis Api comes from the Visual Studio example and after running it you will see the following:\n\n```bash\ninfo: Microsoft.Hosting.Lifetime[14]\n      Now listening on: https://localhost:7265\ninfo: Microsoft.Hosting.Lifetime[14]\n      Now listening on: http://localhost:5076\ninfo: Microsoft.Hosting.Lifetime[0]\n      Application started. Press Ctrl+C to shut down.\ninfo: Microsoft.Hosting.Lifetime[0]\n      Hosting environment: Development\ninfo: Microsoft.Hosting.Lifetime[0]\n      Content root path: {Path}\\casdoor-dotnet-sdk-example\\MvcApi\\ApiSample\n```\n\nTo run the Caller:\n\n```bash\ndotnet run --project CallerSample\n```\n\nThis caller will automatically get the token and call the aforementioned Api. If the message shown below appears after running, the call was successful.\n\n```\ntoken: {token.AccessToken}\nAPI Response:\n[{\"date\":\"2023-08-09\",\"temperatureC\":-5,\"temperatureF\":24,\"summary\":\"Warm\"},{\"date\":\"2023-08-10\",\"temperatureC\":6,\"temperatureF\":42,\"summary\":\"Scorching\"},{\"date\":\"2023-08-11\",\"temperatureC\":45,\"temperatureF\":112,\"summary\":\"Freezing\"},{\"date\":\"2023-08-12\",\"temperatureC\":29,\"temperatureF\":84,\"summary\":\"Hot\"},{\"date\":\"2023-08-13\",\"temperatureC\":23,\"temperatureF\":73,\"summary\":\"Mild\"}]\n```\n\n### Configure your Casdoor\n\nAlmost identical to MvcApp, you can change the settings in the `appsettings.json` file according to the deployed Casdoor configuration. Here are relevant settings in this api sample.\n\n```json\n\"CasDoor\": {\n    \"Endpoint\": \"https://door.casdoor.com\",\n    \"OrganizationName\": \"casbin\",\n    \"ApplicationName\": \"app-example\",\n    \"ApplicationType\": \"webapi\",\n    \"ClientId\": \"b800a86702dd4d29ec4d\",\n    \"ClientSecret\": \"1219843a8db4695155699be3a67f10796f2ec1d5\",\n    \"CallbackPath\": \"/callback\",\n    \"RequireHttpsMetadata\": false\n  },\n```\n\nThe meanings of some fields are explained as follows:\n\n| Name                 | Must | Description                                                  |\n| -------------------- | ---- | ------------------------------------------------------------ |\n| Endpoint             | Yes  | Your Casdoor host.                                           |\n| OrganizationName     | Yes  | The organization that the application belongs to.            |\n| ApplicationName      | Yes  | Your application name.                                       |\n| ApplicationType      | Yes  | Your application type.                                       |\n| ClientId             | Yes  | Your OAuth client id.                                        |\n| ClientSecret         | Yes  | Your OAuth client secret.                                    |\n| CallbackPath         | No   | The callback path that the client will be redirected to after the user has authenticated. Default is \"/casdoor/signin-callback\". |\n| RequireHttpsMetadata | No   | Whether requires https for Casdoor endpoint.                 |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasdoor%2Fcasdoor-dotnet-sdk-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcasdoor%2Fcasdoor-dotnet-sdk-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasdoor%2Fcasdoor-dotnet-sdk-example/lists"}