{"id":22352936,"url":"https://github.com/fschick/keycloak.restapiclient","last_synced_at":"2025-04-09T07:09:04.967Z","repository":{"id":62686071,"uuid":"561689250","full_name":"fschick/Keycloak.RestApiClient","owner":"fschick","description":"Keycloak Admin REST API client (.NET)","archived":false,"fork":false,"pushed_at":"2025-02-12T14:07:40.000Z","size":107,"stargazers_count":63,"open_issues_count":0,"forks_count":20,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-02T02:22:19.998Z","etag":null,"topics":["csharp","dotnet","keycloak","keycloak-api","rest","rest-client"],"latest_commit_sha":null,"homepage":"","language":"Mustache","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fschick.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-11-04T09:07:27.000Z","updated_at":"2025-03-18T10:44:03.000Z","dependencies_parsed_at":"2024-04-23T09:47:50.029Z","dependency_job_id":"a4597f0c-1f73-4da7-83ea-0338661114f5","html_url":"https://github.com/fschick/Keycloak.RestApiClient","commit_stats":{"total_commits":46,"total_committers":5,"mean_commits":9.2,"dds":0.08695652173913049,"last_synced_commit":"fa979e442253f49502bb87097898af1b28dc8a20"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschick%2FKeycloak.RestApiClient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschick%2FKeycloak.RestApiClient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschick%2FKeycloak.RestApiClient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschick%2FKeycloak.RestApiClient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fschick","download_url":"https://codeload.github.com/fschick/Keycloak.RestApiClient/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247994121,"owners_count":21030050,"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":["csharp","dotnet","keycloak","keycloak-api","rest","rest-client"],"created_at":"2024-12-04T12:31:52.927Z","updated_at":"2025-04-09T07:09:04.937Z","avatar_url":"https://github.com/fschick.png","language":"Mustache","funding_links":[],"categories":[],"sub_categories":[],"readme":"# .NET / C# Keycloak.RestApiClient\nThis is a .NET / C# REST API client\n\n* for the [Keycloak Admin REST API](https://www.keycloak.org/docs-api/latest/rest-api/index.html)\n* auto-generated by [OpenAPI Generator](https://openapi-generator.tech)\n* using the [OpenAPI definitions](https://www.keycloak.org/docs-api/latest/rest-api/openapi.json) provided by Keycloak\n\n## Documentation for API Endpoints\n\n* Official documentation: [Keycloak Admin REST API](https://www.keycloak.org/docs-api/latest/rest-api/index.html)\n* Generated Swagger UI: [Swagger Editor](https://editor.swagger.io/?url=https://www.keycloak.org/docs-api/latest/rest-api/openapi.json)\n\n## Keycloak versions supported\n\n| Keycloak.RestApiClient | Keycloak |\n| ---------------------- | -------- |\n| 26.n.n                 | 26.x.x   |\n| ...                    | ...      |\n| 19.n.n                 | 19.x.x   |\n\n## Frameworks supported\n\n- .NET Core \u003e=1.0\n- .NET Framework \u003e=4.6\n- Mono/Xamarin \u003e=vNext\n\n## Installation\nInstall from NuGet package\n```powershell\nInstall-Package Schick.Keycloak.RestApiClient\n```\n\n## Getting Started\n\n### Method names\n\nMethod names are humanized:\n\n`GET` on path `/{realm}/users` becomes `GetUsers(Async)`\n\n`GET` on path `/{realm}/identity-provider/providers/{provider_id}` becomes `GetIdentityProviderProvidersByProviderId(Async)`\n\n### Authentication\n\nYou can select authentication flow either by the username and password or by providing client ID and client secret.\n\n### Sample code\n\nWith authentication by username/password\n\n```csharp\nusing FS.Keycloak.RestApiClient.Api;\nusing FS.Keycloak.RestApiClient.Authentication.ClientFactory;\nusing FS.Keycloak.RestApiClient.Authentication.Flow;\nusing FS.Keycloak.RestApiClient.ClientFactory;\n\nvar credentials = new PasswordGrantFlow\n{\n    KeycloakUrl = \"https://\u003ckeycloak-url\u003e\",\n    Realm = \"\u003crealm\u003e\",\n    UserName = \"\u003cusername\u003e\",\n    Password = \"\u003cpassword\u003e\"\n};\n\nusing var httpClient = AuthenticationHttpClientFactory.Create(credentials);\nusing var usersApi = ApiClientFactory.Create\u003cUsersApi\u003e(httpClient);\n\nvar users = await usersApi.GetUsersAsync(\"\u003crealm\u003e\");\nConsole.WriteLine($\"Users: {users.Count}\");\n```\n\nWith authentication by client-id/client-secret\n\n```csharp\nusing FS.Keycloak.RestApiClient.Api;\nusing FS.Keycloak.RestApiClient.Authentication.ClientFactory;\nusing FS.Keycloak.RestApiClient.Authentication.Flow;\nusing FS.Keycloak.RestApiClient.ClientFactory;\n\nvar credentials = new ClientCredentialsFlow\n{\n    KeycloakUrl = \"https://\u003ckeycloak-url\u003e\",\n    Realm = \"\u003crealm\u003e\",\n    ClientId = \"\u003cclient-id\u003e\",\n    ClientSecret = \"\u003cclient-secret\u003e\"\n};\n\nusing var httpClient = AuthenticationHttpClientFactory.Create(credentials);\nusing var usersApi = ApiClientFactory.Create\u003cUsersApi\u003e(httpClient);\n\nvar users = await usersApi.GetUsersAsync(\"\u003crealm\u003e\");\nConsole.WriteLine($\"Users: {users.Count}\");\n```\n\n## Advanced Usage\nTo use the API client with a HTTP proxy, setup a `System.Net.WebProxy`\n```csharp\nConfiguration c = new Configuration();\nSystem.Net.WebProxy webProxy = new System.Net.WebProxy(\"http://myProxyUrl:80/\");\nwebProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;\nc.Proxy = webProxy;\n```\n\n### Connections\nEach ApiClass (properly the ApiClient inside it) will create an instance of HttpClient. It will use that for the entire lifecycle and dispose it when called the Dispose method.\n\nTo better manager the connections it's a common practice to reuse the HttpClient and HttpClientHandler (see [here](https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests#issues-with-the-original-httpclient-class-available-in-net) for details). To use your own HttpClient instance just pass it to the ApiClass constructor.\n\n```csharp\nHttpClientHandler yourHandler = new HttpClientHandler();\nHttpClient yourHttpClient = new HttpClient(yourHandler);\nvar api = new YourApiClass(yourHttpClient, yourHandler);\n```\n\nIf you want to use an HttpClient and don't have access to the handler, for example in a DI context in Asp.net Core when using IHttpClientFactory.\n\n```csharp\nHttpClient yourHttpClient = new HttpClient();\nvar api = new YourApiClass(yourHttpClient);\n```\nYou'll loose some configuration settings, the features affected are: Setting and Retrieving Cookies, Client Certificates, Proxy settings. You need to either manually handle those in your setup of the HttpClient or they won't be available.\n\nHere an example of DI setup in a sample web project:\n\n```csharp\nservices.AddHttpClient\u003cYourApiClass\u003e(httpClient =\u003e new PetApi(httpClient));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffschick%2Fkeycloak.restapiclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffschick%2Fkeycloak.restapiclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffschick%2Fkeycloak.restapiclient/lists"}