/Keycloak.Net

C# client for Keycloak 6.x

Primary LanguageC#MIT LicenseMIT

Keycloak.Net

Icon

forked from lvermeulen/Keycloak.Net

Build status license NuGet downloads .net4.5.2 .netstandard 1.4 FOSSA Status

C# SDK client for Keycloak.

See documentation at https://www.keycloak.org/documentation.

Features

  • Attack Detection
  • Authentication Management
  • Client Attribute Certificate
  • Client Initial Access
  • Client Registration Policy
  • Client Role Mappings
  • Client Scopes
  • Clients
  • Component
  • Groups
  • Identity Providers
  • Key
  • Protocol Mappers
  • Realms Admin
  • Role Mapper
  • Roles
  • Roles (by ID)
  • Scope Mappings
  • User Storage Provider
  • Users
  • Root

Build

  1. Build the solution and package the Nuget package from the './src/core/Keycloak.Net.csproj' project.
    • Ensure that the nuget package version number follows the assembly's version and uses SemVer.
    • The major version number should follow the same major release of Keycloak Server.
      • E.g. Keycloak.Net 16.x.x releases should support Keycloak Server 16.x.x releases.
    • The minor version should support the following changes:
      • New functionalities added in the Keycloak.Net to support the existing APIs of Keycloak Server.
      • New functionalities added in Keycloak Server in a backwards compatible manner within the same major release.
    • The patch version is added to support minor bugfixes to support existing Keycloak Server APIs of that major release version.
  2. Upload the Nuget package to your source repository with the release number mentioned above.

Usage

  1. Install the standard Nuget package into your .NET application:

    • Package Manager
    Install-Package Keycloak.Net -Version x.x.x
    • CLI
    dotnet add package --version x.x.x Keycloak.Net
  2. Initialize the Keycloak Client with the following line:

    var keycloakClient = new KeycloakClient("http://keycloak.local", "realm", "admin-cli-client", "user", "password");
    var masterRealm = keycloakClient.GetRealmAsync("realm");

Tests

Unit Test

The unit tests are written to mainly cover common solutions such as the following:

Integration Test

The integration tests requires a hosted Keycloak Server to run. If there's no Keycloak Server available, you can easily deploy a scaffolded version of the Keycloak Server using Helm.

helm repo add bitnami https://charts.bitnami.com/bitnami
helm install my-keycloak bitnami/keycloak --namespace dev --create-namespace -f keycloak.yml --atomic

All tests should then run sequentially from Step1_0 to StepX.

Contributing

Contributions and bug reports are always welcomed. If you wish to contribute, please submit your Pull Requests for review and merge.

  • Always create branches for different issues found and submit as separate Pull Requests.
  • Always pull and rebase changes from main branch to keep a clean git history.
  • Please squash your commits into a single commit if there are too many commits on your branch before submitting a Pull Request.