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

feat: add refreshAccessToken() API #51

Merged
merged 4 commits into from
Sep 27, 2024
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
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;
Loading