-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaccounts-twitch-client.js
40 lines (35 loc) · 1.46 KB
/
accounts-twitch-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
TwitchAccounts = {};
TwitchAccounts.requestCredential = function (options, credentialRequestCompleteCallback) {
if (!credentialRequestCompleteCallback && typeof options === 'function') {
credentialRequestCompleteCallback = options;
options = {};
} else if (!options) {
options = {};
}
var config = ServiceConfiguration.configurations.findOne({service: 'twitch'});
if (!config) {
credentialRequestCompleteCallback && credentialRequestCompleteCallback(
new ServiceConfiguration.ConfigError());
return;
}
var credentialToken = Random.secret();
var loginStyle = OAuth._loginStyle('twitch', config, options);
var requiredScope = ['user_read'];
var scope = (options && options.requestPermissions) || ['user_read', 'channel_read'];
scope = _.union(scope, requiredScope);
var flatScope = _.map(scope, encodeURIComponent).join('+');
var loginUrl =
"https://api.twitch.tv/kraken/oauth2/authorize" +
"?response_type=code" +
"&client_id=" + config.clientId +
"&redirect_uri=" + OAuth._redirectUri('twitch', config) +
"&scope=" + flatScope +
'&state=' + OAuth._stateParam(loginStyle, credentialToken);
OAuth.launchLogin({
loginService: "twitch"
, loginStyle: loginStyle
, loginUrl: loginUrl
, credentialRequestCompleteCallback: credentialRequestCompleteCallback
, credentialToken: credentialToken
});
};