Registry / auth-security / hapi-saml2

hapi-saml2

JSON →
library5.1.3jsnpmunverified

hapi-saml2 is a Hapi.js plugin providing SAML-based Single Sign On via the node-saml library. Version 5.1.3 is current stable. It supports @hapi/hapi v18-v21, and requires @hapi/boom >=7.2.0 as a peer dependency. Key differentiators: built specifically for Hapi.js ecosystem (inline with Hapi's plugin architecture), replaces older passport-saml dependency with modern node-saml, and offers customizable route prefixes and handler hooks (preLogin, postResponseValidationErrorHandler). Release cadence: occasional updates to match node-saml releases.

npm install hapi-saml2
INSTALL
IMPORT
SIG · HAPI-SAML2
H
hapi-saml2
auth-securityjavascriptv5.1.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const Hapi = require('@hapi/hapi'); const plugin = require('hapi-saml2'); await server.register({ plugin, options })
import Hapi from '@hapi/hapi' (ESM may not work if Hapi is CommonJS)
Package is CommonJS only; use require() with @hapi/hapi (CommonJS) to avoid interop issues.
plugin options (getSAMLOptions, login, logout)
options: { getSAMLOptions: (request) => { return { entryPoint: '...', cert: '...' }; }, login: async (request, identifier, user) => { return true; }, logout: async (request) => { } }
options: { samlOptions: { ... } } (no such top-level key; saml config must be returned from getSAMLOptions)
getSAMLOptions is a function that must return node-saml options; it is called per request to allow dynamic configuration.
login callback
login: async (request, identifier, user) => { return true; }
login: async (request, identifier, user) => { /* no return */ } (must return boolean or { success: boolean, errorMessage?: string })
Return true to authenticate; return object with success: false to trigger postResponseValidationErrorHandler.

Registers the hapi-saml2 plugin with required callbacks and dynamic SAML options from environment variables.

const Hapi = require('@hapi/hapi'); const server = Hapi.server({ port: 3000, host: 'localhost' }); const init = async () => { await server.register({ plugin: require('hapi-saml2'), options: { getSAMLOptions: (request) => ({ entryPoint: process.env.SAML_ENTRY_POINT ?? 'https://idp.example.com/ssos', cert: process.env.SAML_CERT ?? '', issuer: 'http://localhost:3000', callbackUrl: 'http://localhost:3000/saml/callback' }), login: async (request, identifier, user) => { // After SAML response validation, identifier is the NameID console.log(`User ${identifier} logging in`); return true; }, logout: async (request) => { // Implement logout logic, e.g., clear session console.log('User logged out'); }, redirectUrlAfterSuccess: '/dashboard', redirectUrlAfterFailure: '/login' } }); await server.start(); console.log('Server running on %s', server.info.uri); }; init().catch(console.error);
Debug
Known issues
breakingVersion 5.x replaced passport-saml with @node-saml/node-saml. Callback signatures changed: login now receives (request, identifier, user) instead of the old passport-based signature.
fix
Update login callback to accept (request, identifier, user) and return boolean or object.
affects: >=5.0.0
breakingRemoved samlOptions top-level config. Use getSAMLOptions function instead.
fix
Move SAML configuration into getSAMLOptions function that returns node-saml options.
affects: >=5.0.0
deprecatedOptions like 'issuer', 'callbackUrl' directly in options root were removed. Must be inside getSAMLOptions return.
fix
Place all SAML-specific options inside the object returned by getSAMLOptions.
affects: >=5.0.0 <6.0.0
gotchaThe plugin requires @hapi/hapi v18 or later. Hapi v17 is not supported (will throw on register).
fix
Upgrade @hapi/hapi to v18+ (tested up to v21).
affects: >=1.0.0
gotchaThe plugin modifies server routes automatically. If apiPrefix collides with existing routes, registration fails silently with Boom.conflict.
fix
Ensure apiPrefix (default '/saml') is not already used by other plugins or routes.
affects: >=5.0.0
Errors
Common errors & fixes
Error: SAML instance is not configured
getSAMLOptions returned undefined or threw inside the function.
fix
Ensure getSAMLOptions always returns an object with required node-saml properties (entryPoint, cert, etc.).
AssertionError: login must be a function
Login option is missing or not a function in plugin options.
fix
Add login: async (request, identifier, user) => { return true; } to options.
TypeError: Cannot destructure property 'nameID' of 'user' as it is undefined
user parameter in login callback is undefined if SAML response lacks expected profile attributes.
fix
Check that Identity Provider sends NameID; use identifier (string) instead of user properties if only NameID is needed.
Upgrade
Version history
5.1.3latest on npm
Audit
Dependencies
@hapi/boomrequiredpeer dependency for HTTP-friendly error objects used in configuration error handling and SAML failures
Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
hapi-saml2 — npm install hapi-saml2 · libregistry