-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickbooks_client.js
42 lines (36 loc) · 1.6 KB
/
quickbooks_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
Quickbooks = {};
// Request Quickbooks credentials for the user
// @param options {optional} XXX support options.requestPermissions
// @param credentialRequestCompleteCallback {Function} Callback function to call on
// completion. Takes one argument, credentialToken on success, or Error on
// error.
Quickbooks.requestCredential = function (options, credentialRequestCompleteCallback) {
// support both (options, callback) and (callback).
if (!credentialRequestCompleteCallback && typeof options === 'function') {
credentialRequestCompleteCallback = options;
options = {};
}
var config = ServiceConfiguration.configurations.findOne({service: 'quickbooks'});
if (!config) {
credentialRequestCompleteCallback && credentialRequestCompleteCallback(
new ServiceConfiguration.ConfigError());
return;
}
var credentialToken = Random.secret();
// We need to keep credentialToken across the next two 'steps' so we're adding
// a credentialToken parameter to the url and the callback url that we'll be returned
// to by oauth provider
var loginStyle = OAuth._loginStyle('quickbooks', config, options);
// url to app, enters "step 1" as described in
// packages/accounts-oauth1-helper/oauth1_server.js
var loginUrl = Meteor.absoluteUrl(
'_oauth/quickbooks/?requestTokenAndRedirect=true'
+ '&state=' + OAuth._stateParam(loginStyle, credentialToken));
OAuth.launchLogin({
loginService: "quickbooks",
loginStyle: loginStyle,
loginUrl: loginUrl,
credentialRequestCompleteCallback: credentialRequestCompleteCallback,
credentialToken: credentialToken
});
};