View
3.657
Download
0
Category
Preview:
DESCRIPTION
Social networks integration using node js: 1. OAuth2 2. API consumption 3. everyauth vs. passport.js the demo code can be found under my github repo - https://github.com/orkaplan/social-demo
Citation preview
• An authentication & authorization standard against third party REST services
• Set a list of permission to access data and perform actions:
• Read user data
• Write to user data
• Delete user data
• Get user Location
• At the end of the process an access_token is obtained
Implementation example for Facebook
Implementation example for Facebook
• You don’t have to implement your own authentication mechanism
• Save the security headache
• Save development time
• Use OAuth for 3rd party services to provide the authentication mechanism for the product.
• Get access token and use it to fetch basic details about the user.
• Examples:• Asana leverages Google authentication in addition to its service.
• For Android use Google ID (google play API).
• Social plugins for Wordpress.
everyauth
.appId(conf.fb.appId)
.appSecret(conf.fb.appSecret)
.findOrCreateUser( function (session, accessToken, accessTokenExtra, fbUserMetadata) {
return this.promise();
var user = usersByFbId[fbUserMetadata.id] ||
(usersByFbId[fbUserMetadata.id] = addUser('facebook', fbUserMetadata));
promise.fulfill(user);
})
.redirectPath('/');
https://graph.facebook.com/mike.shaver/picture
{ "data":
{
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/372183_100002526091955_998385602_q.jpg",
"is_silhouette": false
} }
{ "data":
{
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/372183_100002526091955_998385602_q.jpg",
"is_silhouette": false
} }
https://graph.facebook.com/mike.shaver/picture
var baseUrl = "https://graph.facebook.com/";
var url = userId + "/likes";
var params = {access_token: accessToken};
request({
method: 'GET',
url:baseUrl + url,
qs: params,
json: true
},
function (err, res, body) {
if (err) return callback(err);
if (!res || res.statusCode != 200) return callback({message: "invalid status code" + (res && res.statusCode) , body: body});
return callback(null, body);
}
);
var fbapi = require('facebook-api');
var client = fbapi.user(user.accessToken);
client.me.friends(function (err, friends) {
res.render('account', { user: user, friends: friends});
});
Recommended