forked from sylvaingi/meteor-soundcloud
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsoundcloud_client.js
31 lines (28 loc) · 1.22 KB
/
soundcloud_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
// Request soundcloud 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.
Accounts.soundcloud.requestCredential = function (options, credentialRequestCompleteCallback) {
// support both (options, callback) and (callback).
if (!credentialRequestCompleteCallback && typeof options === 'function') {
credentialRequestCompleteCallback = options;
}
var config = ServiceConfiguration.configurations.findOne({service: 'soundcloud'});
if (!config) {
credentialRequestCompleteCallback && credentialRequestCompleteCallback(new ServiceConfiguration.ConfigError("Service not configured"));
return;
}
var credentialToken = Random.id();
var redirect_uri = encodeURIComponent(config.redirect_uri);
var loginUrl =
'https://soundcloud.com/connect' +
'?client_id=' + config.clientId +
'&redirect_uri=' + redirect_uri +
'&scope=non-expiring' +
'&response_type=code_and_token' +
'&display=popup' +
'&state=' + credentialToken;
Oauth.initiateLogin(
credentialToken, loginUrl, credentialRequestCompleteCallback);
};