forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeetup_client.js
39 lines (34 loc) · 1.5 KB
/
meetup_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
Meetup = {};
// Request Meetup credentials for the user
// @param options {optional}
// @param credentialRequestCompleteCallback {Function} Callback function to call on
// completion. Takes one argument, credentialToken on success, or Error on
// error.
Meetup.requestCredential = function (options, credentialRequestCompleteCallback) {
// support both (options, callback) and (callback).
if (!credentialRequestCompleteCallback && typeof options === 'function') {
credentialRequestCompleteCallback = options;
options = {};
}
var config = ServiceConfiguration.configurations.findOne({service: 'meetup'});
if (!config) {
credentialRequestCompleteCallback && credentialRequestCompleteCallback(new ServiceConfiguration.ConfigError("Service not configured"));
return;
}
var credentialToken = Random.id();
var scope = (options && options.requestPermissions) || [];
var flatScope = _.map(scope, encodeURIComponent).join('+');
var loginUrl =
'https://secure.meetup.com/oauth2/authorize' +
'?client_id=' + config.clientId +
'&response_type=code' +
'&scope=' + flatScope +
'&redirect_uri=' + Meteor.absoluteUrl('_oauth/meetup?close') +
'&state=' + credentialToken;
// meetup box gets taller when permissions requested.
var height = 620;
if (_.without(scope, 'basic').length)
height += 130;
Oauth.initiateLogin(credentialToken, loginUrl, credentialRequestCompleteCallback,
{width: 900, height: height});
};