forked from PoBuchi/pauli-linkedin-oauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkedin-client.js
44 lines (37 loc) · 1.54 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
34
35
36
37
38
39
40
41
42
43
44
LinkedIn = {};
// 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 = {};
}
const config = ServiceConfiguration.configurations.findOne({service: 'linkedin'});
if (!config) {
credentialRequestCompleteCallback && credentialRequestCompleteCallback(new ServiceConfiguration.ConfigError("Service not configured"));
return;
}
const credentialToken = Random.secret();
let scope = [];
if (options && options.requestPermissions) {
scope = options.requestPermissions.join('+');
}
const loginStyle = OAuth._loginStyle('linkedin', config, options);
const loginUrl =
'https://www.linkedin.com/uas/oauth2/authorization' +
'?response_type=code' + '&client_id=' + config.clientId +
'&redirect_uri=' + OAuth._redirectUri('linkedin', config) +
'&scope=' + scope +
'&state=' + OAuth._stateParam(loginStyle, credentialToken);
OAuth.launchLogin({
loginService: "linkedin",
loginStyle: loginStyle,
loginUrl: loginUrl,
credentialRequestCompleteCallback: credentialRequestCompleteCallback,
credentialToken: credentialToken
});
};