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

[MOVED] Feathers local, token, and OAuth authentication over REST and Websockets using JSON Web Tokens (JWT) with PassportJS.

License

Notifications You must be signed in to change notification settings

feathersjs-ecosystem/authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

cb006cd Β· May 8, 2019
Sep 14, 2018
Oct 25, 2017
Jun 29, 2018
May 31, 2018
Nov 15, 2015
Oct 23, 2017
Oct 24, 2017
Oct 24, 2017
Oct 24, 2017
Jun 11, 2018
Jun 29, 2018
Nov 15, 2015
May 8, 2019
Oct 24, 2017
Nov 13, 2018
Mar 30, 2019

Repository files navigation

@feathersjs/authentication

Important: The code for this module has been moved into the main Feathers repository at feathersjs/feathers (package direct link). Please open issues and pull requests there.

Build Status

Add Authentication to your FeathersJS app.

@feathersjs/authentication adds shared PassportJS authentication for Feathers HTTP REST and WebSocket transports using JSON Web Tokens.

Installation

npm install @feathersjs/authentication --save

Quick example

const feathers = require('@feathersjs/feathers');
const express = require('@feathersjs/express');
const socketio = require('@feathersjs/socketio');
const auth = require('@feathersjs/authentication');
const local = require('@feathersjs/authentication-local');
const jwt = require('@feathersjs/authentication-jwt');
const memory = require('feathers-memory');

const app = express(feathers());
app.configure(express.rest())
 .configure(socketio())
 .use(express.json())
 .use(express.urlencoded({ extended: true }))
 .configure(auth({ secret: 'supersecret' }))
 .configure(local())
 .configure(jwt())
 .use('/users', memory())
 .use('/', express.static(__dirname + '/public'))
 .use(express.errorHandler());

app.service('users').hooks({
  // Make sure `password` never gets sent to the client
  after: local.hooks.protect('password')
});

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

// 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' })
  ]
 }
});

const port = 3030;
let server = app.listen(port);
server.on('listening', function() {
 console.log(`Feathers application started on localhost:${port}`);
});

Documentation

Please refer to the @feathersjs/authentication API documentation for more details.

License

Copyright (c) 2018

Licensed under the MIT license.

About

[MOVED] Feathers local, token, and OAuth authentication over REST and Websockets using JSON Web Tokens (JWT) with PassportJS.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published