Skip to content
This repository was archived by the owner on Mar 22, 2022. It is now read-only.

1.0 Pre-release #336

Merged
merged 95 commits into from
Nov 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
f6d247b
cleaning up dependencies
ekryski Apr 14, 2016
14bb7b3
Merge branch 'master' into 0.8
ekryski Apr 18, 2016
545929a
merging in master
ekryski Jul 18, 2016
e6d4a86
removing auth redirects and exposing middleware
ekryski Jul 18, 2016
521294a
expanding express middleware
ekryski Jul 18, 2016
da777d9
moving what I can in services to setup method
ekryski Jul 18, 2016
36876c8
updating dependencies
ekryski Jul 19, 2016
b6732ee
cleaning up middleware and adding debug logs
ekryski Jul 19, 2016
c031ac1
cleaning up services and adding debug logs
ekryski Jul 19, 2016
982ee1d
changing options for populate user hook to conform with other options
ekryski Jul 19, 2016
ce3b534
cleaning up main index file
ekryski Jul 19, 2016
a10f7a6
fixing lint errors
ekryski Jul 19, 2016
cfc09e0
getting example app working
ekryski Jul 19, 2016
a61df31
fixing options for populate user middlware
ekryski Jul 19, 2016
f4018d2
fixing socket logout emitting
ekryski Jul 19, 2016
4fcdc41
restructuring so you can set hooks to construct your token payload if…
ekryski Jul 19, 2016
7dd6a56
Default to a session cookie instead of 1 day
ekryski Jul 19, 2016
444eca4
Switch to "user" instead of "data" for the response from auth
ekryski Jul 19, 2016
f484d49
Make sure we clear the user out of locals so that you don't end up in…
ekryski Jul 19, 2016
681c2aa
Allow passing options when creating a JWT.
ekryski Jul 19, 2016
afe3ca2
setting version
ekryski Jul 19, 2016
4dff589
don't throw an error in the decode token middleware
ekryski Jul 19, 2016
6fafb6e
bump version
ekryski Jul 19, 2016
ed19823
clearing cookie if use not found. Setting cookie age to same as JWT
ekryski Aug 8, 2016
859178b
bump version
ekryski Aug 8, 2016
02e0682
Don’t mix options when signing tokens (#255)
marshallswain Aug 9, 2016
880ca97
Attempt to get token right away. (#252)
marshallswain Aug 9, 2016
2c49e00
fix restrict to owner hook methods. Closes #228
ekryski Aug 10, 2016
f6274fe
bump version
ekryski Aug 10, 2016
a972473
cookies should get set regardless of whether it was an xhr request if…
ekryski Sep 1, 2016
5184a4c
bumping version
ekryski Sep 1, 2016
664959b
adding migration guide
ekryski Sep 24, 2016
e53fd33
reorganizing middleware, hooks and services
ekryski Sep 24, 2016
429d190
updaing mocha
ekryski Sep 24, 2016
388439e
updating migration doc of things left to doc/complete
ekryski Sep 24, 2016
c2e7b58
fixing a bunch of the tests and adding tests for all new middleware
ekryski Sep 26, 2016
c5017ab
cleaning up client side tests. Still failing
ekryski Sep 26, 2016
eb6709e
getting all tests passing
ekryski Sep 28, 2016
fc58e0a
updating all middleware to not have default and pull from global config
ekryski Sep 30, 2016
62eafcc
finished consolidating options
ekryski Oct 4, 2016
e4281fd
bumping version
ekryski Oct 4, 2016
eeb5fbf
adding more details to migration guide
ekryski Oct 5, 2016
93c6f28
fix typo missing 'd'
marshallswain Oct 6, 2016
c2a44b6
Fix typo and simplify wording.
marshallswain Oct 6, 2016
04cffbf
normalize the callbackURL
marshallswain Oct 6, 2016
e06b6c7
Make sure the provider plugin name doesn't overwrite the OAuth provid…
marshallswain Oct 6, 2016
37d771a
consistency: `callbackUrl` should be `callbackURL`
marshallswain Oct 8, 2016
7dd4391
Normalize comparison URL & fix typo
marshallswain Oct 8, 2016
ac6e371
Always use service lookup.
marshallswain Oct 8, 2016
e3cb40c
DRY up the dynamic token and user service lookup.
marshallswain Oct 9, 2016
963cc3a
OAuth require successRedirect with default successHandler
marshallswain Oct 9, 2016
6f0308f
First cut for authentication middleware (#305)
daffl Oct 11, 2016
5d9cbc5
First cut for authentication middleware (#305)
daffl Oct 11, 2016
531898a
Merge pull request #304 from feathersjs/0.8-oauth-fixes
marshallswain Oct 11, 2016
45ccaa1
Cookies will match jwt expiry by default. (#308)
marshallswain Oct 11, 2016
a5ad6d2
Store config at `app.config` (#312)
marshallswain Oct 13, 2016
1220895
adding instanbul code coverage
ekryski Oct 14, 2016
bf6f7a6
Remove permissions hooks and middleware which will be put into feathe…
daffl Oct 15, 2016
1a58d87
Started implementation of more modularized module structure
daffl Oct 17, 2016
5cda433
Some reorganization
daffl Oct 18, 2016
081aec0
Implement Socket new authentication
daffl Oct 18, 2016
c8efa77
More reorganization and start of integration tests
daffl Oct 19, 2016
33b50f8
eslint fix
ekryski Oct 19, 2016
30f2db0
More integration tests and cleanup
daffl Oct 20, 2016
bd2aa8b
pulling down changes and resolving conflicts
ekryski Oct 22, 2016
5cb504e
Merge branch 'modularization' of github.com:feathersjs/feathers-authe…
ekryski Oct 22, 2016
75b51e4
reogranizing
ekryski Oct 22, 2016
80e0d0a
Applying latest changes and merging with dev other branch
daffl Oct 22, 2016
9297a9c
Socket.io authentication tests and login logout event
daffl Oct 23, 2016
a120020
Improving socket tests and adding Primus
daffl Oct 24, 2016
253277b
Some cleanup
daffl Oct 24, 2016
5e5b6a1
Better error verification tests
daffl Oct 24, 2016
ebf603f
Implement login and logout events for REST authentication (#325)
daffl Oct 25, 2016
6a2787c
Fix tests
daffl Oct 25, 2016
8700d11
wip
ekryski Oct 27, 2016
33e61b4
first cut of auth working with passport. Clean up and tests to do
ekryski Oct 28, 2016
8668382
fixing event middleware resolution
ekryski Oct 28, 2016
b7db1d1
Keep github together
marshallswain Nov 2, 2016
d5156b6
Keep twitter together
marshallswain Nov 2, 2016
5d377d4
getting tests passing. Still a couple more to do
ekryski Nov 7, 2016
9b75949
removing unused hooks for now. May bring some back later
ekryski Nov 7, 2016
0de7826
fixing lint errors
ekryski Nov 8, 2016
7fb1923
removing hashPassword hook. It now lives in feathers-authentication-l…
ekryski Nov 8, 2016
8c59ec7
adding a migration guide and new features docs
ekryski Nov 10, 2016
49a2ed9
adding more detail to migration doc
ekryski Nov 10, 2016
8b6bdb7
cleaning up dependencies
ekryski Nov 15, 2016
cbf9ff7
getting tests passing again
ekryski Nov 15, 2016
b18ba61
adding some more tests. Implementing chained strategies
ekryski Nov 16, 2016
578f807
cleaning up dependencies
ekryski Nov 16, 2016
fbd8e8e
finishing integration tests and handling socket logout timeout
ekryski Nov 16, 2016
69499d9
merging in master and resolving conflicts
ekryski Nov 16, 2016
ea45f06
cleaning up example app
ekryski Nov 16, 2016
c399925
fixing up example
ekryski Nov 16, 2016
4eaea35
updating README
ekryski Nov 16, 2016
9ecb792
updating API docs
ekryski Nov 16, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ node_modules
.lock-wscript

lib/
data.db
coverage/
data.db
_backup/
yarn.lock
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"unused": false,
"strict": false,
"trailing": true,
"smarttabs": true,
"white": false,
"node": true,
"expr": true,
"globals": {
"window": true,
"it": true,
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.editorconfig
.jshintrc
.istanbul.yml
.travis.yml
.babelrc
.idea/
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sudo: false
language: node_js
node_js:
- node
Expand Down
175 changes: 138 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

> Add Authentication to your FeathersJS app.

`feathers-authentication` adds shared [PassportJS](http://passportjs.org/) authentication for Feathers HTTP REST and WebSockets services using [JSON Web Tokens](http://jwt.io/).
`feathers-authentication` adds shared [PassportJS](http://passportjs.org/) authentication for Feathers HTTP REST and WebSockets transports using [JSON Web Tokens](http://jwt.io/).


## Installation
Expand All @@ -20,55 +20,156 @@ npm install feathers-authentication --save

## Documentation

Please refer to the [Authentication documentation](http://docs.feathersjs.com/authentication/readme.html) for more details:
<!-- Please refer to the [Authentication documentation](http://docs.feathersjs.com/authentication/readme.html) for more details. -->

- [Local Auth Tutorial](http://docs.feathersjs.com/authentication/local.html) - How to implement a username and password-based authentication.
- [Use Hooks for Authorization](http://docs.feathersjs.com/authorization/readme.html) - Learn about the bundled hooks.
## API

This module contains:

## Complete Example
1. The main entry function
2. An `authenticate` hook
3. The authentication `service`
4. Socket listeners
5. Express middleware
6. A [Passport](http://passportjs.org/) adapter

### Hooks

Here's an example of a Feathers server that uses `feathers-authentication` for local auth. It includes a `users` service that uses `feathers-mongoose`. *Note that it does NOT implement any authorization.*
There is just 1 hook now called `authenticate`. This can be used to authenticate a service method with a given strategy.

```js
import feathers from 'feathers';
import hooks from 'feathers-hooks';
import bodyParser from 'body-parser';
import authentication from 'feathers-authentication';
import { hooks as authHooks } from 'feathers-authentication';
import mongoose from 'mongoose';
import service from 'feathers-mongoose';

const port = 3030;
const Schema = mongoose.Schema;
const UserSchema = new Schema({
email: {type: String, required: true, unique: true},
password: {type: String, required: true },
createdAt: {type: Date, 'default': Date.now},
updatedAt: {type: Date, 'default': Date.now}
app.service('authentication').hooks({
before: {
create: [
// You can chain multiple strategies
auth.hooks.authenticate(['jwt', 'local']),
],
remove: [
auth.hooks.authenticate('jwt')
]
}
});
let UserModel = mongoose.model('User', UserSchema);
```


### Express Middleware

Just like hooks there is an `authenticate` middleware. It is used the exact same way you would the regular passport express middleware.

```js
app.post('/#', auth.express.authenticate('local', { successRedirect: '/app', failureRedirect: '/#' }));
```

The other middleware are included but typically you don't need to worry about them.

- `emitEvents` - emit `login` and `logout` events
- `exposeCookies` - expose cookies to Feathers so they are available to hooks and services
- `exposeHeaders` - expose headers to Feathers so they are available to hooks and services
- `failureRedirect` - support redirecting on auth failure. Only triggered if `hook.redirect` is set.
- `successRedirect` - support redirecting on auth success. Only triggered if `hook.redirect` is set.
- `setCookie` - support setting the JWT access token in a cookie. Only enabled if cookies are enabled.

### Default Options

mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost:27017/feathers');
The following default options will be mixed in with your global `auth` object from your config file. It will set the mixed options back to to the app so that they are available at any time by `app.get('auth')`. They can all be overridden and are depended upon by some of the authentication plugins.

let app = feathers()
.configure(feathers.rest())
.configure(feathers.socketio())
```js
{
path: '/authentication', // the authentication service path
header: 'Authorization', // the header to use when using JWT auth
entity: 'user', // the entity that will be added to the request, socket, and hook.params. (ie. req.user, socket.user, hook.params.user)
service: 'users', // the service to look up the entity
passReqToCallback: true, // whether the request object should be passed to the strategies `verify` function
session: false, // whether to use sessions
cookie: {
enabled: false, // whether the cookie should be enabled
name: 'feathers-jwt', // the cookie name
httpOnly: false, // whether the cookie should not be available to client side JavaScript
secure: true // whether cookies should only be available over HTTPS
},
jwt: {
header: { typ: 'access' }, // by default is an access token but can be any type
audience: 'https://yourdomain.com', // The resource server where the token is processed
subject: 'anonymous', // Typically the entity id associated with the JWT
issuer: 'feathers', // The issuing server, application or resource
algorithm: 'HS256', // the algorithm to use
expiresIn: '1d' // the access token expiry
}
}
```

## Complementary Plugins

The following plugins are complementary but entirely optional:

- [feathers-authentication-client](https://github.com/feathersjs/feathers-authentication-client)
- [feathers-authentication-local](https://github.com/feathersjs/feathers-authentication-local)
- [feathers-authentication-jwt](https://github.com/feathersjs/feathers-authentication-jwt)
- [feathers-authentication-oauth1](https://github.com/feathersjs/feathers-authentication-oauth1)
- [feathers-authentication-oauth2](https://github.com/feathersjs/feathers-authentication-oauth2)
- [feathers-permissions](https://github.com/feathersjs/feathers-permissions)

## Migrating to 1.0
Refer to [the migration guide](./docs/migrating.md).

## Complete Example
Here's an example of a Feathers server that uses `feathers-authentication` for local auth.

**Note:** This does NOT implement any authorization. Use [feathers-permissions](https://github.com/feathersjs/feathers-permissions) for that.

```js
const feathers = require('feathers');
const rest = require('feathers-rest');
const socketio = require('feathers-socketio');
const hooks = require('feathers-hooks');
const memory = require('feathers-memory');
const bodyParser = require('body-parser');
const errors = require('feathers-errors');
const errorHandler = require('feathers-errors/handler');
const local = require('feathers-authentication-local');
const jwt = require('feathers-authentication-jwt');
const auth = require('feathers-authentication');

const app = feathers();
app.configure(rest())
.configure(socketio())
.configure(hooks())
.use(bodyParser.json())
.use(bodyParser.urlencoded({ extended: true }))
// Configure feathers-authentication
.configure(authentication());

app.use('/users', new service('user', {Model: UserModel}))
.configure(auth({ secret: 'supersecret' }))
.configure(local())
.configure(jwt())
.use('/users', memory())
.use('/', feathers.static(__dirname + '/public'))
.use(errorHandler());

app.service('authentication').hooks({
before: {
create: [
// You can chain multiple strategies
auth.hooks.authenticate(['jwt', 'local']),
customizeJWTPayload()
],
remove: [
auth.hooks.authenticate('jwt')
]
}
});

let userService = app.service('users');
userService.before({
create: [authHooks.hashPassword('password')]
// Add a hook to the user service that automatically replaces
// the password with a hash of the password before saving it.
app.service('users').hooks({
before: {
find: [
auth.hooks.authenticate('jwt')
],
create: [
local.hooks.hashPassword({ passwordField: 'password' })
]
}
});

let server = app.listen(port);
let server = app.listen(3030);
server.on('listening', function() {
console.log(`Feathers application started on localhost:${port}`);
});
Expand All @@ -84,7 +185,7 @@ import feathers from 'feathers/client';
import hooks from 'feathers-hooks';
import socketio from 'feathers-socketio/client';
import localstorage from 'feathers-localstorage';
import authentication from 'feathers-authentication/client';
import authentication from 'feathers-authentication-client';

const socket = io('http://localhost:3030/');
const app = feathers()
Expand All @@ -93,7 +194,7 @@ const app = feathers()
.configure(authentication({ storage: window.localStorage }));

app.authenticate({
type: 'local',
strategy: 'local',
'email': 'admin@feathersjs.com',
'password': 'admin'
}).then(function(result){
Expand Down
Loading