forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeteor_developer_client.js
56 lines (47 loc) · 1.81 KB
/
meteor_developer_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
// Request Meteor developer account credentials for the user
// @param credentialRequestCompleteCallback {Function} Callback function to call on
// completion. Takes one argument, credentialToken on success, or Error on
// error.
var requestCredential = function (options, credentialRequestCompleteCallback) {
// support a callback without options
if (! credentialRequestCompleteCallback && typeof options === "function") {
credentialRequestCompleteCallback = options;
options = null;
}
var config = ServiceConfiguration.configurations.findOne({
service: 'meteor-developer'
});
if (!config) {
credentialRequestCompleteCallback &&
credentialRequestCompleteCallback(new ServiceConfiguration.ConfigError());
return;
}
var credentialToken = Random.secret();
var loginStyle = OAuth._loginStyle('meteor-developer', config, options);
var loginUrl =
MeteorDeveloperAccounts._server +
"/oauth2/authorize?" +
"state=" + OAuth._stateParam(loginStyle, credentialToken, options && options.redirectUrl) +
"&response_type=code&" +
"client_id=" + config.clientId;
/**
* @deprecated in 1.3.0
*/
if (options && options.userEmail && !options.loginHint) {
options.loginHint = options.userEmail;
delete options.userEmail;
}
if (options && options.loginHint) {
loginUrl += '&user_email=' + encodeURIComponent(options.loginHint);
}
loginUrl += "&redirect_uri=" + OAuth._redirectUri('meteor-developer', config);
OAuth.launchLogin({
loginService: "meteor-developer",
loginStyle: loginStyle,
loginUrl: loginUrl,
credentialRequestCompleteCallback: credentialRequestCompleteCallback,
credentialToken: credentialToken,
popupOptions: {width: 470, height: 490}
});
};
MeteorDeveloperAccounts.requestCredential = requestCredential;