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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ymys/directus-extension-sso

v2.3.14

Published

Mobile OAuth proxy endpoints for Directus + Keycloak + Google + Apple

Downloads

1,021

Readme

Directus SSO - Mobile & Web OAuth Proxy

This extension provides optimized OAuth callback and logout endpoints for Directus, supporting both Mobile App Deep Linking and Web Browser SSO (Single Sign-On) with automatic detection.

🚀 Features

  • Unified Callbacks: Handle both Keycloak and Google OAuth redirects in one place.
  • Smart Detection: Automatically detects if the request comes from a mobile app or a web browser.
  • Resilient Authentication:
    • Cookie Brute-Force: Tries multiple session cookies to handle domain conflicts.
    • Mega Brute-Force: Scans all cookies for valid JWT tokens if named lookups fail.
    • Refresh Fallback: Automatically attempts to use refresh tokens if the session is expired.
  • Dynamic Deep Linking: Support for multi-tenant mobile apps via app_scheme and app_path parameters.
  • Seamless Logout: Terminate both Directus and Keycloak sessions simultaneously.

📦 Installation

  1. Copy to extensions folder: Ensure this project is in your Directus extensions/endpoints/sso directory.

  2. Install dependencies & build:

    npm install
    npm run build
  3. Restart Directus: The extension will be loaded automatically.

🔌 Endpoints

  • Health Check: GET /sso/health
  • Keycloak Callback: GET /sso/mobile-callback
  • Google Callback: GET /sso/google-callback
  • Logout Proxy: POST /sso/mobile-logout

⚙️ Configuration

Add these variables to your Directus .env file:

# Directus Public URL
PUBLIC_URL=https://directus.example.com

# Keycloak Configuration
KEYCLOAK_URL=https://keycloak.example.com
KEYCLOAK_REALM=production
KEYCLOAK_CLIENT_ID=admin-cli
KEYCLOAK_ADMIN_USER=admin
KEYCLOAK_ADMIN_PASSWORD=your-password

# Mobile App Defaults
MOBILE_APP_SCHEME=myapp
MOBILE_APP_CALLBACK_PATH=/auth/callback
GOOGLE_CALLBACK_PATH=/auth/callback/google

# Web SSO Settings
COOKIE_DOMAIN=.example.com
COOKIE_SECURE=true
COOKIE_SAME_SITE=lax
SESSION_COOKIE_NAME=directus_session_token
REFRESH_TOKEN_COOKIE_NAME=directus_refresh_token
DEFAULT_ROLE_ID=your-default-role-uuid

# Apple Configuration
# Supports single ID or comma-separated list for multi-app setups
APPLE_CLIENT_ID=net.goyong.irapat,com.finsnapmobile.app

🍎 Apple Authentication Note

Unlike Google (which uses Directus's native settings), the Apple Native Token Flow (/apple-token) manages user creation within this extension.

  • Multiple Client IDs: You can specify multiple bundle IDs in APPLE_CLIENT_ID as a comma-separated list. This is useful if you have multiple mobile apps using the same backend.
  • Permissions: You must provide a DEFAULT_ROLE_ID in your environment variables to ensure new Apple users are assigned the correct permissions.

📱 Mobile Usage

In your mobile app (e.g., React Native / Expo), point your OAuth login to Directus but use the proxy callbacks:

1. Keycloak Flow

const loginUrl = `${DIRECTUS_URL}/auth/login/keycloak?redirect_uri=${DIRECTUS_URL}/sso/mobile-callback`;

2. Google Flow

const loginUrl = `${DIRECTUS_URL}/auth/login/google?redirect_uri=${DIRECTUS_URL}/sso/google-callback`;

3. Dynamic App Redirection

If you have multiple apps or environments, you can override the scheme/path:

const loginUrl = `${DIRECTUS_URL}/auth/login/google?redirect_uri=${DIRECTUS_URL}/sso/google-callback&app_scheme=alternateapp&app_path=/custom/callback`;

🌐 Web SSO Usage

For browser-based apps, simply navigate to the login endpoints. The extension will set the appropriate cookies and redirect the user:

// Navigates to Directus login, then redirects back to your dashboard with session cookies set
window.location.href = `${DIRECTUS_URL}/auth/login/keycloak?redirect_uri=https://dashboard.example.com`;

🔐 Security Note

This extension facilitates session bridging. Ensure COOKIE_SECURE=true is used in production and COOKIE_DOMAIN is correctly scoped to your parent domain (e.g., .example.com) to enable SSO between subdomains.


Built with ❤️ for Directus.