Skip to main content
skill CX Codex

auth0-authentication — Claude Code skill: Auth0 rules

A skill that gives your coding agent Auth0 guidelines: auth flows, Actions, token validation and redirect safety.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add Mindrally/skills --skill auth0-authentication -a claude-code
Open on GitHub

What auth0-authentication does

This skill turns the assistant into an Auth0 reference. It covers environment variables, Authorization Code Flow with PKCE for SPAs and native apps, the server-side flow via express-openid-connect, Actions instead of the old Rules, access and refresh token handling, MFA, and error handling.

There is a section on what to avoid: keeping tokens in localStorage without weighing XSS, validating tokens only on the client, hardcoding client_secret in frontend code, logging out without ending the Auth0 session. The implicit flow is called deprecated outright.

You need AUTH0_DOMAIN, AUTH0_CLIENT_ID, AUTH0_CLIENT_SECRET, AUTH0_AUDIENCE, AUTH0_CALLBACK_URL and AUTH0_LOGOUT_URL in environment variables — the skill insists secrets stay out of code. Action secrets hold the sensitive values used inside Actions. External calls inside an Action add login latency, so the guidance is to keep them few and set short timeouts.

What it helps with

  • pick an auth flow for an SPA, native or server-side app
  • validate access tokens and required scopes on the backend
  • migrate Rules to Actions without breaking login
  • close gaps in redirect URIs, sessions and token storage
  • add MFA for sensitive operations

Example prompts for the agent

  • Review my Auth0 setup for an SPA — do I need PKCE, and where am I storing tokens?
  • Convert this Auth0 Rule into an Action and cut the external calls
  • Set up JWT validation and the read:messages scope for my Express routes

How to install auth0-authentication

1Skills CLI (Vercel)

npx skills add Mindrally/skills --skill auth0-authentication -a claude-code

2Manually: put the files in place

~/.claude/skills/auth0-authentication/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/auth0-authentication/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about auth0-authentication

How do I install auth0-authentication in Claude?

Run npx skills add Mindrally/skills --skill auth0-authentication -a claude-code. The skill file then lives at ~/.claude/skills/auth0-authentication/SKILL.md.

What does auth0-authentication do?

It hands the agent a set of Auth0 implementation rules: auth flows, Actions, token management, MFA and common security mistakes.

Do I need the Auth0 MCP server?

The skill mentions the Auth0 MCP server for managing a tenant in natural language: npx @auth0/auth0-mcp-server init --client cursor. The guidelines themselves work without it.

Source text

SKILL.md · Apache-2.0
---
name: auth0-authentication
description: Guidelines for implementing Auth0 authentication with best practices for security, rules, actions, and SDK integration
metadata:
  maintainer: Mindrally
  source: https://github.com/Mindrally/skills
---

# Auth0 Authentication

You are an expert in Auth0 authentication implementation. Follow these guidelines when working with Auth0 in any project.

## Core Principles

- Always use HTTPS for all Auth0 communications and callbacks
- Store sensitive configuration (client secrets, API keys) in environment variables, never in code
- Implement proper error handling for all authentication flows
- Follow the principle of least privilege for scopes and permissions

## Environment Variables

```bash
# Required Auth0 Configuration
AUTH0_DOMAIN=your-tenant.auth0.com
AUTH0_CLIENT_ID=your-client-id
AUTH0_CLIENT_SECRET=your-client-secret
AUTH0_AUDIENCE=your-api-audience
AUTH0_CALLBACK_URL=https://your-app.com/callback
AUTH0_LOGOUT_URL=https://your-app.com
```

## Authentication Flows

### Authorization Code Flow with PKCE (Recommended for SPAs and Native Apps)

Always use PKCE for public clients:

```javascript
import { Auth0Client } from '@auth0/auth0-spa-js';

const auth0 = new Auth0Client({
  domain: process.env.AUTH0_DOMAIN,
  clientId: process.env.AUTH0_CLIENT_ID,
  authorizationParams: {
    redirect_uri: window.location.origin,
    audience: process.env.AUTH0_AUDIENCE,
  },
  cacheLocation: 'localstorage', // Use 'memory' for higher security
  useRefreshTokens: true,
});
```

### Authorization Code Flow (Server-Side Applications)

```javascript
// Express.js example
const { auth } = require('express-openid-connect');

app.use(
  auth({
    authRequired: false,
    auth0Logout: true,
    secret: process.env.AUTH0_SECRET,
    baseURL: process.env.BASE_URL,
    clientID: process.env.AUTH0_CLIENT_ID,
    issuerBaseURL: `https://${process.env.AUTH0_DOMAIN}`,
  })
);
```

## Auth0 Actions Best Practices

Actions have replaced Rules. Follow these guidelines:

### Action Structure

```javascript
exports.onExecutePostLogin = async (event, api) => {
  // 1. Early returns for efficiency
  if (!event.user.email_verified) {
    api.access.deny('Please verify your email before logging in.');
    return;
  }

  // 2. Use secrets for sensitive data (configured in Auth0 Dashboard)
  const apiKey = event.secrets.EXTERNAL_API_KEY;

  // 3. Minimize external calls - they affect login latency
  // 4. Never log sensitive information
  console.log(`User logged in: ${event.user.user_id}`);

  // 5. Add custom claims sparingly
  api.idToken.setCustomClaim('https://myapp.com/roles', event.authorization?.roles || []);
  api.accessToken.setCustomClaim('https://myapp.com/roles', event.authorization?.roles || []);
};
```

### Action Security Rules

- Store secrets in Action Secrets, never hardcode them
- Limit the data sent to external services - never send the entire event object
- Use short timeouts for external API calls (default 20-second limit)
- Implement proper error handling to avoid authentication failures

## Token Management

### Access Token Best Practices

```javascript
// Always validate tokens server-side
const { auth, requiredScopes } = require('express-oauth2-jwt-bearer');

const checkJwt = auth({
  audience: process.env.AUTH0_AUDIENCE,
  issuerBaseURL: `https://${process.env.AUTH0_DOMAIN}/`,
  tokenSigningAlg: 'RS256',
});

// Require specific scopes
const checkScopes = requiredScopes('read:messages');

app.get('/api/private-scoped', checkJwt, checkScopes, (req, res) => {
  res.json({ message: 'Protected resource' });
});
```

### Refresh Token Configuration

- Enable refresh token rotation
- Set appropriate token lifetimes (access tokens: 1 hour max, refresh tokens: based on risk)
- Implement automatic token refresh in your client

## Security Best Practices

### CSRF Protection

```javascript
// State parameter is automatically handled by Auth0 SDKs
// For custom implementations, always validate the state parameter
const state = generateSecureRandomString();
sessionStorage.setItem('auth0_state', state);
```

### Redirect URI Security

- Whitelist all redirect URIs in Auth0 Dashboard
- Use exact string matching for redirect URIs
- Never use wildcard redirect URIs in production

### Session Management

```javascript
// Implement session timeouts
const sessionConfig = {
  absoluteDuration: 86400, // 24 hours
  inactivityDuration: 3600, // 1 hour of inactivity
};
```

## Multi-Factor Authentication

```javascript
// Enforce MFA for sensitive operations
exports.onExecutePostLogin = async (event, api) => {
  // Check if MFA has been completed
  if (!event.authentication?.methods?.find(m => m.name === 'mfa')) {
    // Trigger MFA challenge
    api.authentication.challengeWithAny([
      { type: 'otp' },
      { type: 'push-notification' },
    ]);
  }
};
```

## Error Handling

```javascript
try {
  await auth0.loginWithRedirect();
} catch (error) {
  if (error.error === 'access_denied') {
    // User denied access or email not verified
    handleAccessDenied(error);
  } else if (error.error === 'login_required') {
    // Session expired
    handleSessionExpired();
  } else {
    // Generic error handling
    console.error('Authentication error:', error.message);
    showUserFriendlyError();
  }
}
```

## MCP Integration

Auth0 provides an MCP server for AI-assisted development:

```bash
# Initialize Auth0 MCP server for Cursor
npx @auth0/auth0-mcp-server init --client cursor
```

This enables natural language Auth0 management operations within your IDE.

## Testing

- Use Auth0's test users for development
- Implement integration tests for authentication flows
- Test token expiration and refresh scenarios
- Verify MFA flows in staging environments

## Common Anti-Patterns to Avoid

1. Storing tokens in localStorage without considering XSS risks
2. Not validating tokens on the server side
3. Using the implicit flow (deprecated)
4. Hardcoding client secrets in frontend code
5. Not implementing proper logout (both local and Auth0 session)
6. Ignoring token expiration in API calls
7. Storing too much data in user metadata

© Mindrally · Apache-2.0 · Mindrally/skills

Similar skills

All skills for Security →

From the same set214

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor