Keycloak

From G1Joshi/Agent-Skills · View interactive version

Keycloak is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Keycloak IAM assistance covering OpenID Connect realms, identity brokering, user federation, and client adapters. Use when configuring enterprise SSO, managing Keycloak realms, or securing microservices.

How to use this skill

Skill file

Keycloak

Keycloak is an open-source Identity and Access Management solution aimed at modern applications and services. It makes it easy to secure applications and services with little to no code.

When to Use

Quick Start

docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:latest start-dev

Core Concepts

Realm Architecture & Multi-Tenancy

Realms isolate groups of users, credentials, roles, and client applications completely:

[ Master Realm (Administer Keycloak) ]
       ├── [ Realm: EnterpriseA ] ── (Users, Roles, Clients, LDAP Provider)
       └── [ Realm: EnterpriseB ] ── (Users, Roles, Clients, Google Provider)

OIDC Client Registration (Public vs Confidential)

{
  "clientId": "frontend-spa",
  "publicClient": true,
  "standardFlowEnabled": true,
  "redirectUris": ["https://app.example.com/*"],
  "webOrigins": ["https://app.example.com"],
  "pkceCodeChallengeMethod": "S256"
}

Docker Deployment with Production Database

Running Keycloak in production mode connected to PostgreSQL:

# docker-compose.yml
services:
  keycloak:
    image: quay.io/keycloak/keycloak:24.0
    command: start --optimized
    environment:
      KC_DB: postgres
      KC_DB_URL: jdbc:postgresql://postgres:5432/keycloak
      KC_DB_USERNAME: keycloak
      KC_DB_PASSWORD: secretpassword
      KC_HOSTNAME: auth.example.com
      KEYCLOAK_ADMIN: admin
      KEYCLOAK_ADMIN_PASSWORD: adminpassword
    ports:
      - "8080:8080"

Common Patterns

Client Credentials Flow for Service-to-Service Auth

Problem: Backend microservices calling other microservices require automated machine-to-machine authentication.

Solution:

Authenticate using Keycloak Client Credentials grant:

curl -X POST "http://keycloak:8080/realms/enterprise/protocol/openid-connect/token" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials" \
  -d "client_id=order-service" \
  -d "client_secret=YOUR_CLIENT_SECRET"

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :------------------------------------- | :------------------------------------------------------------------ | :------------------------------------------------------------------ |

| Invalid parameter: redirect_uri | Target redirect URI not listed in client's Valid Redirect URIs. | Add exact scheme, host, and port to Keycloak client configuration. |

| KC-SERVICES0093: Invalid credentials | Secret mismatch or user locked out by brute-force protection. | Verify client secret and check user unlock status in Admin Console. |

| Token signature verification failed | Microservice validating token against outdated Keycloak realm keys. | Flush JWKS public key cache in the resource server. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.