Skip to content

Instantly share code, notes, and snippets.

@jermsam
Created April 20, 2018 18:29
Show Gist options
  • Save jermsam/91e209f6c20156aeadcaf71717c512ab to your computer and use it in GitHub Desktop.
Save jermsam/91e209f6c20156aeadcaf71717c512ab to your computer and use it in GitHub Desktop.
Feathers Social login
const authentication = require('@feathersjs/authentication');
const jwt = require('@feathersjs/authentication-jwt');
const local = require('@feathersjs/authentication-local');
const oauth2 = require('@feathersjs/authentication-oauth2');
const GithubStrategy = require('passport-github');
module.exports = function (app) {
const config = app.get('authentication');
// Set up authentication with the secret
app.configure(authentication(config));
app.configure(jwt());
app.configure(local());
app.configure(oauth2(Object.assign({
name: 'github',
Strategy: GithubStrategy
}, config.github)));
// The `authentication` service is used to create a JWT.
// The before `create` hook registers strategies that can be used
// to create a new valid JWT (e.g. local or oauth2)
app.service('authentication').hooks({
before: {
create: [
authentication.hooks.authenticate(config.strategies)
],
remove: [
authentication.hooks.authenticate('jwt')
]
}
});
};
{
"host": "localhost",
"port": 3030,
"public": "../public/",
"paginate": {
"default": 10,
"max": 50
},
"postgres": "postgres://postgres:@localhost:5432/chat",
"authentication": {
"secret": "3b905c9b5761206e6579e6e25b42acab0e58d8be72da614809b66f2658690c2bb24f3f65049893e003fe8b61809c924c1bfbadcd48a0fb098e4d31dcb29a61c915cb5f29f293c49d5c7933d7fd6cc7e6b08d4a2c29f0cf683135e106d36fc3c70db1e2078eeb0149ce025f0ec36a42be8f6c6dd49c0ac27852157535710b0ab3f93b3ab2b2b2cbf8ecf354d19accf6c3483fbc13bd6e517d6464a951f169559514c956b73499aa8ad58615eafeb8abb92d79b424b373227afb0dbdf3476299709ae8dd47a2d15ce1ee3c273b2658c1514b0eddaf8f28d73d0b196b991ab505f98a1a4345990f1fb7d891754a83272f8556cb925ea82dde3a1183aed6333209be",
"strategies": [
"jwt",
"local"
],
"path": "/authentication",
"service": "users",
"jwt": {
"header": {
"typ": "access"
},
"audience": "https://yourdomain.com",
"subject": "anonymous",
"issuer": "feathers",
"algorithm": "HS256",
"expiresIn": "1d"
},
"local": {
"entity": "user",
"usernameField": "email",
"passwordField": "password"
},
"github": {
"callbackURL":"/auth/github/redirect",
"clientID": "af83bf5c24844f609200",
"clientSecret": "8e0e766d8b78c95078908746bdfce3dcb093803c",
"successRedirect": "/"
},
"cookie": {
"enabled": true,
"name": "feathers-jwt",
"httpOnly": false,
"secure": false
}
}
}
@jermsam
Copy link
Author

jermsam commented Apr 20, 2018

auth21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment