forked from mondora/mondora-connect-with
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
46 lines (43 loc) · 1.44 KB
/
client.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
Accounts.oauth.tryConnectAfterPopupClosed = function (credentialToken, callback) {
var credentialSecret = OAuth._retrieveCredentialSecret(credentialToken) || null;
var options = {
oauth: {
credentialToken: credentialToken,
credentialSecret: credentialSecret
}
};
Meteor.call("addLoginService", options, function () {
if (callback) {
callback(arguments);
}
});
};
Accounts.oauth.connectCredentialRequestCompleteHandler = function (callback) {
return function (credentialTokenOrError) {
if (credentialTokenOrError && credentialTokenOrError instanceof Error) {
if (callback) {
callback(credentialTokenOrError);
}
} else {
Accounts.oauth.tryConnectAfterPopupClosed(credentialTokenOrError, callback);
}
};
};
var makePascalCased = function (word) {
return word[0].toUpperCase() + word.slice(1).toLowerCase();
};
Meteor.connectWith = function (service, options, callback) {
// Support a callback without options
if (!callback && typeof options === "function") {
callback = options;
options = null;
}
var connectCredentialRequestCompleteCallback = Accounts.oauth.connectCredentialRequestCompleteHandler(callback);
console.log('connect with ', service);
if (service == 'foursquare') {
Foursquare.requestCredential(options, connectCredentialRequestCompleteCallback);
return;
}
var Service = Package[service][makePascalCased(service)];
Service.requestCredential(options, connectCredentialRequestCompleteCallback);
};