komapi-passport
Disclaimer: There will be breaking changes and outdated documentation during the pre-v1.0.0 cycles.
Recommended middleware for authentication in komapi. This is a Koa compatible implementation of Passport and an alternative to koa-passport.
Please refer to Passport for more information on how to use passport.
Documentation
Installation
Install through npm and require it in your index.js
file.
$ npm install --save komapi-passport passport-http bcrypt
Hello World
Try GET /
using the simple example application below. This example uses http basic authentication, but all passport strategies are supported.
Username is "jeffj" and password is "mylittlesecret".
// Dependencies;;;; // Initconst app = ;; // This is optional. See the tips (1) for descriptionconst user = id: 1 username: 'jeffj' name: 'Jeff Jagger' passwordHash: '$2a$06$5f2353rB/Jgb0s8vRKteluCJR2WY1E97.0htzB6RW.O1LJa.BQamu' // mylittlesecret; // Setuppassport; // Middlewaresapp;app;app; // Listenapp;
Tips
- For better performance, use
mutateApp(app);
in your application bootstrap. This adds an application wide compatibility layer between Passport and Koa. If you do not use this, the compatibility layer will be added on a per-request basis - thus reducing performance slightly. - If you allow unauthenticated requests (e.g. using
passport-anonymous
strategy) you can enforce authentication on some of your routes with the includedPassport.ensureAuthenticated()
middleware.
Contributing
This project follows angular commit conventions.
Release
Run npm run release
to publish a new release and npm run release --tag=next
to publish a pre-release.