4.0.1 • Published 3 years ago

hapi-micro-auth v4.0.1

Weekly downloads
20
License
MIT
Repository
github
Last release
3 years ago

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

4.0.1

3 years ago

4.0.0

3 years ago

3.7.1

4 years ago

3.7.0

4 years ago

3.6.0

4 years ago

3.5.0

4 years ago

3.4.0

5 years ago

3.3.0

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.3.0

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago