@feathersjs/authentication package provides server-side authentication through the AuthenticationService and various hooks and utilities.
Installation
AuthenticationService
The main authentication service that extendsAuthenticationBase and implements JWT-based authentication.
Constructor
Application
required
The Feathers application instance
string
default:"authentication"
The configuration key name in
app.getobject
Optional initial configuration options
Methods
create
Create and return a new JWT for a given authentication request. Triggers thelogin event.
AuthenticationRequest
required
The authentication request (must include
strategy key)AuthenticationParams
Service call parameters
string
The generated JWT access token
object
Authentication metadata including strategy and decoded payload
object
The authenticated entity (e.g., user object) if entity lookup is configured
remove
Mark a JWT as removed. By default only verifies the JWT and returns the result. Triggers thelogout event.
string | null
required
The JWT to remove or null. When an id is passed, it must match the
accessToken in params.authenticationAuthenticationParams
Service call parameters with authentication information
register
Register a new authentication strategy.string
required
The name to register the strategy under
AuthenticationStrategy
required
The authentication strategy instance
getStrategy
Returns a single strategy by name.string
required
The strategy name
createAccessToken
Create a new access token with payload and options.string | Buffer | object
required
The JWT payload
SignOptions
Options to extend the defaults (
configuration.jwtOptions)Secret
Use a different secret instead of the configured one
verifyAccessToken
Verify an access token.string
required
The token to verify
JwtVerifyOptions
Verification options
Secret
Use a different secret for verification
Properties
configuration
Returns the current authentication configuration.strategyNames
A list of all registered strategy names.Configuration
Configure authentication in your Feathers app configuration:string
required
The secret used to sign and verify JWTs. Keep this secure!
string[]
required
Array of allowed authentication strategy names
object
JWT signing options
header: JWT header (default:{ typ: 'access' })audience: The resource server where the token is processedissuer: The issuing server, application or resource (default: ‘feathers’)algorithm: Signing algorithm (default: ‘HS256’)expiresIn: Expiration time (default: ‘1d’)
string
The path of the entity service (e.g., ‘users’)
string
The name of the entity (default: ‘user’)
string
The id field of the entity service. Auto-detected if not provided
Hooks
authenticate
Protect service methods by requiring authentication.string | AuthenticateHookSettings
required
Strategy name(s) or settings object
string[]
Additional strategy names (when settings is a string)
JWTStrategy
The built-in JWT authentication strategy.Configuration
string
default:"Authorization"
The HTTP header to parse for the JWT
string[]
default:"['Bearer', 'JWT']"
Allowed authentication schemes
string
The entity service path (inherited from main auth config)
string
The entity name (inherited from main auth config)
string
The entity id field (inherited from main auth config)
AuthenticationBaseStrategy
Base class for creating custom authentication strategies.Methods to Implement
authenticate
Authenticate an authentication request with this strategy.parse (optional)
Parse a basic HTTP request for authentication information.handleConnection (optional)
Update a real-time connection according to this strategy.Events
The authentication service emits the following events:login
Emitted when a user successfully authenticates (aftercreate).
logout
Emitted when a user logs out (afterremove).