Skip to content

Commit

Permalink
Merge pull request #405 from XeroAPI/refresh_without_full_client
Browse files Browse the repository at this point in the history
Refresh without full client
  • Loading branch information
SerKnight authored Apr 14, 2020
2 parents 44c9999 + 46f872e commit a203fc5
Show file tree
Hide file tree
Showing 158 changed files with 1,062 additions and 948 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ console.log(tenants || xero.tenants)
Once you have a valid token/tokenSet saved you can set the tokenSet on the client without going through the callback by calling `setTokenSet`.

For example - once a user authenticates you can refresh the token (which will also set the new token on the client) to make authorized api calls.

There are two ways to refresh a token.

```js
// refreshToken()
const validTokenSet = await xero.refreshToken()
```

If you already generated a valid access token, you can initialize an empty client and refresh any saved access_tokens by passing the client, secret, and refresh_token to refreshWithRefreshToken()
```js
const newXeroClient = new XeroClient()
const refreshedTokenSet = await newXeroClient.refreshWithRefreshToken(client_id, client_secret, tokenSet.refresh_token)
```

Making AUthorized API calls:

```js
const tokenSet = getTokenSetFromDatabase(userId) // example function name

Expand Down Expand Up @@ -255,8 +271,8 @@ if (tokenSet.expired()) {
// refreshToken()
const validTokenSet = await xero.refreshToken()

// refreshTokenUsingTokenSet()
await xero.refreshTokenUsingTokenSet(tokenSet)
// refreshWithRefreshToken()
await xero.refreshWithRefreshToken(client_id, client_secret, tokenSet.refresh_token)

// disconnect()
await xero.disconnect(xero.tenants[0].id)
Expand Down
Loading

0 comments on commit a203fc5

Please sign in to comment.