Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 96 - Add support for 'redirectOnError' parameter during auth. #98

Merged
merged 5 commits into from
Sep 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ This package can be installed via npm or yarn.
| userAgent | The useragent that should be used with all calls to the Xero API | True |
| consumerKey | The consumer key that is required with all calls to the Xero API., | True |
| consumerSecret | The secret key from the developer portal that is required to authenticate your API calls | True |
| AuthorizeCallbackUrl | The callback that Xero should invoke when the authorization is successful. | False |
| authorizeCallbackUrl | The callback that Xero should invoke when the authorization is successful. | False |
| privateKeyPath | The filesystem path to your privatekey.pem file to sign the API calls | False |
| runscopeBucketId | Your personal runscope bucket for debugging API calls | False |
| redirectOnError | Whether the Xero Auth process should redirect to your app in the event the user clicks 'Cancel' | False |
---

```javascript
Expand All @@ -91,7 +92,8 @@ This package can be installed via npm or yarn.
"consumerKey": "AAAAAAAAAAAAAAAAAA",
"consumerSecret": "BBBBBBBBBBBBBBBBBBBB",
"authorizeCallbackUrl": 'https://www.mywebsite.com/xerocallback',
"runscopeBucketId" : "xxxyyyzzzz"
"runscopeBucketId" : "xxxyyyzzzz",
"redirectOnError" : true
}

//Sample Partner App Config
Expand All @@ -101,7 +103,8 @@ This package can be installed via npm or yarn.
"consumerSecret": "BBBBBBBBBBBBBBBBBBBB",
"authorizeCallbackUrl": 'https://www.mywebsite.com/xerocallback',
"privateKeyPath" : "/some/path/to/partner_privatekey.pem",
"runscopeBucketId" : "xxxyyyzzzz"
"runscopeBucketId" : "xxxyyyzzzz",
"redirectOnError" : true
}
```

Expand Down
6 changes: 4 additions & 2 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Object.assign(Application, {
coreAPIEndPointUrl: '/api.xro/2.0/',
payrollAPIEndPointUrl: '/payroll.xro/1.0/',
pageMaxRecords: 100,
redirectOnError: false
},
});

Expand Down Expand Up @@ -581,7 +582,6 @@ var PrivateApplication = Application.extend({

var RequireAuthorizationApplication = Application.extend({
constructor: function(options) {

Application.call(this, options);
},
init: function() {
Expand Down Expand Up @@ -652,6 +652,9 @@ var RequireAuthorizationApplication = Application.extend({
});
},
buildAuthorizeUrl: function(requestToken, other) {
other = other || {};
other['redirectOnError'] = this.options.redirectOnError

var q = Object.assign({}, { oauth_token: requestToken }, other);
return this.options.baseUrl + this.options.authorizeUrl + '?' + querystring.stringify(q);
},
Expand All @@ -674,7 +677,6 @@ var RequireAuthorizationApplication = Application.extend({

var PublicApplication = RequireAuthorizationApplication.extend({
constructor: function(config) {

RequireAuthorizationApplication.call(this, Object.assign({}, config, { type: 'public' }));
},
init: function() {
Expand Down
2 changes: 0 additions & 2 deletions lib/oauth/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ exports.OAuth.prototype._createSignatureBase = function(method, url, parameters)
//Added to support runscope usage
try {
url = url.split("runscope.net")[1].replace(/^/, "https://api.xero.com");

} catch (e) {
//do nothing. This error only occurs if runscope isn't in the url.
}
Expand Down Expand Up @@ -505,7 +504,6 @@ exports.OAuth.prototype.get = function(url, oauth_token, oauth_token_secret, cal
return this._performSecureRequest(oauth_token, oauth_token_secret, "GET", url, null, "", null, callback, options);
}


exports.OAuth.prototype._putOrPost = function(method, url, oauth_token, oauth_token_secret, post_body, post_content_type, callback) {
var extra_params = null;
if (typeof post_content_type == "function") {
Expand Down
2 changes: 1 addition & 1 deletion test/core/receipts_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('Receipts', () => {
it('create multiple Receipts', done => {
const Receipts = [];

for (let i = 0; i < 2; i += 1) {
for (let i = 0; i < 10; i += 1) {
const newReceipt = {};
Object.assign(newReceipt, sampleReceipt);
newReceipt.ReceiptID = undefined;
Expand Down
2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--timeout 60000
--timeout 120000
84 changes: 42 additions & 42 deletions test/testrunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,48 @@ describe('Accounting API Tests', () => {
});

// Accounting (Core) API Tests
// importTest('organisation_tests', `${__dirname}/core/organisation_tests.js`);
// importTest('accounts_tests', `${__dirname}/core/accounts_tests.js`);
// importTest('creditnotes_tests', `${__dirname}/core/creditnotes_tests.js`);
// importTest('currencies_tests', `${__dirname}/core/currencies_tests.js`);
// importTest('report_tests', `${__dirname}/core/report_tests.js`);
// importTest(
// 'invoicereminder_tests',
// `${__dirname}/core/invoicereminder_tests.js`
// );
// importTest('brandingtheme_tests', `${__dirname}/core/brandingtheme_tests.js`);
// importTest('taxrate_tests', `${__dirname}/core/taxrate_tests.js`);
// importTest('invoices_tests', `${__dirname}/core/invoices_tests.js`);
// importTest('payments_tests', `${__dirname}/core/payments_tests.js`);
// importTest(
// 'banktransactions_tests',
// `${__dirname}/core/banktransactions_tests.js`
// );
// importTest('banktransfers_tests', `${__dirname}/core/banktransfers_tests.js`);
// importTest(
// 'trackingcategories_tests',
// `${__dirname}/core/trackingcategories_tests.js`
// );
// importTest('items_tests', `${__dirname}/core/items_tests.js`);
// importTest('contacts_tests', `${__dirname}/core/contacts_tests.js`);
// importTest('journals_tests', `${__dirname}/core/journals_tests.js`);
// importTest(
// 'manualjournals_tests',
// `${__dirname}/core/manualjournal_tests.js`
// );
// importTest('users_tests', `${__dirname}/core/users_tests.js`);
// importTest(
// 'repeatinginvoice_tests',
// `${__dirname}/core/repeatinginvoice_tests.js`
// );
// importTest('contactgroups_tests', `${__dirname}/core/contactgroups_tests.js`);
// importTest('employees_tests', `${__dirname}/core/employees_tests.js`);
// importTest('receipts_tests', `${__dirname}/core/receipts_tests.js`);
// importTest('expenseclaims_tests', `${__dirname}/core/expenseclaims_tests.js`);
// importTest(
// 'purchaseorders_tests',
// `${__dirname}/core/purchaseorders_tests.js`
// );
importTest('organisation_tests', `${__dirname}/core/organisation_tests.js`);
importTest('accounts_tests', `${__dirname}/core/accounts_tests.js`);
importTest('creditnotes_tests', `${__dirname}/core/creditnotes_tests.js`);
importTest('currencies_tests', `${__dirname}/core/currencies_tests.js`);
importTest('report_tests', `${__dirname}/core/report_tests.js`);
importTest(
'invoicereminder_tests',
`${__dirname}/core/invoicereminder_tests.js`
);
importTest('brandingtheme_tests', `${__dirname}/core/brandingtheme_tests.js`);
importTest('taxrate_tests', `${__dirname}/core/taxrate_tests.js`);
importTest('invoices_tests', `${__dirname}/core/invoices_tests.js`);
importTest('payments_tests', `${__dirname}/core/payments_tests.js`);
importTest(
'banktransactions_tests',
`${__dirname}/core/banktransactions_tests.js`
);
importTest('banktransfers_tests', `${__dirname}/core/banktransfers_tests.js`);
importTest(
'trackingcategories_tests',
`${__dirname}/core/trackingcategories_tests.js`
);
importTest('items_tests', `${__dirname}/core/items_tests.js`);
importTest('contacts_tests', `${__dirname}/core/contacts_tests.js`);
importTest('journals_tests', `${__dirname}/core/journals_tests.js`);
importTest(
'manualjournals_tests',
`${__dirname}/core/manualjournal_tests.js`
);
importTest('users_tests', `${__dirname}/core/users_tests.js`);
importTest(
'repeatinginvoice_tests',
`${__dirname}/core/repeatinginvoice_tests.js`
);
importTest('contactgroups_tests', `${__dirname}/core/contactgroups_tests.js`);
importTest('employees_tests', `${__dirname}/core/employees_tests.js`);
importTest('receipts_tests', `${__dirname}/core/receipts_tests.js`);
importTest('expenseclaims_tests', `${__dirname}/core/expenseclaims_tests.js`);
importTest(
'purchaseorders_tests',
`${__dirname}/core/purchaseorders_tests.js`
);
importTest('attachment_tests', `${__dirname}/core/attachment_tests.js`);
});

Expand Down