-
Notifications
You must be signed in to change notification settings - Fork 63
Add token refresh logic if the user's access token is expired #528
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@asgardeo/browser': patch | ||
| --- | ||
|
|
||
| Add token refresh logic if the user's access token is expired |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -706,6 +706,28 @@ export class AuthenticationHelper<T extends MainThreadClientConfig | WebWorkerCl | |
| } | ||
|
|
||
| public async isSignedIn(): Promise<boolean> { | ||
| return this._authenticationClient.isSignedIn(); | ||
| if (await this._authenticationClient.isSignedIn()) { | ||
| return true; | ||
| } | ||
|
|
||
| // A refresh is already in progress — wait for it to finish then re-check. | ||
| if (this._isTokenRefreshing) { | ||
| await SPAUtils.until(() => !this._isTokenRefreshing); | ||
|
|
||
| return this._authenticationClient.isSignedIn(); | ||
| } | ||
|
|
||
| // Token may be expired — attempt a silent refresh before giving up. | ||
| try { | ||
| this._isTokenRefreshing = true; | ||
| await this.refreshAccessToken(); | ||
| this._isTokenRefreshing = false; | ||
|
|
||
| return true; | ||
| } catch { | ||
| this._isTokenRefreshing = false; | ||
|
|
||
| return false; | ||
| } | ||
|
Comment on lines
+709
to
+731
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we could use something like the following version to keep public async isSignedIn(): Promise<boolean> {
if (await this._authenticationClient.isSignedIn()) {
return this._authenticationClient.isSignedIn();
}
if (this._isTokenRefreshing) {
await SPAUtils.until(() => !this._isTokenRefreshing);
return this._authenticationClient.isSignedIn();
}
try {
this._isTokenRefreshing = true;
await this.refreshAccessToken();
} catch {
// Ignore refresh failures. Signed-in state is determined below.
} finally {
this._isTokenRefreshing = false;
}
return this._authenticationClient.isSignedIn();
}
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to do this IMO. But +1 to merge the already tested path immediately and later bring this in. |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.