keycloak

📁 g1joshi/agent-skills 📅 3 days ago
2
总安装量
2
周安装量
#64766
全站排名
安装命令
npx skills add https://github.com/g1joshi/agent-skills --skill keycloak

Agent 安装分布

mcpjam 2
claude-code 2
replit 2
junie 2
zencoder 2

Skill 文档

Keycloak

Open-source IAM for enterprise authentication.

When to Use

  • Enterprise SSO
  • SAML/OIDC integration
  • Self-hosted identity
  • Multi-tenant applications

Quick Start

import Keycloak from "keycloak-js";

const keycloak = new Keycloak({
  url: "https://keycloak.example.com",
  realm: "my-realm",
  clientId: "my-app",
});

await keycloak.init({ onLoad: "login-required" });
console.log("Authenticated:", keycloak.authenticated);

Core Concepts

Token Management

// Get access token
const token = keycloak.token;

// Refresh token
await keycloak.updateToken(30); // Refresh if expires in 30s

// API call with token
fetch("/api/data", {
  headers: { Authorization: `Bearer ${token}` },
});

Protected Routes

// Express middleware
function keycloakProtect(req, res, next) {
  const token = req.headers.authorization?.split(" ")[1];
  if (!token) return res.status(401).send("Unauthorized");
  // Verify with Keycloak
  next();
}

Best Practices

Do: Use refresh token rotation, configure proper CORS Don’t: Store tokens insecurely, skip token validation

References