Skip to main content
Feathers authentication provides a flexible, secure system for managing user authentication in your application. It supports multiple authentication strategies including JWT, local username/password, and OAuth providers.

Core Architecture

The authentication system is built around the AuthenticationService which manages:
  • Authentication strategies - Pluggable methods for authenticating users (JWT, local, OAuth)
  • JWT token management - Creating and verifying access tokens
  • Real-time connection handling - Managing authenticated WebSocket connections
  • HTTP request parsing - Extracting authentication from HTTP headers

Installation

Basic Setup

1

Configure Authentication

Set up authentication in your application configuration:
2

Create Authentication Service

Register the authentication service in your application:
3

Protect Routes

Use the authenticate hook to protect your services:

Configuration Options

The authentication service accepts the following configuration options:

Required Options

Optional Options

JWT Options

Supported algorithms: HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512

Authentication Flow

1

Client Login Request

Client sends credentials to the authentication service:
2

Strategy Validation

The authentication service:
  1. Validates the strategy is allowed (in authStrategies)
  2. Calls the strategy’s authenticate() method
  3. Strategy validates credentials and returns user entity
3

JWT Creation

The service creates a JWT access token:
  • Calls getPayload() to build token payload
  • Calls getTokenOptions() to set token options (subject, expiration)
  • Signs the token with the configured secret
4

Return Authentication Result

Returns the authentication result:

Using the authenticate Hook

The authenticate hook protects service methods by requiring authentication:

Accessing Authenticated User

After successful authentication, the user entity is available in params:

Real-time Connection Management

The authentication system automatically manages WebSocket connections:

Security Best Practices

Keep your secret secure! Never commit your JWT secret to version control. Use environment variables:

Recommendations

  1. Use strong secrets - Generate a cryptographically secure random string (at least 32 characters)
  2. Set appropriate token expiration - Balance security and user experience (1d for web, 30d for mobile)
  3. Use HTTPS in production - Always transmit tokens over secure connections
  4. Rotate secrets periodically - Implement a key rotation strategy
  5. Validate token audience - Ensure tokens are used for the intended application
  6. Use refresh tokens - Implement refresh token rotation for long-lived sessions

Custom Token Payload

Extend the getPayload method to add custom claims:

Custom Token Options

Customize token options per request:

Logging Out

Remove authentication (triggers logout event):

Events

The authentication service emits events during the authentication lifecycle:
  • login - After successful authentication
  • logout - After successful logout
  • disconnect - When a real-time connection closes

Next Steps

JWT Strategy

Learn about JWT token authentication

Local Strategy

Implement username/password authentication

OAuth Strategy

Add social login with OAuth providers