-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwechat_browser.js
51 lines (45 loc) · 1.7 KB
/
wechat_browser.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
MeteorWeChat = {};
// Request WeChat 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.
MeteorWeChat.requestCredential = function (options, credentialRequestCompleteCallback) {
// support both (options, callback) and (callback).
if (!credentialRequestCompleteCallback && typeof options === 'function') {
credentialRequestCompleteCallback = options;
options = {};
} else if (!options) {
options = {};
}
var config = ServiceConfiguration.configurations.findOne({service: 'wechat'});
if (!config) {
credentialRequestCompleteCallback && credentialRequestCompleteCallback(
new ServiceConfiguration.ConfigError()
);
return;
}
var credentialToken = Random.secret();
var scope = (options && options.requestPermissions) || ['snsapi_login'];
scope = _.map(scope, encodeURIComponent).join(',');
var loginStyle = OAuth._loginStyle('wechat', config, options);
var state = OAuth._stateParam(loginStyle, credentialToken);
var loginUrl =
'https://open.weixin.qq.com/connect/qrconnect' +
'?appid=' + config.appId +
'&response_type=code' +
'&scope=' + scope +
'&redirect_uri=' + OAuth._redirectUri('wechat', config) +
'&state=' + state;
OAuth.launchLogin({
loginService: "wechat",
loginStyle: loginStyle,
loginUrl: loginUrl,
credentialRequestCompleteCallback: credentialRequestCompleteCallback,
credentialToken: credentialToken
});
};
MeteorWeChat.appInstalled = function(callback) {
// for browser, it's always false
callback && callback(null, false);
};