-
-
Save mdhanda/4fdf8dd05705b5b8bffd4c066c2978aa to your computer and use it in GitHub Desktop.
How to use Feathers Client to Authenticate Facebook/Instagram credentials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/app.js | |
'use strict'; | |
const contentTypes = require('./../utils/content-types'); | |
const sysInfo = require('./../utils/sys-info'); | |
const env = process.env; | |
const path = require('path'); | |
const serveStatic = require('feathers').static; | |
const favicon = require('serve-favicon'); | |
const compress = require('compression'); | |
const cors = require('cors'); | |
const feathers = require('feathers'); | |
const configuration = require('feathers-configuration'); | |
const hooks = require('feathers-hooks'); | |
const memory = require('feathers-memory'); | |
const rest = require('feathers-rest'); | |
const bodyParser = require('body-parser'); | |
const socketio = require('feathers-socketio'); | |
const middleware = require('./middleware'); | |
const services = require('./services'); | |
const app = feathers(); | |
app.configure(configuration(path.join(__dirname, '..'))); | |
app.use(compress()) | |
.options('*', cors()) | |
.use(cors()) | |
.use(favicon( path.join(app.get('public'), 'favicon.ico') )) | |
.use('/', serveStatic( app.get('public') )) | |
.use(bodyParser.json()) | |
.use(bodyParser.urlencoded({ extended: true })) | |
.configure(hooks()) | |
.configure(rest()) | |
.configure(socketio()) | |
.configure(services) | |
.configure(middleware); | |
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/services/authentication/index.js | |
'use strict'; | |
const authentication = require('feathers-authentication'); | |
const FacebookStrategy = require('passport-facebook').Strategy; | |
const FacebookTokenStrategy = require('passport-facebook-token'); | |
const InstagramStrategy = require('passport-instagram').Strategy; | |
const InstagramTokenStrategy = require('passport-instagram-token'); | |
module.exports = function() { | |
const app = this; | |
let config = app.get('auth'); | |
config.facebook.strategy = FacebookStrategy; | |
config.facebook.tokenStrategy = FacebookTokenStrategy; | |
config.instagram.strategy = InstagramStrategy; | |
config.instagram.tokenStrategy = InstagramTokenStrategy; | |
app.set('auth', config); | |
app.configure(authentication(config)); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Feathers Auth0 Example</title> | |
</head> | |
<body> | |
<h1>Feathers OAuth2 Example</h1> | |
<a href="/auth/github">Login with Github</a> | |
<a href="/auth/facebook">Login with Facebook</a> | |
<a href="/auth/instagram">Login with Instagram</a> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"host": "instacards-cloudgroup.rhcloud.com", | |
"port": 80, | |
"mongodb": "mongodb://127.0.0.1:27017/instacards", | |
"public": "../public/", | |
"auth": { | |
"token": { | |
"secret": "rdkjfqBvlXIJyrzquhAIwTa0BN+PMz4v7ZdnG2GCeWGDOOPZK7NWG6AaNGskxeQmJ/3wtwRGYPKbsihBwwLhKQ==" | |
}, | |
"local": {}, | |
"facebook": { | |
"clientID": "587639168061607", | |
"clientSecret": "8ab3b1f3c2a3df1c47c0a84262861989", | |
"permissions": { | |
"scope": ["public_profile","email"] | |
} | |
}, | |
"instagram": { | |
"clientID": "09ad8a5223fe471c9448a49ff07cc676", | |
"clientSecret": "31db525184ac4c3fba6a26b1005178aa", | |
"permissions": { | |
"scope": ["basic"] | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/services/index.js | |
'use strict'; | |
const authentication = require('./authentication'); | |
const user = require('./user'); | |
const mongoose = require('mongoose'); | |
module.exports = function() { | |
const app = this; | |
// default to a 'localhost' configuration: | |
var connection_string = app.get('mongodb'); | |
// if OPENSHIFT env variables are present, use the available connection info: | |
if(process.env.MONGODB_URL){ | |
connection_string = process.env.MONGODB_URL + process.env.OPENSHIFT_APP_NAME; | |
} | |
console.log("Mongo Connection: "+connection_string); | |
mongoose.connect(connection_string, { db: { nativeParser: true } }); | |
mongoose.Promise = global.Promise; | |
app.configure(authentication); | |
app.configure(user); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Feathers OAuth2 Success</title> | |
</head> | |
<body> | |
<h1>Feathers OAuth2 Succeeded</h1> | |
<!-- Make sure to change your Auth0 domain --> | |
<a href="/" id="logout">Logout</a> | |
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script> | |
<script type="text/javascript" src="//npmcdn.com/feathers-client@^1.0.0/dist/feathers.js"></script> | |
<script type="text/javascript"> | |
var host = 'http://localhost:3030'; | |
// Set up Feathers client side | |
var app = feathers() | |
.configure(feathers.rest(host).jquery(jQuery)) | |
.configure(feathers.hooks()) | |
.configure(feathers.authentication({ storage: window.localStorage })); | |
// authenticate using your JWT that was passed in the short lived cookie | |
app.authenticate().then(function(result){ | |
console.log('Authenticated!', result); | |
alert('Your JWT is: ' + app.get('token')); | |
}).catch(function(error){ | |
console.error('Error authenticating!', error); | |
}); | |
$('#logout').on('click', function(ev) { | |
app.logout(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment