New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

studio-ai-auth

Package Overview
Dependencies
Maintainers
0
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

studio-ai-auth

A Next.js middleware for handling authentication with Keycloak and JWT.

latest
npmnpm
Version
3.0.10
Version published
Maintainers
0
Created
Source

studio-ai-auth

A reusable Next.js middleware package for authentication and token validation. This package helps enforce authentication across multiple micro-frontends without code duplication.

🚀 Features

👉 JWT Token Decryption & Validation 👉 Automatic Redirection to Authentication if token is missing/invalid
👉 Configurable Public Routes (Define accessible routes without authentication)
👉 Reusable Across Micro-Frontends (Reduce redundant auth logic)
👉 Easy Integration with Next.js Middleware

📛 Installation

Install the package using npm:

npm i studio-ai-auth

or using yarn:

yarn add studio-ai-auth

** Environment Variables**

Ensure you have the required environment variables set in your .env.local file:

PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANB...\n-----END PRIVATE KEY-----"
PRIVATE_KEY="-----BEGIN PUBLIC KEY-----\nMIIEvQIBADSZANB...\n-----END PUBLiC KEY-----"
KEYCLOAK_ISSUER="https://keycloak.example.com/auth/realms/my-realm"
KEYCLOAK_CLIENT_ID="my-client-id"

🗜️ How It Works?

1️⃣ Extracts JWT from Cookies
2️⃣ Decrypts & Validates token (expiration, issuer, audience)
3️⃣ Allows or Redirects the request based on validation
4️⃣ Handles Public Routes (Allows users to access without authentication)

📀 Example Project Structure

/my-nextjs-app
 ├── /app
 │   ├── page.tsx
 │   ├── dashboard -> page.tsx
 │   ├── profile -> page.tsx
 ├── /middleware.ts  ← (Integrate middleware here)
 ├── /env.local      ← (Store private key & env variables)
 ├── /public
 ├── package.json
 ├── tsconfig.json

🛠️ Troubleshooting

Issue: Cannot find module 'node-jose'

Ensure you have the required dependencies installed:

npm i node-jose

Issue: 403 Forbidden - You do not have permission to publish

Check if you're logged into npm:

npm whoami

If not logged in, run:

npm login

📚 License

This project is licensed under the MIT License.

💡 Contributing

Want to improve this package? Open an issue or submit a PR! 😊

📩 Need Help?

If you have any issues, feel free to open an issue.

Keywords

auth

FAQs

Package last updated on 19 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts