A Seneca.js Auth Plugin
A user authentication plugin, using PassportJS for Express and Bell for Hapi.
![]() |
This open source module is sponsored and supported by Voxgig. |
|---|
- Install
- Migration guide
- Plugins and modules
- Note about node version support
- Options deprecated or no longer supported
- Restrict Login
- JSON API and Redirects
- API
- Example of using seneca-auth with Hapi
- Test
Lead Maintainers: Mircea Alexandru and Mihai Dima
For a gentle introduction to Seneca itself, see the senecajs.org site.
If you're using this plugin module, feel free to contact me on twitter if you have any questions! :) @rjrodger
Supports Seneca versions 1.x - 3.x
npm install seneca-authvar seneca = require('seneca')()
seneca.use('user')
seneca.use('entity')
seneca.use('auth')var _ = require('lodash')
var Chairo = require('chairo')
var Hapi = require('hapi')
var Bell = require('bell')
var Hapi_Cookie = require('hapi-auth-cookie')
var server = new Hapi.Server()
server.connection({port: 3000})
server.register([Hapi_Cookie, Bell, Chairo], function (err) {
var si = server.seneca
si.use('user')
si.use('entity')
si.use(
require('seneca-auth'),
{
secure: true,
restrict: '/api'
}
)
si.add({role: 'test', cmd: 'service'}, function (args, cb) {
return cb(null, {something: 'else'})
})
si.act({
role: 'web',
plugin: 'test',
use: {
prefix: '/api',
pin: {role: 'test', cmd: '*'},
map: {
service: {GET: true}
}
}
}, function(err){
server.start(function () {
console.log(server.info.uri)
})
})
})See the user accounts example or seneca-mvp example for more complete usage examples.
Disable default plugins by setting the flags on options.default_plugins to false.
For example, if you want to use auth-token-header
instead of auth-token-cookie:
seneca.use(require('seneca-auth', {
default_plugins: { authTokenCookie: false }
}))
seneca.use(require('auth-token-header'))This plugin provides user authentication for Seneca-based applications, supporting PassportJS for Express and Bell for Hapi frameworks.
A large part of the internal functionality is implemented as external plugins:
| Functionality | Loaded by default | Plugin |
|---|---|---|
| Local strategy auth | Yes | seneca-local-auth |
| Facebook strategy auth | No | seneca-facebook-auth |
| Github strategy auth | No | seneca-github-auth |
| Google strategy auth | No | seneca-google-auth |
| LinkedIn strategy auth | No | seneca-linkedin-auth |
| Twitter strategy auth | No | seneca-twitter-auth |
| Redirect | Yes | auth-redirect |
| Cookie token | Yes | auth-token-cookie |
| Header token | No | auth-token-header |
| Url matcher | Yes | auth-urlmatcher |
| Restrict Login | No | auth-restrict-login |
Hapi is supported only if using node 4 or greater. When using node 0.1x only Express is supported.
Some options are no longer supported:
service- the service array is no longer supported. Auth strategies plugins must be loaded explicitly.sendemail- the send email option is no longer supported.email- see above.
Some options are deprecated:
tokenkey- now an option for auth-token-cookie or auth-token-header.
If you have any questions, open an issue or contact the Senecajs team.
Different conditions for login can be added by overriding the default behavior of seneca action with pattern role: 'auth', restrict: 'login'.
This function must return:
{ ok: true }if login is allowed{ ok: false, why: 'reason' }if login is not allowed
See auth-restrict-login for an example.
Login an existing user and set a login token.
- default url path:
/auth/login - options property:
urlpath.login
Logout an existing user with an active login.
- default url path:
/auth/logout - options property:
urlpath.logout
Get the details of an existing, logged in user.
- default url path:
/auth/user - options property:
urlpath.user
Register a user and login automatically.
- default url path:
/auth/register - options property:
urlpath.register
Create a reset token.
- default url path:
/auth/create_reset - options property:
urlpath.create_reset
Load a user entity using a reset token.
- default url path:
/auth/load_reset - options property:
urlpath.load_reset
Execute a password reset action.
- default url path:
/auth/execute_reset - options property:
urlpath.execute_reset
Update user data.
- default url path:
/auth/update_user - options property:
urlpath.update_user
Change user password.
- default url path:
/auth/change_password - options property:
urlpath.change_password
The redirect functionality is implemented as a separate module. See auth-redirect for details.
The Senecajs org encourages open participation. If you feel you can help in any way, be it with documentation, examples, extra testing, or new features please get in touch.
npm testThis plugin was created to provide standardized authentication for the Seneca microservices framework. It is part of the Voxgig open source initiative.
Copyright (c) 2012 - 2016, Richard Rodger and other contributors. Licensed under MIT.


