forked from awesomepan/meteor-accounts-qq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qq_client.js
executable file
·39 lines (36 loc) · 1.43 KB
/
qq_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
Qq = {};
// Request QQ 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.
Qq.requestCredential = function (options, credentialRequestCompleteCallback) {
if (!credentialRequestCompleteCallback && typeof options === 'function') {
credentialRequestCompleteCallback = options;
options = {};
}
var config = ServiceConfiguration.configurations.findOne({service: 'qq'});
if (!config) {
credentialRequestCompleteCallback && credentialRequestCompleteCallback(
new ServiceConfiguration.ConfigError());
return;
}
var credentialToken = Random.secret();
var loginStyle = OAuth._loginStyle('qq', config, options);
var scope = (options && options.requestPermissions) || ['get_user_info'];
var flatScope = _.map(scope, encodeURIComponent).join('+');
var loginUrl =
'https://graph.qq.com/oauth2.0/authorize' +
'?client_id=' + config.clientId +
'&response_type=code' +
'&scope=' + flatScope +
'&redirect_uri=' + OAuth._redirectUri('qq', config) +
'&state=' + OAuth._stateParam(loginStyle, credentialToken);
OAuth.launchLogin({
loginService: "qq"
, loginStyle: loginStyle
, loginUrl: loginUrl
, credentialRequestCompleteCallback: credentialRequestCompleteCallback
, credentialToken: credentialToken
});
};