forked from yubozhao/meteor-accounts-instagram
-
Notifications
You must be signed in to change notification settings - Fork 1
/
untappd_client.js
56 lines (44 loc) · 1.62 KB
/
untappd_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
47
48
49
50
51
52
53
54
55
56
Untappd = {};
Untappd.requestCredential = function (options, credentialRequestCompleteCallback) {
if (!credentialRequestCompleteCallback && typeof options === 'function') {
credentialRequestCompleteCallback = options;
options = {};
}
var config =
ServiceConfiguration.configurations.findOne({ service: 'untappd' });
if (!config) {
if (credentialRequestCompleteCallback) {
credentialRequestCompleteCallback(new ServiceConfiguration.ConfigError());
}
return;
}
var credentialToken = Random.secret();
var loginStyle = OAuth._loginStyle('untappd', config, options);
// var scope = (config.scope) || ['basic', 'likes', 'relationships', 'comments'];
if (typeof scope === 'string') {
scope = [scope];
}
var flatScope = _.map(scope, encodeURIComponent).join('+');
var absoluteUrlOptions = {};
var rootUrl = this.rootUrl();
if (rootUrl) {
absoluteUrlOptions.rootUrl = rootUrl;
}
var uri = OAuth._redirectUri('untappd', config, null, absoluteUrlOptions);
var loginUrl = 'https://untappd.com/oauth/authenticate' +
'?client_id=' + config.clientId +
'&response_type=code' +
// '&scope=' + flatScope +
'&redirect_url=' + uri.replace('?close', '') +
'&state=' + OAuth._stateParam(loginStyle, credentialToken);
OAuth.launchLogin({
loginService: "untappd",
loginStyle: loginStyle,
loginUrl: loginUrl,
credentialRequestCompleteCallback: credentialRequestCompleteCallback,
credentialToken: credentialToken
});
};
// override this method to set the root redirect URL
// useful for multi-tenant environments
Untappd.rootUrl = function () { /* noop */ };