forked from Tobe3/accounts-pinterest
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpinterest_client.js
46 lines (37 loc) · 1.57 KB
/
pinterest_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
Pinterest = {};
Pinterest.requestCredential = function (options, credentialRequestCompleteCallback) {
if (!credentialRequestCompleteCallback && typeof options === 'function') {
credentialRequestCompleteCallback = options;
options = {};
}
var config = ServiceConfiguration.configurations.findOne({service: 'pinterest'});
if (!config) {
credentialRequestCompleteCallback && credentialRequestCompleteCallback(
new ServiceConfiguration.ConfigError());
return;
}
var mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i.test(navigator.userAgent);
var display = mobile ? 'touch' : 'redirect';
var scope = ['read_public','write_public'];
var credentialToken = Random.id();
var loginStyle = OAuth._loginStyle('pinterest', config, options);
var state = OAuth._stateParam(loginStyle, credentialToken);
if (config.scope) {
scope = config.scope;
if (options && options.requestPermissions) {
scope = scope + ',';
}
}
if (options && options.requestPermissions) {
scope = scope + options.requestPermissions.join(',');
}
//alert(OAuth._redirectUri('pinterest', config));
var loginUrl =
'https://api.pinterest.com/oauth/?' +
'response_type=code' +
'&redirect_uri=' + encodeURIComponent(Meteor.absoluteUrl('_oauth/pinterest?close', {secure: true,replaceLocalhost:true})) +
'&client_id=' + config.clientId +
'&scope=read_public,write_public'+
'&state=' + OAuth._stateParam(loginStyle, credentialToken, options && options.redirectUrl);
OAuth.initiateLogin(credentialToken, loginUrl, credentialRequestCompleteCallback);
};