Skip to content

Commit

Permalink
Merge pull request #454 from XeroAPI/state_readme
Browse files Browse the repository at this point in the history
Readme update for state
  • Loading branch information
SerKnight authored Sep 4, 2020
2 parents 98a4ae9 + b387335 commit 3e535de
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ Call `apiCallback` function with the response url which returns a tokenSet you c
*The `tokenSet` can also be accessed from the client as `xero.readTokenSet()`.*
> `http://localhost:${port}/callback`
```js
console.log(xero.config.state)
=> 'returnPage=my-sweet-dashboard'
const { TokenSet } = require('openid-client');
const tokenSet: TokenSet = await xero.apiCallback(req.url);
const tokenSet = await xero.apiCallback(req.url);
```
The `tokenSet` is what you should store in your database. That object is what you will need to pass to the client. It contains your access_token and refresh_token as well as other information regarding your connection.
```js
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xero-node",
"version": "4.8.0",
"version": "4.8.1",
"description": "Xero NodeJS OAuth 2.0 client for xero-node",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/XeroClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface XeroAccessToken {
}

export class XeroClient {
constructor(private readonly config?: IXeroClientConfig) {
constructor(readonly config?: IXeroClientConfig) {
this.accountingApi = new xero.AccountingApi();
this.assetApi = new xero.AssetApi();
this.projectApi = new xero.ProjectApi();
Expand Down
4 changes: 3 additions & 1 deletion src/test/xeroClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ describe('the XeroClient', () => {
scopes: 'openid profile email accounting.transactions offline_access'.split(" "),
state: '12345'
});
expect(xeroWithState.config.state).toEqual('12345');

const authUrlWithState = await xeroWithState.buildConsentUrl();
expect(authUrlWithState.includes('state=12345')).toEqual(true);
});
Expand All @@ -72,7 +74,7 @@ describe('the XeroClient', () => {
httpTimeout: 3000
});
const xeroClient = await xeroWithConfig.initialize()
expect(xeroClient['config']['httpTimeout']).toEqual(3000)
expect(xeroClient.config.httpTimeout).toEqual(3000)
});

it('initialize() returns the client', async () => {
Expand Down

0 comments on commit 3e535de

Please sign in to comment.