Skip to content

Commit

Permalink
feat: add refreshAccessToken() API (#51)
Browse files Browse the repository at this point in the history
* feat: add refresh access token on sdk

* feat: update README.md

* chore: update readme

* chore: Update README.md
  • Loading branch information
Kadphol authored Sep 27, 2024
1 parent c864899 commit 938f531
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ getUserInfo(accessToken).then((resp) => {
});
```

#### Refresh access token

You could use a refresh token, to get a new token from the oauth server when token expired.

```typescript
sdk.refreshAccessToken(refreshToken).then((resp) => {
const token = resp.access_token;
// Do stuff with new access token
});
```

#### A note on Storage
By default, this package will use sessionStorage to persist the pkce_state. On (mostly) mobile devices there's a higher chance users are returning in a different browser tab. E.g. they kick off in a WebView & get redirected to a new tab. The sessionStorage will be empty there.

Expand Down
4 changes: 4 additions & 0 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ class Sdk {
throw new Error(error.message);
}
}

public refreshAccessToken(refreshToken: string): Promise<ITokenResponse> {
return this.pkce.refreshAccessToken(refreshToken);
}
}

export default Sdk;

0 comments on commit 938f531

Please sign in to comment.