4.0.6 • Published 8 months ago

hapi-saml2 v4.0.6

Weekly downloads
98
License
MIT
Repository
github
Last release
8 months ago

hapi-saml2

hapi-saml2 is a hapi.js plugin, it uses node-saml library to provide Single Sign On using SAML protocol

Notes

This plugin based on node-saml and was originally inspired by hapi-saml-sso.

Check the documentation of the repository for options documentation

Versions

node-saml version

hapi-saml2 versiondependency version
4.0.5 - 4.0.6@node-saml/node-saml@4.0.5
4.0.3 - 4.0.4@node-saml/node-saml@4.0.3
3.2.2 - 3.2.2passport-saml@3.2.1
3.2.0 - 3.2.1passport-saml@3.2.0
2.2.0 - 2.2.0passport-saml@2.2.0
2.0.2 - 2.0.3passport-saml@2.0.2
1.3.5 - 1.3.8passport-saml@1.3.5

@hapi/hapi supported versions

hapi-saml2 versionhapi.js supported version
1.0.0 - latestv18 - v21
0.0.1 - 0.0.5v17

Usage

Add hapi-saml2 to your project:

npm install hapi-saml2 --save

Register the plugin and configure it with the options:

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) => {}, // required. should return options for `node-saml`
      login: async (request, identifier, user) => {}, // required. should return true if user is authenticated and authenticate user based on identifier (Profile.nameID is used), 
      // or return an object { success: Boolean, errorMessage: String } to sent an error message to postResponseValidationErrorHandler(if implemented)
      logout: async (request) => {}, // required. should logout the user on the app
      apiPrefix: '/saml', // prefix for added routes
      redirectUrlAfterSuccess: '/', // url to redirect to after successful login
      redirectUrlAfterFailure: '/', // url to redirect to after failed login
      boomErrorForMissingConfiguration: Boom.badImplementation('SAML instance is not configured'), // Boom error to throw on missing configuration error
      boomErrorForIncorrectConfiguration: Boom.badImplementation('SAML configuration is incorrect'), // Boom error to throw on incorrect configuration error
      postResponseValidationErrorHandler: async ({ request, h, e }) => { return h.redirect('/errorPage') } // function to handle Post Response validation errors
    }
  })

  await server.start()
}

init()

The plugin provides the following SSO API:

GET  /saml/metadata.xml
GET  /saml/login
GET  /saml/logout
POST /saml/callback

They can be configured with apiPrefix option.

Testing

First, install the following dev-dependencies:

yarn add -D @hapi/hapi
yarn add -D @hapi/boom

Then run yarn test.

4.0.5

8 months ago

4.0.6

8 months ago

4.0.4

1 year ago

4.0.3

1 year ago

3.2.2

2 years ago

3.2.1

3 years ago

3.2.0

3 years ago

2.2.0

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

1.3.8

3 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.0.2

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago