# keycloak multiple accounts

> Enable multiple concurrent Keycloak accounts in SPAs using token parking and SSO cookie isolation.

keycloak multiple accounts is a paid AI agent skill on Agensi by Dark inside, in APIs & Backend. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $2 (one-time purchase)
- Creator: [Dark inside](https://www.agensi.io/creators/dark-inside)
- Category: [APIs & Backend](https://www.agensi.io/skills/apis-backend)
- Version: 1.0
- Last updated: 2026-11-17
- Security: scan passed (2026-11-17); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/keycloak-multiple-accounts
- Tags: api, keycloak, oidc, authentication, nginx

## About this skill

Managing multiple active sessions in a Single Page Application (SPA) using Keycloak is notoriously difficult due to HTTP-only SSO cookies. Standard OIDC libraries often fail when trying to add a second account, resulting in `different_user_authenticated` errors or silent redirects to the first user. This skill provides a proven architecture and implementation guide to enable account switching and "Add Account" functionality without killing existing sessions.

### What it does
- **Multi-account Storage** manages the lifecycle of multiple tokens using a hybrid `sessionStorage` and `localStorage` approach.
- **SSO Cookie Management** bypasses Keycloak cookie collisions via a custom `forget-session` proxy pattern.
- **Session Switching** performs silent token refreshes to swap active users without requiring new credentials.
- **Per-account Logout** revokes specific server-side sessions while keeping other parked accounts active.
- **Session Lifespan Optimization** provides configuration schemas for Keycloak realm settings to prevent premature token expiration.

### How it works
1. **Initialize** the OIDC client using tokens stored in `sessionStorage` and disable the session-status iframe to prevent cookie-based logouts.
2. **Add Account** by parking current tokens in `localStorage`, clearing the active tab session, and redirecting through a proxy endpoint that clears SSO cookies before showing the login form.
3. **Switch Accounts** by performing a `grant_type=refresh_token` POST request for a parked account and reloading the page with new tokens.
4. **Clean Up** by revoking individual refresh tokens via the OIDC logout endpoint when a user removes a specific account.

### Frameworks & tools
This skill is framework-agnostic but includes implementation examples for `keycloak-js`. It requires a reverse proxy such as Nginx, Caddy, or Traefik to handle cookie clearing.

### Why this beats prompting it yourself
Keycloak's default behavior is strictly one-session-per-browser-realm. Prompting usually leads to `prompt=login` suggestions that still trigger OIDC errors or `keycloak.logout()` calls that destroy all sessions. This skill provides the specific storage orchestration and proxy configuration needed to handle the underlying cookie constraints.

### Use cases
- Adding an "Add another account" button to an enterprise SaaS dashboard.
- Building a fast account switcher for developers or admins managing multiple profiles.
- Resolving `different_user_authenticated` errors in multi-tenant SPAs.

### Known limitations
Requires control over the reverse proxy or CDN worker to implement the cookie-clearing endpoint. Parked tokens are stored in `localStorage`, which requires a strict CSP to mitigate XSS risks.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the keycloak multiple accounts skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### Why can't I just use the standard Keycloak-js library to handle multiple accounts?

Standard OIDC implementations rely on a single SSO cookie that prevents adding a second user; this skill provides a specialized architecture to isolate those cookies and manage multiple token sets simultaneously without session collisions.

### What exactly is included in the skill package?

The purchase includes a comprehensive implementation guide, the storage orchestration logic for token parking, and the specific reverse proxy configurations (Nginx/Caddy) required to handle cookie isolation.

### Can I use this skill with frontend frameworks other than React?

Yes, while the examples focus on keycloak-js, the architectural pattern and proxy-level configurations are compatible with any OIDC-compliant frontend framework including React, Vue, and Angular.

### Which AI agents is this skill compatible with?

This skill is designed for AI agents that assist in software architecture and development, providing them with the specific technical blueprint needed to solve complex authentication workflows that generic LLMs typically struggle with.

### Do I need to make changes to my server-side infrastructure to use this?

It requires a reverse proxy or CDN worker (like Nginx or Cloudflare Workers) to intercept and clear specific cookies, as client-side JavaScript cannot bypass HTTP-only cookie restrictions on its own.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
