Medusa security

From OrcaQubits/agentic-commerce-skills-plugins · View interactive version

Medusa security is an AI agent skill from the GitHub repository OrcaQubits/agentic-commerce-skills-plugins. Secure Medusa v2 applications — authentication strategies, API key types (publishable vs secret), CORS configuration, JWT and cookie secrets, admin vs store auth, and session management. Use when configuring security.

How to use this skill

Skill file

Medusa v2 Security

Before writing code

Fetch live docs:

  1. Web-search site:docs.medusajs.com authentication for auth strategies and API key setup
  2. Web-search site:docs.medusajs.com api key publishable secret for API key types
  3. Web-search site:docs.medusajs.com CORS configuration for cross-origin resource sharing
  4. Fetch https://docs.medusajs.com/learn/fundamentals/api-routes/middlewares for middleware and auth config
  5. Web-search site:docs.medusajs.com medusa-config auth providers for auth provider registration

Authentication Architecture

Admin vs Store Authentication

Medusa v2 separates admin and storefront authentication into distinct flows:

| Aspect | Admin Auth | Store Auth |

|--------|-----------|------------|

| Actor type | user | customer |

| API scope | /admin/* routes | /store/* routes |

| Default provider | emailpass | emailpass |

| Session cookie | Admin session cookie | Store session cookie |

| API key support | Secret API key (Bearer) | Publishable API key (header) |

| JWT usage | Admin JWT token | Customer JWT token |

| Middleware | authenticate("user", ...) | authenticate("customer", ...) |

Auth Provider System

Auth Module
├── emailpass    — email + password (default)
├── google       — OAuth 2.0 via Google
├── github       — OAuth 2.0 via GitHub
└── custom       — implement AbstractAuthModuleProvider

Auth providers are registered in medusa-config.ts under the auth module configuration. Each provider handles a specific identity verification strategy.

API Key Types

| Key Type | Header | Purpose | Visibility |

|----------|--------|---------|------------|

| Publishable | x-publishable-api-key | Storefront API access, scopes to sales channels | Safe for client-side |

| Secret | Authorization: Bearer <key> | Admin API access, full permissions | Server-side only |

CORS Configuration

Configure CORS in medusa-config.ts under projectConfig:

| Setting | Purpose | Example |

|---------|---------|---------|

| storeCors | Allowed origins for Store API | http://localhost:8000 |

| adminCors | Allowed origins for Admin API | http://localhost:9000 |

| authCors | Allowed origins for Auth routes | http://localhost:8000,http://localhost:9000 |

JWT and Cookie Secrets

Secret Configuration

| Secret | Environment Variable | Purpose |

|--------|---------------------|---------|

| Cookie secret | COOKIE_SECRET | Signs session cookies |

| JWT secret | JWT_SECRET | Signs JSON Web Tokens |

| Admin JWT | Configured per auth provider | Admin token signing |

| Store JWT | Configured per auth provider | Customer token signing |

Session Management

Sessions are managed via HTTP-only cookies with configurable options:

API Route Authentication

Middleware Configuration

Apply auth middleware in src/api/middlewares.ts:

// Fetch live docs for authenticate() middleware
// signature and actor type options
import { authenticate } from "@medusajs/medusa"

| Middleware Function | Actor Type | Use Case |

|-------------------|-----------|----------|

| authenticate("user", ...) | Admin user | Admin-only routes |

| authenticate("customer", ...) | Customer | Store auth-required routes |

| authenticate("user", ["bearer","session"]) | Admin | Multiple auth strategies |

Auth Scopes on Custom Routes

Auth Provider Implementation

Custom auth providers extend AbstractAuthModuleProvider:

// Fetch live docs for AbstractAuthModuleProvider
// methods: authenticate, register, validateCallback

| Method | Purpose |

|--------|---------|

| authenticate() | Verify identity (login) |

| register() | Create new identity |

| validateCallback() | Handle OAuth redirect callbacks |

Security Hardening Checklist

Environment Variables

Network and Transport

API Keys and Access

Session and Token Security

Best Practices

Fetch the Medusa authentication and security documentation for exact provider registration syntax, middleware options, and cookie configuration before implementing.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.