Skip to content

Instantly share code, notes, and snippets.

@kwcto
Created November 17, 2016 08:28
Show Gist options
  • Save kwcto/99706ee212ebc2962bec4705545152e1 to your computer and use it in GitHub Desktop.
Save kwcto/99706ee212ebc2962bec4705545152e1 to your computer and use it in GitHub Desktop.
feathers-authentication-oauth2 with Auth0
// Use passport-auth0 instead of passport-github
// from https://github.com/feathersjs/feathers-authentication-oauth2/commit/1902760035af910f830a5692bad11799d37753a9
const feathers = require('feathers');
const rest = require('feathers-rest');
const hooks = require('feathers-hooks');
const memory = require('feathers-memory');
const bodyParser = require('body-parser');
const Auth0Strategy = require('passport-auth0').Strategy;
const errorHandler = require('feathers-errors/handler');
const auth = require('feathers-authentication');
const oauth2 = require('feathers-authentication-oauth2');
// Initialize the application
const app = feathers()
.configure(rest())
.configure(hooks())
// Needed for parsing bodies (login)
.use(bodyParser.json())
.use(bodyParser.urlencoded({ extended: true }))
// Configure feathers-authentication
.configure(auth({ secret: 'super secret' }))
.configure(oauth2({
Strategy: Auth0Strategy,
domain: '<your-domain>.auth0.com',
'clientID': '<your-auth0-clientID>',
'clientSecret': '<your-auth0-clientSecret>',
// Not implemented in passport-auth0
// Return named scopes ([https://auth0.com/docs/scopes])
scope: ['openid', 'email', 'nickname']
// Return all attributes (not recommended)
// scope: ['openid', 'profile']
}))
.use('/users', memory())
.use(errorHandler());
app.listen(3030);
console.log('Feathers app started on 127.0.0.1:3030');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment