npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hapi-auth-cookie-redis

v2.0.0

Published

Redis authentication cookie plugin

Downloads

6

Readme

hapi-auth-cookie-redis

Redis authentication provides simple session management. The user has to be authenticated via other means, typically a RESTful API, and upon successful authentication the browser receives an authentication cookie.

Subsequent requests containing the cookie are authenticated and validated via the provided validateFunc in case the user info requires validation on each request.

Quick Start

Installation

npm install --save hapi-auth-cookie-redis

Configuration

The 'redis' scheme takes the following required options:

  • param - the Redis root key for session data storage. Defaults to 'auth'. Change it to something more app-dependent if you have more applications on the same redis instance.
  • host - the redis server host. Defaults to '127.0.0.1'
  • port - the redis server port. Defaults to 6379
  • db - the default redis db. Defaults to 0
  • password - the redis auth_pass. Defaults to ''
  • cookie - the cookie name stored on the client browser. Defaults to 'auth'
  • ttl - login expire time. Defaults to 3600 (seconds), -1 for never, DO NOT use 0
  • validateFunc - an optional session validation function used to validate the auth token on each request. Used to verify that the internal session state is still valid (e.g. user account still exists). The function has the signature function(request, session, callback) where:
    • request - is the Hapi request object of the request which is being authenticated.
    • session - is the session object set via request.auth.redis.set(user).
    • callback - a callback function with the signature function(err, isValid, credentials) where:
      • err - an internal error.
      • isValid - true if the content of the session is valid, otherwise false.
      • credentials - a credentials object passed back to the application in request.auth.credentials. If value is null or undefined, defaults to session. If set, will override the current session as if request.auth.redis.set(user) was called.

When the redis scheme is enabled on a route, the request.auth.redis objects is decorated with the following methods:

  • set(value) - sets a specific object on the current session where value is a json object containing all the info about the logged user
  • expire() - clears the current session

Run the example

npm install 
node example/server

Then visit: http://localhost:3000/example-one

Routes:

  • POST /login

email and password required.

Available Users:

[
  {
    id: 123,
    email: '[email protected]',
    password: 'admin',
    scope: ['user', 'admin', 'user-123']
  },
  {
    id: 124,
    email: '[email protected]',
    password: 'guest',
    scope: ['user', 'user-124']
  },
  {
    id: 125,
    email: '[email protected]',
    password: 'other',
    scope: ['user', 'user-125']
  }
]
  • GET /logout

  • GET /example-one

No required authorization.

  • GET /example-two

User required authorization

  • GET /example-three

Admin required authorization because the default is admin.

  • GET /example-four/{id}

User specific authorization required.