hapi-micro-auth v4.0.1
Hapi plugin to expose micro-auth as an auth provider.
Installation
npm install hapi-micro-auth
or
yarn add hapi-micro-auth
Usage
In your server setup code:
await server.register({
plugin: require('../'),
options: {
host: 'http://localhost:8081/auth', // URL to micro-auth
routes: true
}
});
In rapptor:
plugins:
hapi-micro-auth:
verbose: true
host: '{{urls.auth.endpoint}}'
hostRedirect: '{{urls.auth.redirect}}'
cacheEnabled: false
redirectTo: '/login'
redirectOnTry: false
routes:
login: false
logout: '/logout'
cookie:
name: 'auth'
isSecure: false
ttl: 12960000000
clearInvalid: true
strategy:
name: 'microauth'
mode: 'try'
Plugin Configuration
The following options are available:
const defaults = {
verbose: false,
host: '',
hostRedirect: null,
queryKey: 'token',
cookie: {
name: 'token',
isSecure: false,
ttl: 1000 * 60 * 60 * 24 * 30, //30 days
clearInvalid: false
},
trackLastSession: true,
sessionDateCookie: {
name: 'lastSessionDateSet',
ttl: null,
isSecure: false,
isSameSite: 'Lax'
},
redirectOnTry: true,
redirectTo: false, // defaults to routes.login w/ host redirect
routes: {
login: '/login',
logout: '/logout',
hook: '/auth-hook'
},
hookSecret: false,
hookEventNamespace: 'microauth',
cacheEnabled: true,
cache: {
segment: 'microauth-sessions',
expiresIn: 1 * 60 * 60 * 1000, //1 hour
staleIn: 5 * 60 * 1000, //5 minutes
staleTimeout: 100,
generateTimeout: 5000
},
strategy: {
name: 'microauth',
mode: 'required'
},
noRedirect: false,
setDefault: true
};
Methods
All methods are accessible from server.microauth
async getMe(token)
Takes a user token and returns a user object or Boom.notFound()
.
Note: This is slightly different from getUser
in that it calls the /me
api endpoint which returns different information which isn't suitable for use when grabbing information for public display.
getTokenFromRequest(request)
Returns a token from a request.
async getUser(token)
Takes a user token and returns a user object or Boom.notFound()
.
async list(query)
Returns a list of users matching the supplied query. See the micro-auth docs for query params.
async updateLastSessionDate(token, userAgent)
This is called automatically if set in options.
async updateMeta(token, newMetadata)
Updates a user's meta object with the supplied newMetadata
.
async updateSettings(token, newSettings)
Updates a user's settings object with the supplied newSettings
.
A First + Third Project
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago