Skip to content

Commit b5f75b0

Browse files
authored
Merge branch 'main' into fix/rename-flowId-to-flowExecId
2 parents b511cea + c3c428f commit b5f75b0

41 files changed

Lines changed: 453 additions & 234 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/browser/CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
# @asgardeo/browser
22

3+
## 0.6.3
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
[[`7e8151d`](https://github.com/asgardeo/javascript/commit/7e8151d68786d53566502a1a164428635a803ec8)]:
9+
- @asgardeo/javascript@0.16.1
10+
11+
## 0.6.2
12+
13+
### Patch Changes
14+
15+
- [#445](https://github.com/asgardeo/javascript/pull/445)
16+
[`6e6fb7f`](https://github.com/asgardeo/javascript/commit/6e6fb7fdd525e064e517c4e5b2a538c1d7b2c286) Thanks
17+
[@NipuniBhagya](https://github.com/NipuniBhagya)! - Fix the race condition in token refresh
18+
19+
## 0.6.1
20+
21+
### Patch Changes
22+
23+
- [#442](https://github.com/asgardeo/javascript/pull/442)
24+
[`ed8f055`](https://github.com/asgardeo/javascript/commit/ed8f055630cb4078bd0164a1969718510a5d1b5b) Thanks
25+
[@NipuniBhagya](https://github.com/NipuniBhagya)! - Fix auto refresh token logic error
26+
327
## 0.6.0
428

529
### Minor Changes

packages/browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@asgardeo/browser",
3-
"version": "0.6.0",
3+
"version": "0.6.3",
44
"description": "Browser-specific implementation of Asgardeo JavaScript SDK.",
55
"keywords": [
66
"asgardeo",

packages/browser/src/__legacy__/client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,12 @@ export class AsgardeoSPAClient {
11071107
return this._client?.isSignedIn();
11081108
}
11091109

1110+
public async startAutoRefreshToken(): Promise<void> {
1111+
await this.isInitialized();
1112+
1113+
return (this._client as MainThreadClientInterface)?.startAutoRefreshToken();
1114+
}
1115+
11101116
/**
11111117
* This method specifies if there is an active session in the browser or not.
11121118
*

packages/browser/src/__legacy__/clients/main-thread-client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@ export const MainThreadClient = async (
415415
return _authenticationClient.decodeJwtToken<T>(token);
416416
};
417417

418+
const startAutoRefreshToken = async (): Promise<void> => {
419+
_spaHelper.clearRefreshTokenTimeout();
420+
await _spaHelper.refreshAccessTokenAutomatically(_authenticationHelper);
421+
};
422+
418423
return {
419424
disableHttpHandler,
420425
enableHttpHandler,
@@ -441,6 +446,7 @@ export const MainThreadClient = async (
441446
signIn,
442447
signOut,
443448
signInSilently,
449+
startAutoRefreshToken,
444450
reInitialize,
445451
decodeJwtToken,
446452
};

packages/browser/src/__legacy__/helpers/spa-helper.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
2+
* Copyright (c) 2020-2026, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
33
*
44
* WSO2 Inc. licenses this file to you under the Apache License,
55
* Version 2.0 (the "License"); you may not use this file except
@@ -24,6 +24,7 @@ import {MainThreadClientConfig, WebWorkerClientConfig} from '../models/client-co
2424
export class SPAHelper<T extends MainThreadClientConfig | WebWorkerClientConfig> {
2525
private _authenticationClient: AsgardeoAuthClient<T>;
2626
private _storageManager: StorageManager<T>;
27+
private _isTokenRefreshLoading: boolean = false;
2728

2829
public constructor(authClient: AsgardeoAuthClient<T>) {
2930
this._authenticationClient = authClient;
@@ -42,13 +43,37 @@ export class SPAHelper<T extends MainThreadClientConfig | WebWorkerClientConfig>
4243

4344
const sessionData = await this._storageManager.getSessionData();
4445
if (sessionData.refresh_token) {
45-
// Refresh 10 seconds before the expiry time
46-
const expiryTime = parseInt(sessionData.expires_in);
47-
const time = expiryTime <= 10 ? expiryTime : expiryTime - 10;
46+
if (sessionData.created_at == null || sessionData.expires_in == null) {
47+
return;
48+
}
49+
50+
const TOKEN_REFRESH_BUFFER_MS = 10_000;
51+
const expiryTime = Number(sessionData.expires_in) * 1000;
52+
const absoluteExpiryTime: number = sessionData.created_at + expiryTime;
53+
const timeUntilRefresh = absoluteExpiryTime - Date.now() - TOKEN_REFRESH_BUFFER_MS;
54+
55+
if (timeUntilRefresh <= 0) {
56+
if (this._isTokenRefreshLoading) return;
57+
58+
this._isTokenRefreshLoading = true;
59+
try {
60+
await authenticationHelper.refreshAccessToken();
61+
} finally {
62+
this._isTokenRefreshLoading = false;
63+
}
64+
return;
65+
}
4866

4967
const timer = setTimeout(async () => {
50-
await authenticationHelper.refreshAccessToken();
51-
}, time * 1000);
68+
if (this._isTokenRefreshLoading) return;
69+
70+
this._isTokenRefreshLoading = true;
71+
try {
72+
await authenticationHelper.refreshAccessToken();
73+
} finally {
74+
this._isTokenRefreshLoading = false;
75+
}
76+
}, timeUntilRefresh);
5277

5378
await this._storageManager.setTemporaryDataParameter(
5479
TokenConstants.Storage.StorageKeys.REFRESH_TOKEN_TIMER,

packages/browser/src/__legacy__/models/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export interface MainThreadClientInterface {
6767
getAccessToken(sessionId?: string): Promise<string>;
6868
getStorageManager(): Promise<StorageManager<MainThreadClientConfig>>;
6969
isSignedIn(): Promise<boolean>;
70+
startAutoRefreshToken(): Promise<void>;
7071
reInitialize(config: Partial<AuthClientConfig<MainThreadClientConfig>>): Promise<void>;
7172
signInSilently(
7273
additionalParams?: Record<string, string | boolean>,

packages/express/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# @asgardeo/express
22

3+
## 0.0.69
4+
5+
### Patch Changes
6+
7+
- Updated dependencies []:
8+
- @asgardeo/node@0.0.70
9+
310
## 0.0.68
411

512
### Patch Changes

packages/express/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@asgardeo/express",
3-
"version": "0.0.68",
3+
"version": "0.0.69",
44
"description": "Express.js implementation of Asgardeo JavaScript SDK.",
55
"keywords": [
66
"asgardeo",

packages/i18n/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# @asgardeo/i18n
22

3+
## 0.4.5
4+
5+
### Patch Changes
6+
7+
- [#447](https://github.com/asgardeo/javascript/pull/447)
8+
[`7e8151d`](https://github.com/asgardeo/javascript/commit/7e8151d68786d53566502a1a164428635a803ec8) Thanks
9+
[@ThaminduDilshan](https://github.com/ThaminduDilshan)! - Add flow native render support for invite flows removing the
10+
custom workarounds
11+
312
## 0.4.4
413

514
### Patch Changes

packages/i18n/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@asgardeo/i18n",
3-
"version": "0.4.4",
3+
"version": "0.4.5",
44
"description": "Internationalization (i18n) package for Asgardeo JavaScript SDKs.",
55
"keywords": [
66
"asgardeo",

0 commit comments

Comments
 (0)