agentleFS
NikiforovAllNikiforovAll/keycloak-authorization-services-dotnet/skills/keycloak-auth-services/SKILL.md

keycloak-auth-services

Skill673 starsChanged 7 months agoMITView on GitHub

Implementation guide for Keycloak.AuthServices .NET library — authentication (JWT Bearer, OIDC, RFC 8414), authorization (RBAC, resource protection, Authorization Server, organizations, multi-tenancy), Admin REST API SDK, Protection API SDK, and developer experience tooling (.NET Aspire, templates, OpenTelemetry). Trigger phrases include Keycloak.AuthServices, ProtectedResource, Admin SDK, Protection API, organization, RFC 8414, token introspection.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    All packages bind to "Keycloak" config section by default.

    line 83
  2. Very specific:

    IHttpClientBuilder: all HTTP clients return IHttpClientBuilder for resilience, handlers, etc.

    line 136
  3. Very specific:

    Token management: use Duende.AccessTokenManagement for service account tokens

    line 137

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Keycloak.AuthServices Implementation Guide

Quick Start

Choose your task and load the appropriate reference:

  1. JWT Bearer Authentication (Web API) → Continue below
  2. OIDC Authentication (Web App) → Load authentication.md
  3. Authorization & RBAC → Load authorization.md
  4. Resource Protection & Authorization Server → Load resource-protection.md
  5. Admin REST API SDK → Load admin-sdk.md
  6. Protection API SDK → Load protection-api.md
  7. Developer Experience (Aspire, Templates) → Load devex.md
  8. Configuration Reference → Load configuration.md
  9. Recipes & Troubleshooting → Load troubleshooting.md
  10. Token Introspection (Lightweight Tokens) → Load authorization.md (see "Token Introspection" section)
  11. Organization Authorization (Multi-Tenancy) → Load organization-authorization.md
  12. RFC 8414 Server Metadata Discovery → Load authentication.md (see "Server Metadata Discovery" section)
  13. Custom Token Provider (IKeycloakAccessTokenProvider) → Load resource-protection.md (see "IKeycloakAccessTokenProvider" section)
  14. Extensible Policy Builder (IProtectedResourcePolicyBuilder) → Load resource-protection.md (see "IProtectedResourcePolicyBuilder" section)
  15. Pluggable Parameter Resolvers → Load resource-protection.md (see "Pluggable Parameter Resolvers" section)

Packages Overview

PackagePurpose
Keycloak.AuthServices.AuthenticationJWT Bearer (Web API) and OpenID Connect (Web App) authentication
Keycloak.AuthServices.AuthorizationRBAC (realm/client roles), Authorization Server client, [ProtectedResource] attribute, organization authorization
Keycloak.AuthServices.SdkHand-written Admin REST API + Protection API HTTP clients
Keycloak.AuthServices.Sdk.KiotaAuto-generated (Kiota) Admin REST API client — full API coverage
Keycloak.AuthServices.CommonShared configuration (KeycloakInstallationOptions), claims utilities
Keycloak.AuthServices.OpenTelemetryMetrics and tracing instrumentation
Keycloak.AuthServices.Aspire.Hosting.NET Aspire KeycloakResource integration
Keycloak.AuthServices.Templatesdotnet new project templates

Minimal Web API Setup

dotnet add package Keycloak.AuthServices.Authentication
dotnet add package Keycloak.AuthServices.Common
using Keycloak.AuthServices.Authentication;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddKeycloakWebApiAuthentication(builder.Configuration);
builder.Services.AddAuthorization();

var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();

app.MapGet("/", () => "Hello World!").RequireAuthorization();
app.Run();
// appsettings.json — "Keycloak" section (kebab-case from adapter config)
{
  "Keycloak": {
    "realm": "Test",
    "auth-server-url": "http://localhost:8080/",
    "ssl-required": "none",
    "resource": "test-client",
    "verify-token-audience": true,
    "credentials": {
      "secret": "your-client-secret"
    }
  }
}

Configuration Section

All packages bind to "Keycloak" config section by default. Key properties:

PropertyDescription
realmKeycloak realm name
auth-server-urlKeycloak server URL (e.g., http://localhost:8080/)
resourceClient ID
ssl-requirednone, external, or all
verify-token-audienceValidate audience claim against resource
credentials.secretClient secret (confidential clients)

Both kebab-case (Keycloak adapter format) and PascalCase are supported.

Adding Authorization (RBAC)

dotnet add package Keycloak.AuthServices.Authorization
builder.Services.AddKeycloakAuthorization(builder.Configuration)
    .AddAuthorizationBuilder()
    .AddPolicy("AdminOnly", policy => policy.RequireRealmRoles("admin"))
    .AddPolicy("EditorOnly", policy => policy.RequireResourceRoles("editor"));

Adding Authorization Server (Resource Protection)

builder.Services
    .AddKeycloakAuthorization()
    .AddAuthorizationServer(builder.Configuration);

app.MapGet("/workspaces", () => "Hello World!")
    .RequireProtectedResource("workspaces", "workspace:read");

Adding Admin SDK

dotnet add package Keycloak.AuthServices.Sdk
builder.Services.AddKeycloakAdminHttpClient(builder.Configuration);

app.MapGet("/users", async (IKeycloakUserClient client) =>
    await client.GetUsers("my-realm"));

Essential Patterns

  • Configuration section: defaults to "Keycloak", override via configSectionName parameter
  • IHttpClientBuilder: all HTTP clients return IHttpClientBuilder for resilience, handlers, etc.
  • Token management: use Duende.AccessTokenManagement for service account tokens
  • OpenTelemetry: AddKeycloakAuthServicesInstrumentation() for metrics and tracing
  • Aspire: AddKeycloakContainer("keycloak") + AddRealm("Test") for local dev

Reference Documentation

  • authentication.md — JWT Bearer and OIDC setup, all overloads, adapter file config, RFC 8414 server metadata discovery
  • authorization.md — RBAC, realm/client roles, role claims transformation, token introspection
  • organization-authorization.md — Organization-based multi-tenancy, membership requirements, parameter resolvers
  • resource-protection.md — Authorization Server, Protected Resource Builder, dynamic resources, policy provider, IKeycloakAccessTokenProvider, IProtectedResourcePolicyBuilder, pluggable parameter resolvers
  • admin-sdk.md — Admin REST API (hand-written + Kiota), access token management
  • protection-api.md — UMA Protection API, resource/permission/policy management
  • devex.md — .NET Aspire, templates, OpenTelemetry
  • configuration.md — All configuration options, naming conventions, adapter file
  • troubleshooting.md — Common issues, recipes, debugging

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.