npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

keycloak-auth-plugin

v0.0.1

Published

Keycloak authentication provider for the Strapi v5 administration panel.

Downloads

5

Readme

🔑 Strapi Keycloak Passport Plugin

🚀 Seamlessly integrate Keycloak authentication with Strapi Admin Panel.
💼 Enterprise-grade security, role-based access control (RBAC), and streamlined authentication.

✨ Features

🔐 Single Sign-On (SSO) – Replace Strapi's default admin login with Keycloak authentication.
🛡️ Role Mapping – Dynamically map Keycloak roles to Strapi admin roles.
⚡ Auto-Assign Default Role – Ensure a default role (STRAPI_ADMIN → Super Admin) exists at first-time activation.
🔍 Strapi RBAC Integration – Leverage Strapi's native Roles & Permissions to enforce admin access.
💾 Persistent Admin Session – No redundant authentication; login once, persist across requests.
📜 Full Logging & Debugging – Logs every authentication & authorization event.


📦 Installation

yarn add keycloak-auth-plugin

or

npm install keycloak-auth-plugin

⚙️ Configuration

🔹 config/plugins.js

Add the following entry inside your config/plugins.js file:

module.exports = ({ env }) => ({
  'keycloak-auth-plugin': {
    enabled: env('KEYCLOAK_PASSPORT_ACTIVE', true),
    config: {
      KEYCLOAK_AUTH_URL: env('KEYCLOAK_PASSPORT_AUTH_URL', 'https://keycloak.example.com/auth'),
      KEYCLOAK_REALM: env('KEYCLOAK_PASSPORT_REALM', 'master'),
      KEYCLOAK_CLIENT_ID: env('KEYCLOAK_PASSPORT_CLIENT_ID', 'strapi-admin'),
      KEYCLOAK_CLIENT_SECRET: env('KEYCLOAK_PASSPORT_CLIENT_SECRET', 'your-secret'),
      KEYCLOAK_TOKEN_URL: env('KEYCLOAK_PASSPORT_TOKEN_URL', '/token'),
      KEYCLOAK_USERINFO_URL: env('KEYCLOAK_PASSPORT_USERINFO_URL', '/userinfo'),
      roleConfigs: {
        defaultRoleId: env('KEYCLOAK_PASSPORT_DEFAULT_ROLE_ID', 5),
        excludedRoles: env('KEYCLOAK_PASSPORT_EXZIL_ROLES', [
          'uma_authorization',
          'default-roles-centralisedcms',
          'offline_access',
          'VIEWER',
        ]),
      },
    },
  },
});

This configuration:

  • Enables or disables the plugin via KEYCLOAK_PASSPORT_ACTIVE.
  • Connects to Keycloak using client credentials (KEYCLOAK_CLIENT_ID, KEYCLOAK_CLIENT_SECRET).
  • Defines RBAC mappings, excluding irrelevant Keycloak roles from syncing.
  • Auto-assigns a default role (defaultRoleId) if no mapping exists.

🛠 Setup in Keycloak

1️⃣ Create a Client

  • Go to Keycloak Admin PanelClients
  • Create New Client:
    • Client ID: strapi-admin
    • Access Type: Confidential
    • Root URL: https://your-strapi-instance.com/admin
  • Save the client, then go to the Credentials tab and copy:
    • Client Secret
    • Client ID

2️⃣ Configure Admin Roles

  • Go to RolesCreate Role
    • Role: STRAPI_ADMIN (This will map to Strapi Super Admin by default)
  • Assign this role to Keycloak users who should have Strapi Super Admin access.

🔐 Role-Based Access Control (RBAC)

Strapi Keycloak Passport Plugin respects Strapi's native RBAC system.
It maps Keycloak roles to Strapi admin roles.

🛠 Managing Role Mappings

1️⃣ Go to: Admin Panel → Keycloak Plugin
2️⃣ Map Keycloak roles to Strapi admin roles.
3️⃣ Save the mapping.

🔄 Example Mapping:

| Keycloak Role | Strapi Role | |---------------------|------------------| | STRAPI_ADMIN | Super Admin (1) | | EDITOR | Editor (2) | | VIEWER | Viewer (3) |

📌 How Role Mapping Works

✅ If a Keycloak user logs in with STRAPI_ADMIN, they get Super Admin rights in Strapi.
✅ If no role mapping exists, they get assigned the default role (KEYCLOAK_PASSPORT_DEFAULT_ROLE_ID).


🔄 Authentication Flow

sequenceDiagram
  participant User
  participant Strapi
  participant Keycloak
  User->>Strapi: Request login (email + password)
  Strapi->>Keycloak: Authenticate via OAuth2
  Keycloak->>Strapi: Return Access Token
  Strapi->>Keycloak: Fetch User Info
  Strapi->>Strapi: Find/Create Admin User
  Strapi->>User: Return JWT Token

Admin logs in once → session persists, no re-authentication needed on every request.


📜 API Endpoints

| Method | Endpoint | Description | Auth Required | |--------|---------|-------------|--------------| | POST | /admin/login | Authenticate admin via Keycloak | ❌ No | | GET | /keycloak-roles | Fetch available Keycloak roles | ✅ Yes | | GET | /get-keycloak-role-mappings | Get saved role mappings | ✅ Yes | | POST | /save-keycloak-role-mappings | Save new role mappings | ✅ Yes |


🚀 Next-Level Security

| Feature | Status | |---------|--------| | ✅ OAuth2 Authentication | ✔ Enabled | | ✅ Session-Based Persistence | ✔ Secure | | ✅ Role-Based Access Control (RBAC) | ✔ Strapi Admin Integration | | ✅ Middleware Protection | ✔ Only Authorized Users Access APIs |


🎯 Final Command to Rule Them All

yarn develop

🔥 Your Strapi is now fully Keycloak-powered! 🔥