-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedin_client.js
33 lines (28 loc) · 1.3 KB
/
linkedin_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
// Request LinkedIn 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.
LinkedIn.requestCredential = function (options, credentialRequestCompleteCallback) {
// support both (options, callback) and (callback).
if (!credentialRequestCompleteCallback && typeof options === 'function') {
credentialRequestCompleteCallback = options;
options = {};
}
var config = ServiceConfiguration.configurations.findOne({service: 'linkedin'});
if (!config) {
credentialRequestCompleteCallback && credentialRequestCompleteCallback(new ServiceConfiguration.ConfigError("Service not configured"));
return;
}
var credentialToken = Random.id();
var scope = [];
if (options && options.requestPermissions) {
scope = options.requestPermissions.join('+');
}
var loginUrl =
'https://www.linkedin.com/uas/oauth2/authorization' +
'?response_type=code' + '&client_id=' + config.clientId +
'&redirect_uri=' + encodeURIComponent(Meteor.absoluteUrl('_oauth/linkedin?close')) +
'&scope=' + scope + '&state=' + credentialToken;
Oauth.initiateLogin(credentialToken, loginUrl, credentialRequestCompleteCallback);
};