-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.js
82 lines (67 loc) · 2.35 KB
/
auth.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//////////////////////////
//
// Authentication
// See "Logging the user in" on https://developers.facebook.com/mobile
//
//////////////////////////
var user = [];
//Detect when Facebook tells us that the user's session has been returned
FB.Event.monitor('auth.statusChange', function(session) {
console.log('Got the user\'s session: ', session);
if (session && session.status != 'not_authorized') {
if (session.authResponse['accessToken']) {
document.body.className = 'connected';
//Fetch user's id, name, and picture
FB.api('/me', {
fields: 'name, picture'
},
function(response) {
if (!response.error) {
user = response;
console.log('Got the user\'s name and picture: ', response);
//Update display of user name and picture
if (FB.$('user-name')) {
FB.$('user-name').innerHTML = user.name;
}
if (FB.$('user-picture')) {
FB.$('user-picture').src = user.picture;
}
}
clearAction();
});
}
}
else if (session === undefined) {
document.body.className = 'not_connected';
clearAction();
}
else if (session && session.status == 'not_authorized') {
document.body.className = 'not_connected';
clearAction();
}
});
//Prompt the user to login and ask for the 'email' permission
function promptLogin() {
FB.login(null, {scope: 'email, user_actions:endoapp, user_actions:mapmyrideapp, friends_actions:endoapp, friends_actions:mapmyrideapp'});
}
//This will prompt the user to grant you acess to their Facebook Likes
function promptExtendedPermissions() {
FB.login(function() {
setAction("The 'user_likes' permission has been granted.", false);
setTimeout('clearAction();', 2000);
document.body.className = 'permissioned';
}, {scope: 'user_likes, user_actions.music, user_actions:castline, user_actions:endoapp, user_actions:mapmyrideapp'});
}
//See https://developers.facebook.com/docs/reference/rest/auth.revokeAuthorization/
function uninstallApp() {
FB.api({method: 'auth.revokeAuthorization'},
function(response) {
window.location.reload();
});
}
//See https://developers.facebook.com/docs/reference/javascript/FB.logout/
function logout() {
FB.logout(function(response) {
window.location.reload();
});
}