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-couchdb-cookie

v3.1.0

Published

CouchDB Cookie authentication plugin

Downloads

12

Readme

hapi-auth-couchdb-cookie Build Status

hapi CouchDB Cookie authentication plugin, heavily inspired by hapi-auth-cookie.

CouchDB Cookie authentication provides authentication via a CouchDB. It checks the user credentials with a CouchDB and passes the Cookie from CouchDB to the user. All following requests can use the cookie for access. A validateFunc can be passed in, in case the cookie's content requires validation on each request. Note that cookie operates as a bearer token and anyone in possession of the cookie content can use it to impersonate its true owner.

Installation

npm install hapi-auth-couchdb-cookie --save

Usage

The Plugin works out of the box by just including it, if CouchDB runs on the default port. However, you can customize the behaviour with the properties noted below.

server.register(require('hapi-auth-couchdb-cookie'), function (err) {
  server.auth.strategy('session', 'couchdb-cookie', {});
});

Because this scheme decorates the request object with session-specific methods, it cannot be registered more than once.

Options

redirectTo

Type String | Default false

Optional login URI to redirect unauthenticated requests to. Note that using redirectTo with authentication mode 'try' will cause the protected endpoint to always redirect, voiding 'try' mode. To set an individual route to use or disable redirections, use the route plugins config ({ config: { plugins: { 'hapi-auth-couchdb-cookie': { redirectTo: false } } } }).

appendNext

Type String|Boolean | Default false

If true and redirectTo is true, appends the current request path to the query component of the redirectTo URI using the parameter name 'next'. Set to a string to use a different parameter name. Defaults to false.

getNextValue

Type function | Default undefined

If redirectTo and appendNext are true and it is a function, getNextValue gets called with the request object as the only parameter. It should return a String that is used as the value of either 'next' or the String set as appendNext in the url for the redirect.

redirectOnTry

Type Boolean | Default true

If false and route authentication mode is 'try', authentication errors will not trigger a redirection. Requires hapi version 6.2.0 or newer.

couchdbUrl

Type String | Default http://localhost:5984

URL of the CouchDB to authenticate to.

validateFunc

Type Function | Default function() {}

An optional session validation function used to validate the content of the session cookie 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(session, callback) where:

  • session - is the session object set via request.auth.session.set().
  • callback - a callback function with the signature function(error, isValid, credentials) where:
    • error - 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 cookie as if request.auth.session.set() was called.

request.auth.session.authenticate(username, password, callback)

Call this to authenticate against CouchDB. Takes three params.

username

Type String | No default

The username to authenticate

password

Type String | No default

The password of the user to authenticate

callback

Type function | No default

Called when the authentication took place with to params:

  • error An optional error object containing the reason (most likely unauthenticated)
  • credentials The credentials from CouchDB

request.auth.session.clear()

Call this to clear authentication against CouchDB.

Example

See the /example folder. To see it in action, run:

node example/index.js

Contributing

Development

Run the tests locally

npm test

Deployment

To release, run the following

npm run release:patch|minor|major

License

The MIT License (MIT) Copyright © 2015 Ubilabs GmbH [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.