Skip to content

Commit

Permalink
Merge pull request #616 from daffron/master
Browse files Browse the repository at this point in the history
Add timeout, and clock tolerance configuration options
  • Loading branch information
RettBehrens authored Dec 2, 2022
2 parents 9da2368 + 426127d commit 39d67a2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ const xero = new XeroClient({
redirectUris: [`http://localhost:${port}/callback`],
scopes: 'openid profile email accounting.transactions offline_access'.split(" "),
state: 'returnPage=my-sweet-dashboard', // custom params (optional)
httpTimeout: 3000 // ms (optional)
httpTimeout: 3000, // ms (optional)
clockTolerance: 10 // seconds (optional)
});
```

Expand Down Expand Up @@ -234,7 +235,8 @@ const xero = new XeroClient({
grantType: 'client_credentials', // only used for client_credentials auth flow
scopes: 'openid profile email accounting.transactions offline_access'.split(" "), // not used for client_credentials auth flow
state: 'returnPage=my-sweet-dashboard', // custom params (optional), not used for client_credentials auth flow
httpTimeout: 3000 // ms (optional)
httpTimeout: 3000, // ms (optional)
clockTolerance: 10 // seconds (optional)
});

xero.accountingApi
Expand Down
10 changes: 6 additions & 4 deletions src/XeroClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export interface IXeroClientConfig {
grantType?: string;
scopes?: string[],
state?: string,
httpTimeout?: number
httpTimeout?: number,
clockTolerance?: number
};

export interface XeroIdToken {
Expand Down Expand Up @@ -89,8 +90,9 @@ export class XeroClient {
if (this.config) {
custom.setHttpOptionsDefaults({
retry: {
maxRetryAfter: this.config.httpTimeout || 2500
}
maxRetryAfter: this.config.httpTimeout || 3500
},
timeout: this.config.httpTimeout || 3500
})

const issuer = await Issuer.discover('https://identity.xero.com');
Expand All @@ -100,7 +102,7 @@ export class XeroClient {
redirect_uris: this.config.redirectUris,
});

this.openIdClient[custom.clock_tolerance] = 5;
this.openIdClient[custom.clock_tolerance] = this.config.clockTolerance || 5;
}
return this;
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/xeroClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ describe('the XeroClient', () => {
expect(xeroClient.config.httpTimeout).toEqual(3000)
});

it('allows for the configuration of the openid-client clock tolerance', async () => {
const xeroWithConfig = new XeroClient({
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
redirectUris: [`http://localhost:5000/callback`],
scopes: 'openid profile email accounting.transactions offline_access'.split(" "),
clockTolerance: 10
});
const xeroClient = await xeroWithConfig.initialize()
expect(xeroClient.config?.clockTolerance).toEqual(10)
});

it('allows for the configuration of the Xero Client for use of client credentials grant', async () => {
const xeroCustomConnection = new XeroClient({
clientId: 'YOUR_CLIENT_ID',
Expand Down

0 comments on commit 39d67a2

Please sign in to comment.