Skip to content

Commit

Permalink
Merge pull request #147 from thivi/main
Browse files Browse the repository at this point in the history
Bump core JS SDK version and fix circular dependency issue
  • Loading branch information
thivi authored Mar 10, 2023
2 parents 03caf63 + 4af2b0d commit 9b7590e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 46 deletions.
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"author": "Asgardeo",
"license": "Apache-2.0",
"dependencies": {
"@asgardeo/auth-js": "^3.0.5",
"@asgardeo/auth-js": "^3.0.6",
"await-semaphore": "^0.1.3",
"axios": "^0.26.0",
"base64url": "^3.0.1",
Expand Down
84 changes: 43 additions & 41 deletions lib/src/helpers/authentication-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,32 @@
*/

import {
AsgardeoAuthClient,
AsgardeoAuthException,
AuthClientConfig,
AuthenticationUtils,
BasicUserInfo,
CryptoHelper,
CustomGrantConfig,
DataLayer,
DecodedIDTokenPayload,
FetchResponse,
GetAuthURLConfig,
AsgardeoAuthClient,
AsgardeoAuthException,
AuthClientConfig,
AuthenticationUtils,
BasicUserInfo,
CryptoHelper,
CustomGrantConfig,
DataLayer,
DecodedIDTokenPayload,
FetchResponse,
GetAuthURLConfig,
OIDCEndpoints,
TokenResponse
} from "@asgardeo/auth-js";
import { SPAHelper } from "./spa-helper";
import { Message, SPAUtils, SessionManagementHelperInterface } from "..";
import {
ACCESS_TOKEN_INVALID,
CHECK_SESSION_SIGNED_IN,
CHECK_SESSION_SIGNED_OUT,
import {
ACCESS_TOKEN_INVALID,
CHECK_SESSION_SIGNED_IN,
CHECK_SESSION_SIGNED_OUT,
CUSTOM_GRANT_CONFIG,
ERROR,
ERROR_DESCRIPTION,
PROMPT_NONE_IFRAME,
REFRESH_ACCESS_TOKEN_ERR0R,
RP_IFRAME,
Storage
Storage
} from "../constants";
import {
AuthorizationInfo,
Expand All @@ -52,9 +51,12 @@ import {
HttpRequestConfig,
HttpResponse,
MainThreadClientConfig,
Message,
SessionManagementHelperInterface,
WebWorkerClientConfig
} from "../models";
import { SPACustomGrantConfig } from "../models/request-custom-grant";
import { SPAUtils } from "../utils";

export class AuthenticationHelper<
T extends MainThreadClientConfig | WebWorkerClientConfig
Expand Down Expand Up @@ -106,11 +108,11 @@ export class AuthenticationHelper<
): Promise<BasicUserInfo | FetchResponse> {
let useDefaultEndpoint = true;
let matches = false;

// If the config does not contains a token endpoint, default token endpoint will be used.
if (config?.tokenEndpoint) {
useDefaultEndpoint = false;

for (const baseUrl of [
...((await this._dataLayer.getConfigData())?.resourceServerURLs ?? []),
(config as any).baseUrl
Expand All @@ -131,14 +133,14 @@ export class AuthenticationHelper<
return this._authenticationClient
.requestCustomGrant(config)
.then(async (response: FetchResponse | TokenResponse) => {
if (enableRetrievingSignOutURLFromSession &&
if (enableRetrievingSignOutURLFromSession &&
typeof enableRetrievingSignOutURLFromSession === "function") {
enableRetrievingSignOutURLFromSession(config);
}

if (config.returnsSession) {
this._spaHelper.refreshAccessTokenAutomatically(this);

return this._authenticationClient.getBasicUserInfo();
} else {
return response as FetchResponse;
Expand Down Expand Up @@ -191,7 +193,7 @@ export class AuthenticationHelper<
const refreshTokenError: Message<string> = {
type: REFRESH_ACCESS_TOKEN_ERR0R
}

window.postMessage(refreshTokenError);
return Promise.reject(error);
}
Expand Down Expand Up @@ -236,16 +238,16 @@ export class AuthenticationHelper<
} catch (refreshError: any) {
if (isHttpHandlerEnabled) {
if (typeof httpErrorCallback === "function") {
await httpErrorCallback({
...error,
code: ACCESS_TOKEN_INVALID
await httpErrorCallback({
...error,
code: ACCESS_TOKEN_INVALID
});
}
if (typeof httpFinishCallback === "function") {
httpFinishCallback();
}
}

throw new AsgardeoAuthException(
"SPA-AUTH_HELPER-HR-SE01",
refreshError?.name ?? "Refresh token request failed.",
Expand Down Expand Up @@ -307,10 +309,10 @@ export class AuthenticationHelper<
): Promise<HttpResponse[] | undefined> {
let matches = true;
const config = await this._dataLayer.getConfigData();

for (const requestConfig of requestConfigs) {
let urlMatches = false;

for (const baseUrl of [
...((await config)?.resourceServerURLs ?? []),
(config as any).baseUrl
Expand All @@ -321,21 +323,21 @@ export class AuthenticationHelper<
break;
}
}

if (!urlMatches) {
matches = false;

break;
}
}

const requests: Promise<HttpResponse<any>>[] = [];

if (matches) {
requestConfigs.forEach((request) => {
requests.push(httpClient.request(request));
});

return (
httpClient?.all &&
httpClient
Expand All @@ -360,7 +362,7 @@ export class AuthenticationHelper<
httpFinishCallback();
}
}

throw new AsgardeoAuthException(
"SPA-AUTH_HELPER-HRA-SE01",
refreshError?.name ?? "Refresh token request failed.",
Expand All @@ -369,7 +371,7 @@ export class AuthenticationHelper<
"access token following a 401 response from the server."
);
}

if (refreshTokenResponse) {
return (
httpClient.all &&
Expand All @@ -387,13 +389,13 @@ export class AuthenticationHelper<
httpFinishCallback();
}
}

return Promise.reject(error);
})
);
}
}

if (isHttpHandlerEnabled) {
if (typeof httpErrorCallback === "function") {
await httpErrorCallback(error);
Expand All @@ -402,7 +404,7 @@ export class AuthenticationHelper<
httpFinishCallback();
}
}

return Promise.reject(error);
})
);
Expand Down Expand Up @@ -458,8 +460,8 @@ export class AuthenticationHelper<

// Enable OIDC Sessions Management only if it is set to true in the config.
if (
checkSession &&
typeof checkSession === "function" &&
checkSession &&
typeof checkSession === "function" &&
config.enableOIDCSessionManagement
) {
checkSession();
Expand Down
8 changes: 4 additions & 4 deletions lib/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"@jridgewell/gen-mapping" "^0.1.0"
"@jridgewell/trace-mapping" "^0.3.9"

"@asgardeo/auth-js@^3.0.5":
version "3.0.5"
resolved "https://registry.yarnpkg.com/@asgardeo/auth-js/-/auth-js-3.0.5.tgz#f68b620a8e72f097878ae07bc21fef9f6e454d9b"
integrity sha512-70RNIvNdWAQIHcNmiHDo19+BbEa1ASncOVJG90wwHMpVsahzN0PISxJejr7UbO/rvNN4HOm/Q1azhE7UkwboZQ==
"@asgardeo/auth-js@^3.0.6":
version "3.0.6"
resolved "https://registry.yarnpkg.com/@asgardeo/auth-js/-/auth-js-3.0.6.tgz#619ad64a8d7b8a4cdc859bbce5ef0deb00b7db0b"
integrity sha512-UdA5wNADGjND+7UBHutsUPcseTjvqp8Ymsm+rMBK0Tc4gO81dv4YYVBvXs155SiNmvHM/FUc7uUTbJRtqz63sg==

"@babel/cli@^7.17.6":
version "7.18.9"
Expand Down

0 comments on commit 9b7590e

Please sign in to comment.