This repository was archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathapp.js
More file actions
53 lines (42 loc) · 1.25 KB
/
Copy pathapp.js
File metadata and controls
53 lines (42 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var fbgraph = require('fbgraph');
var express = require('express');
var stormpath = require('express-stormpath');
var app = express();
function getFacebookPicture(accessToken, size, callback) {
if (!size) {
size = 'normal';
}
var requestOptions = {
access_token: accessToken
};
fbgraph.get('/me/picture?type=' + size, requestOptions, callback);
}
app.use(stormpath.init(app, {
debug: 'info',
postLoginHandler: function (account, req, res, next) {
account.getProviderData(function (err, providerData) {
if (err) {
return next(err);
}
if (providerData.providerId === 'facebook') {
return getFacebookPicture(providerData.accessToken, 'normal', function (err, profilePicture) {
if (err) {
return next(err);
}
// E.g. save profilePicture.location to database.
console.log('Facebook profile picture of account \'%s\' is \'%s\'.', account.href, profilePicture.location);
next();
});
}
next();
});
}
}));
app.on('error', function (err) {
console.error('An error occurred!', err);
});
app.on('stormpath.ready', function (err) {
app.listen(3000, function () {
console.log('Listening on http://localhost:3000/');
});
});