-
Notifications
You must be signed in to change notification settings - Fork 9
/
linkedin-client.js
79 lines (73 loc) · 2.16 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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
const {
requestPermissions,
...otherOptionsToPassThrough
} = options
if (requestPermissions) {
scope = requestPermissions.join('+')
} else {
// If extra permissions not passed, we need to request basic, available to all
scope = 'r_emailaddress+r_liteprofile'
}
const loginStyle = OAuth._loginStyle(
'linkedin',
config,
options,
)
if (!otherOptionsToPassThrough.popupOptions) {
// the default dimensions (https://github.com/meteor/meteor/blob/release-1.6.1/packages/oauth/oauth_browser.js#L15) don't play well with the content shown by linkedin
// so override popup dimensions to something appropriate (might have to change if LinkedIn login page changes its layout)
otherOptionsToPassThrough.popupOptions = {
width: 390,
height: 628,
}
}
const loginUrl = `https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=${
config.clientId
}&redirect_uri=${OAuth._redirectUri(
'linkedin',
config,
)}&state=${OAuth._stateParam(
loginStyle,
credentialToken,
)}&scope=${scope}`
OAuth.launchLogin({
credentialRequestCompleteCallback,
credentialToken,
loginService: 'linkedin',
loginStyle,
loginUrl,
...otherOptionsToPassThrough,
})
}