= (props: SignInProps): ReactElement => {
)}
>
)}
- {(authContext?.authResponse?.flowStatus === FlowStatus.SuccessCompleted || isAuthenticated) && (
+ {(authContext?.authResponse?.flowStatus === FlowStatus.SuccessCompleted || isSignedIn) && (
Successfully Authenticated
)}
diff --git a/packages/__legacy__/react/src/components/SignedIn/SignedIn.tsx b/packages/__legacy__/react/src/components/SignedIn/SignedIn.tsx
index 8f719714..58dabe2a 100644
--- a/packages/__legacy__/react/src/components/SignedIn/SignedIn.tsx
+++ b/packages/__legacy__/react/src/components/SignedIn/SignedIn.tsx
@@ -30,9 +30,9 @@ import SignedProps from '../../models/signed-props';
*/
const SignedIn: FC> = (props: PropsWithChildren) => {
const {fallback = null, children} = props;
- const {isAuthenticated} = useAuthentication();
+ const {isSignedIn} = useAuthentication();
- return isAuthenticated ? children : fallback;
+ return isSignedIn ? children : fallback;
};
export default SignedIn;
diff --git a/packages/__legacy__/react/src/components/SignedOut/SignedOut.tsx b/packages/__legacy__/react/src/components/SignedOut/SignedOut.tsx
index b6aa0c27..1e5825a4 100644
--- a/packages/__legacy__/react/src/components/SignedOut/SignedOut.tsx
+++ b/packages/__legacy__/react/src/components/SignedOut/SignedOut.tsx
@@ -30,9 +30,9 @@ import SignedProps from '../../models/signed-props';
*/
const SignedOut: FC> = (props: PropsWithChildren) => {
const {fallback = null, children} = props;
- const {isAuthenticated} = useAuthentication();
+ const {isSignedIn} = useAuthentication();
- return !isAuthenticated ? children : fallback;
+ return !isSignedIn ? children : fallback;
};
export default SignedOut;
diff --git a/packages/__legacy__/react/src/hooks/use-authentication.ts b/packages/__legacy__/react/src/hooks/use-authentication.ts
index 43802cfa..08e75395 100644
--- a/packages/__legacy__/react/src/hooks/use-authentication.ts
+++ b/packages/__legacy__/react/src/hooks/use-authentication.ts
@@ -26,13 +26,13 @@ import UseAuthentication from '../models/use-authentication';
* `useAuthentication` is a custom hook that provides access to the authentication context.
* It returns an object containing the current user, the authentication status, the access token, and a sign out function.
*
- * @returns {UseAuthentication} An object containing the current user (`user`), the authentication status (`isAuthenticated`),
+ * @returns {UseAuthentication} An object containing the current user (`user`), the authentication status (`isSignedIn`),
* the access token (`accessToken`), and a sign out function (`signOut`).
*/
const useAuthentication = (): UseAuthentication => {
const contextValue: AuthContext = useContext(AsgardeoContext);
- const {accessToken, authResponse, isAuthenticated, isGlobalLoading, setUsername, user, username} = contextValue;
+ const {accessToken, authResponse, isSignedIn, isGlobalLoading, setUsername, user, username} = contextValue;
const signOut: () => void = () => {
signOutApiCall().then(() => {
@@ -46,7 +46,7 @@ const useAuthentication = (): UseAuthentication => {
return {
accessToken,
authResponse,
- isAuthenticated,
+ isSignedIn,
isGlobalLoading,
setUsername,
signOut,
diff --git a/packages/__legacy__/react/src/models/auth-context.ts b/packages/__legacy__/react/src/models/auth-context.ts
index 8bebb966..4a1e1f93 100644
--- a/packages/__legacy__/react/src/models/auth-context.ts
+++ b/packages/__legacy__/react/src/models/auth-context.ts
@@ -23,7 +23,7 @@ interface AuthContext {
authResponse: AuthApiResponse;
config: UIAuthConfig;
isAuthLoading: boolean;
- isAuthenticated: boolean | undefined;
+ isSignedIn: boolean | undefined;
isBrandingLoading: boolean;
isComponentLoading: boolean;
isGlobalLoading: boolean;
diff --git a/packages/__legacy__/react/src/models/use-authentication.ts b/packages/__legacy__/react/src/models/use-authentication.ts
index ac52bd89..d48692d8 100644
--- a/packages/__legacy__/react/src/models/use-authentication.ts
+++ b/packages/__legacy__/react/src/models/use-authentication.ts
@@ -21,7 +21,7 @@ import {AuthApiResponse, MeAPIResponse} from '@asgardeo/js';
interface UseAuthentication {
accessToken: string;
authResponse: AuthApiResponse;
- isAuthenticated: Promise | boolean;
+ isSignedIn: Promise | boolean;
isGlobalLoading: boolean;
setUsername: (username: string) => void;
signOut: () => void;
diff --git a/packages/__legacy__/react/src/providers/AsgardeoProvider.tsx b/packages/__legacy__/react/src/providers/AsgardeoProvider.tsx
index 0400cee9..971dcc98 100644
--- a/packages/__legacy__/react/src/providers/AsgardeoProvider.tsx
+++ b/packages/__legacy__/react/src/providers/AsgardeoProvider.tsx
@@ -53,7 +53,7 @@ const AsgardeoProvider: FC> = (
const {children, config, store, branding} = props;
const [accessToken, setAccessToken] = useState('');
- const [isAuthenticated, setIsAuthenticated] = useState();
+ const [isSignedIn, setIsAuthenticated] = useState();
const [user, setUser] = useState();
const [isBrandingLoading, setIsBrandingLoading] = useState(true);
const [isTextLoading, setIsTextLoading] = useState(true);
@@ -89,7 +89,7 @@ const AsgardeoProvider: FC> = (
* Sets the authentication status and access token.
*/
const setAuthentication: () => void = useCallback((): void => {
- authClient.isAuthenticated().then((isAuth: boolean) => {
+ authClient.isSignedIn().then((isAuth: boolean) => {
setIsAuthenticated(isAuth);
if (isAuth) {
@@ -124,10 +124,10 @@ const AsgardeoProvider: FC> = (
/**
* Send the 'code' and 'state' to the parent window and close the current window (popup)
*/
- window.opener.postMessage({code, state}, config.signInRedirectURL);
+ window.opener.postMessage({code, state}, config.afterSignInUrl);
window.close();
}
- }, [config.signInRedirectURL, setAuthentication]);
+ }, [config.afterSignInUrl, setAuthentication]);
const value: AuthContext = useMemo(
() => ({
@@ -135,7 +135,7 @@ const AsgardeoProvider: FC> = (
authResponse,
config,
isAuthLoading,
- isAuthenticated,
+ isSignedIn,
isBrandingLoading,
isComponentLoading,
isGlobalLoading: isAuthLoading || isBrandingLoading || isComponentLoading || isTextLoading,
@@ -158,7 +158,7 @@ const AsgardeoProvider: FC> = (
authResponse,
config,
isAuthLoading,
- isAuthenticated,
+ isSignedIn,
isBrandingLoading,
isComponentLoading,
isTextLoading,
diff --git a/packages/__legacy__/react/src/utils/crypto-utils.ts b/packages/__legacy__/react/src/utils/crypto-utils.ts
index 56675656..b351a9e3 100644
--- a/packages/__legacy__/react/src/utils/crypto-utils.ts
+++ b/packages/__legacy__/react/src/utils/crypto-utils.ts
@@ -70,7 +70,7 @@ export default class SPACryptoUtils implements Crypto {
idToken: string,
jwk: Partial,
algorithms: string[],
- clientID: string,
+ clientId: string,
issuer: string,
subject: string,
clockTolerance?: number,
@@ -78,7 +78,7 @@ export default class SPACryptoUtils implements Crypto {
): Promise {
const jwtVerifyOptions: JwtVerifyOptions = {
algorithms,
- audience: clientID,
+ audience: clientId,
clockTolerance,
issuer,
subject,
diff --git a/packages/browser/README.md b/packages/browser/README.md
index 5f334aeb..64f2dca7 100644
--- a/packages/browser/README.md
+++ b/packages/browser/README.md
@@ -28,8 +28,8 @@ import { AsgardeoAuthClient } from "@asgardeo/browser";
// Initialize the auth client
const authClient = new AsgardeoAuthClient({
- signInRedirectURL: "https://localhost:3000",
- clientID: "",
+ afterSignInUrl: "https://localhost:3000",
+ clientId: "",
baseUrl: "https://api.asgardeo.io/t/"
});
@@ -37,7 +37,7 @@ const authClient = new AsgardeoAuthClient({
authClient.signIn();
// Get user info after authentication
-const userInfo = await authClient.getBasicUserInfo();
+const userInfo = await authClient.getUser();
// Sign out
authClient.signOut();
diff --git a/packages/browser/package.json b/packages/browser/package.json
index edb5091f..a75d8004 100644
--- a/packages/browser/package.json
+++ b/packages/browser/package.json
@@ -1,15 +1,15 @@
{
"name": "@asgardeo/browser",
- "version": "0.0.0",
+ "version": "0.0.1",
"description": "Browser-specific implementation of Asgardeo JavaScript SDK.",
"keywords": [
"asgardeo",
"browser",
"spa"
],
- "homepage": "https://github.com/asgardeo/javascript/tree/main/packages/browser#readme",
+ "homepage": "https://github.com/asgardeo/web-ui-sdks/tree/main/packages/browser#readme",
"bugs": {
- "url": "https://github.com/asgardeo/javascript/issues"
+ "url": "https://github.com/asgardeo/web-ui-sdks/issues"
},
"author": "WSO2",
"license": "Apache-2.0",
@@ -28,7 +28,7 @@
"types": "dist/index.d.ts",
"repository": {
"type": "git",
- "url": "https://github.com/asgardeo/javascript",
+ "url": "https://github.com/asgardeo/web-ui-sdks",
"directory": "packages/browser"
},
"scripts": {
@@ -73,4 +73,4 @@
"publishConfig": {
"access": "public"
}
-}
\ No newline at end of file
+}
diff --git a/packages/browser/src/__legacy__/client.ts b/packages/browser/src/__legacy__/client.ts
index 17a878d9..11190d60 100755
--- a/packages/browser/src/__legacy__/client.ts
+++ b/packages/browser/src/__legacy__/client.ts
@@ -20,15 +20,14 @@ import {
AsgardeoAuthClient,
AsgardeoAuthException,
AuthClientConfig,
- BasicUserInfo,
IsomorphicCrypto,
- CustomGrantConfig,
- DataLayer,
+ TokenExchangeRequestConfig,
+ StorageManager,
IdTokenPayload,
- FetchResponse,
OIDCEndpoints,
+ User,
} from '@asgardeo/javascript';
-import WorkerFile from '../worker';
+// import WorkerFile from '../worker';
import {MainThreadClient, WebWorkerClient} from './clients';
import {Hooks, REFRESH_ACCESS_TOKEN_ERR0R} from './constants';
import {AuthenticationHelper, SPAHelper} from './helpers';
@@ -45,7 +44,7 @@ import {
WebWorkerClientConfig,
WebWorkerClientInterface,
} from './models';
-import {Storage} from './models/storage';
+import {BrowserStorage} from './models/storage';
import {SPAUtils} from './utils';
/**
@@ -54,11 +53,10 @@ import {SPAUtils} from './utils';
const DefaultConfig: Partial> = {
autoLogoutOnTokenRefreshError: true,
checkSessionInterval: 3,
- clientHost: origin,
enableOIDCSessionManagement: false,
periodicTokenRefresh: false,
sessionRefreshInterval: 300,
- storage: Storage.SessionStorage,
+ storage: BrowserStorage.SessionStorage,
};
/**
@@ -70,12 +68,13 @@ const DefaultConfig: Partial> = {
export class AsgardeoSPAClient {
protected static _instances: Map = new Map();
protected _client: WebWorkerClientInterface | MainThreadClientInterface | undefined;
- protected _storage: Storage | undefined;
+ protected _storage: BrowserStorage | undefined;
protected _authHelper: typeof AuthenticationHelper = AuthenticationHelper;
- protected _worker: new () => Worker = WorkerFile;
+ // protected _worker: new () => Worker = WorkerFile;
+ protected _worker = null;
protected _initialized: boolean = false;
protected _startedInitialize: boolean = false;
- protected _onSignInCallback: (response: BasicUserInfo) => void = () => null;
+ protected _onSignInCallback: (response: User) => void = () => null;
protected _onSignOutCallback: () => void = () => null;
protected _onSignOutFailedCallback: (error: SignOutError) => void = () => null;
protected _onEndUserSession: (response: any) => void = () => null;
@@ -95,13 +94,13 @@ export class AsgardeoSPAClient {
}
}
- public instantiateWorker(worker: new () => Worker) {
- if (worker) {
- this._worker = worker;
- } else {
- this._worker = WorkerFile;
- }
- }
+ // public instantiateWorker(worker: new () => Worker) {
+ // if (worker) {
+ // this._worker = worker;
+ // } else {
+ // this._worker = WorkerFile;
+ // }
+ // }
/**
* This method specifies if the `AsgardeoSPAClient` has been initialized or not.
@@ -112,7 +111,7 @@ export class AsgardeoSPAClient {
*
* @private
*/
- private async _isInitialized(): Promise {
+ public async isInitialized(): Promise {
if (!this._startedInitialize) {
return false;
}
@@ -148,7 +147,7 @@ export class AsgardeoSPAClient {
* @private
*/
private async _validateMethod(validateAuthentication: boolean = true): Promise {
- if (!(await this._isInitialized())) {
+ if (!(await this.isInitialized())) {
return Promise.reject(
new AsgardeoAuthException(
'SPA-AUTH_CLIENT-VM-NF01',
@@ -158,7 +157,7 @@ export class AsgardeoSPAClient {
);
}
- if (validateAuthentication && !(await this.isAuthenticated())) {
+ if (validateAuthentication && !(await this.isSignedIn())) {
return Promise.reject(
new AsgardeoAuthException(
'SPA-AUTH_CLIENT-VM-IV02',
@@ -217,8 +216,8 @@ export class AsgardeoSPAClient {
* @example
* ```
* auth.initialize({
- * signInRedirectURL: "http://localhost:3000/sign-in",
- * clientID: "client ID",
+ * afterSignInUrl: "http://localhost:3000/sign-in",
+ * clientId: "client ID",
* baseUrl: "https://api.asgardeo.io"
* });
* ```
@@ -235,16 +234,16 @@ export class AsgardeoSPAClient {
authHelper?: typeof AuthenticationHelper,
workerFile?: new () => Worker,
): Promise {
- this._storage = (config.storage as Storage) ?? Storage.SessionStorage;
+ this._storage = (config.storage as BrowserStorage) ?? BrowserStorage.SessionStorage;
this._initialized = false;
this._startedInitialize = true;
authHelper && this.instantiateAuthHelper(authHelper);
- workerFile && this.instantiateWorker(workerFile);
+ // workerFile && this.instantiateWorker(workerFile);
const _config = await this._client?.getConfigData();
- if (!(this._storage === Storage.WebWorker)) {
+ if (!(this._storage === BrowserStorage.WebWorker)) {
const mainThreadClientConfig = config as AuthClientConfig;
const defaultConfig = {...DefaultConfig} as Partial>;
const mergedConfig: AuthClientConfig = {
@@ -327,11 +326,11 @@ export class AsgardeoSPAClient {
/**
* This method returns a Promise that resolves with the basic user information obtained from the ID token.
*
- * @return {Promise} - A promise that resolves with the user information.
+ * @return {Promise} - A promise that resolves with the user information.
*
* @example
* ```
- * auth.getBasicUserInfo().then((response) => {
+ * auth.getUser().then((response) => {
* // console.log(response);
* }).catch((error) => {
* // console.error(error);
@@ -344,10 +343,10 @@ export class AsgardeoSPAClient {
*
* @preserve
*/
- public async getBasicUserInfo(): Promise {
+ public async getUser(): Promise {
await this._validateMethod();
- return this._client?.getBasicUserInfo();
+ return this._client?.getUser();
}
/**
@@ -373,7 +372,7 @@ export class AsgardeoSPAClient {
* @param {string} sessionState - The session state. (Optional)
* @param {string} state - The state. (Optional)
*
- * @return {Promise} - A promise that resolves with the user information.
+ * @return {Promise} - A promise that resolves with the user information.
*
* @example
* ```
@@ -394,8 +393,8 @@ export class AsgardeoSPAClient {
tokenRequestConfig?: {
params: Record;
},
- ): Promise {
- await this._isInitialized();
+ ): Promise {
+ await this.isInitialized();
// Discontinues the execution of this method if `config.callOnlyOnRedirect` is true and the `signIn` method
// is not being called on redirect.
@@ -407,11 +406,9 @@ export class AsgardeoSPAClient {
return this._client
?.signIn(config, authorizationCode, sessionState, state, tokenRequestConfig)
- .then((response: BasicUserInfo) => {
+ .then((response: User) => {
if (this._onSignInCallback) {
- if (response.allowedScopes || response.displayName || response.email || response.username) {
- this._onSignInCallback(response);
- }
+ this._onSignInCallback(response);
}
return response;
@@ -426,7 +423,7 @@ export class AsgardeoSPAClient {
* If this method is to be called on page load and the `signIn` method is also to be called on page load,
* then it is advisable to call this method after the `signIn` call.
*
- * @return {Promise} - A Promise that resolves with the user information after signing in
+ * @return {Promise} - A Promise that resolves with the user information after signing in
* or with `false` if the user is not signed in.
*
* @example
@@ -437,31 +434,21 @@ export class AsgardeoSPAClient {
public async trySignInSilently(
additionalParams?: Record,
tokenRequestConfig?: {params: Record},
- ): Promise {
- await this._isInitialized();
+ ): Promise {
+ await this.isInitialized();
// checks if the `signIn` method has been called.
if (SPAUtils.wasSignInCalled()) {
return undefined;
}
- return this._client
- ?.trySignInSilently(additionalParams, tokenRequestConfig)
- .then((response: BasicUserInfo | boolean) => {
- if (this._onSignInCallback && response) {
- const basicUserInfo = response as BasicUserInfo;
- if (
- basicUserInfo.allowedScopes ||
- basicUserInfo.displayName ||
- basicUserInfo.email ||
- basicUserInfo.username
- ) {
- this._onSignInCallback(basicUserInfo);
- }
- }
+ return this._client?.trySignInSilently(additionalParams, tokenRequestConfig).then((response: User | boolean) => {
+ if (this._onSignInCallback && response) {
+ this._onSignInCallback(response as User);
+ }
- return response;
- });
+ return response;
+ });
}
/**
@@ -619,7 +606,7 @@ export class AsgardeoSPAClient {
*
* @preserve
*/
- public async requestCustomGrant(config: CustomGrantConfig): Promise | BasicUserInfo | undefined> {
+ public async exchangeToken(config: TokenExchangeRequestConfig): Promise {
if (config.signInRequired) {
await this._validateMethod();
} else {
@@ -636,7 +623,7 @@ export class AsgardeoSPAClient {
);
}
- const customGrantResponse = await this._client?.requestCustomGrant(config);
+ const customGrantResponse = await this._client?.exchangeToken(config);
const customGrantCallback = this._onCustomGrant.get(config.id);
customGrantCallback && customGrantCallback(this._onCustomGrant?.get(config.id));
@@ -693,10 +680,10 @@ export class AsgardeoSPAClient {
*
* @preserve
*/
- public async getOIDCServiceEndpoints(): Promise {
- await this._isInitialized();
+ public async getOpenIDProviderEndpoints(): Promise {
+ await this.isInitialized();
- return this._client?.getOIDCServiceEndpoints();
+ return this._client?.getOpenIDProviderEndpoints();
}
/**
@@ -710,7 +697,7 @@ export class AsgardeoSPAClient {
*/
public getHttpClient(): HttpClientInstance {
if (this._client) {
- if (this._storage !== Storage.WebWorker) {
+ if (this._storage !== BrowserStorage.WebWorker) {
const mainThreadClient = this._client as MainThreadClientInterface;
return mainThreadClient.getHttpClient();
}
@@ -738,7 +725,7 @@ export class AsgardeoSPAClient {
*
* @example
* ```
- * auth.getDecodedIDToken().then((response)=>{
+ * auth.getDecodedIdToken().then((response)=>{
* // console.log(response);
* }).catch((error)=>{
* // console.error(error);
@@ -750,10 +737,10 @@ export class AsgardeoSPAClient {
*
* @preserve
*/
- public async getDecodedIDToken(): Promise {
+ public async getDecodedIdToken(): Promise {
await this._validateMethod();
- return this._client?.getDecodedIDToken();
+ return this._client?.getDecodedIdToken();
}
/**
@@ -764,22 +751,22 @@ export class AsgardeoSPAClient {
*
* @example
* ```
- * auth.getCryptoHelper().then((response)=>{
+ * auth.getCrypto().then((response)=>{
* // console.log(response);
* }).catch((error)=>{
* // console.error(error);
* });
* ```
- * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getCryptoHelper
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getCrypto
*
* @memberof AsgardeoSPAClient
*
* @preserve
*/
- public async getCryptoHelper(): Promise {
+ public async getCrypto(): Promise {
await this._validateMethod();
- return this._client?.getCryptoHelper();
+ return this._client?.getCrypto();
}
/**
@@ -789,19 +776,19 @@ export class AsgardeoSPAClient {
*
* @example
* ```
- * const idToken = await auth.getIDToken();
+ * const idToken = await auth.getIdToken();
* ```
*
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIDToken
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIdToken
*
* @memberof AsgardeoAuthClient
*
* @preserve
*/
- public async getIDToken(): Promise {
+ public async getIdToken(): Promise {
await this._validateMethod();
- return this._client?.getIDToken();
+ return this._client?.getIdToken();
}
/**
@@ -829,7 +816,7 @@ export class AsgardeoSPAClient {
public async getAccessToken(): Promise {
await this._validateMethod();
- if (this._storage && [(Storage.WebWorker, Storage.BrowserMemory)].includes(this._storage)) {
+ if (this._storage && [(BrowserStorage.WebWorker, BrowserStorage.BrowserMemory)].includes(this._storage)) {
return Promise.reject(
new AsgardeoAuthException(
'SPA-AUTH_CLIENT-GAT-IV01',
@@ -868,7 +855,7 @@ export class AsgardeoSPAClient {
public async getIDPAccessToken(): Promise {
await this._validateMethod();
- if (this._storage && [(Storage.WebWorker, Storage.BrowserMemory)].includes(this._storage)) {
+ if (this._storage && [(BrowserStorage.WebWorker, BrowserStorage.BrowserMemory)].includes(this._storage)) {
return Promise.reject(
new AsgardeoAuthException(
'SPA-AUTH_CLIENT-GIAT-IV01',
@@ -891,7 +878,7 @@ export class AsgardeoSPAClient {
*
* @example
* ```
- * auth.getDataLayer().then((dataLayer) => {
+ * auth.getStorageManager().then((dataLayer) => {
* // console.log(dataLayer);
* }).catch((error) => {
* // console.error(error);
@@ -904,10 +891,10 @@ export class AsgardeoSPAClient {
*
* @preserve
*/
- public async getDataLayer(): Promise> {
+ public async getStorageManager(): Promise> {
await this._validateMethod();
- if (this._storage && [(Storage.WebWorker, Storage.BrowserMemory)].includes(this._storage)) {
+ if (this._storage && [(BrowserStorage.WebWorker, BrowserStorage.BrowserMemory)].includes(this._storage)) {
return Promise.reject(
new AsgardeoAuthException(
'SPA-AUTH_CLIENT-GDL-IV01',
@@ -918,7 +905,7 @@ export class AsgardeoSPAClient {
}
const mainThreadClient = this._client as MainThreadClientInterface;
- return mainThreadClient.getDataLayer();
+ return mainThreadClient.getStorageManager();
}
/**
@@ -968,7 +955,7 @@ export class AsgardeoSPAClient {
*
* @preserve
*/
- public async refreshAccessToken(): Promise {
+ public async refreshAccessToken(): Promise {
await this._validateMethod(false);
return this._client?.refreshAccessToken();
@@ -983,10 +970,10 @@ export class AsgardeoSPAClient {
*
* @preserve
*/
- public async isAuthenticated(): Promise {
- await this._isInitialized();
+ public async isSignedIn(): Promise {
+ await this.isInitialized();
- return this._client?.isAuthenticated();
+ return this._client?.isSignedIn();
}
/**
@@ -999,9 +986,9 @@ export class AsgardeoSPAClient {
* @preserve
*/
public async isSessionActive(): Promise {
- await this._isInitialized();
+ await this.isInitialized();
- if (this._storage && [(Storage.WebWorker, Storage.BrowserMemory)].includes(this._storage)) {
+ if (this._storage && [(BrowserStorage.WebWorker, BrowserStorage.BrowserMemory)].includes(this._storage)) {
return Promise.reject(
new AsgardeoAuthException(
'SPA-AUTH_CLIENT-ISA-IV01',
@@ -1038,7 +1025,7 @@ export class AsgardeoSPAClient {
public async on(hook: Hooks.CustomGrant, callback: (response?: any) => void, id: string): Promise;
public async on(hook: Exclude, callback: (response?: any) => void): Promise;
public async on(hook: Hooks, callback: (response?: any) => void | Promise, id?: string): Promise {
- await this._isInitialized();
+ await this.isInitialized();
if (callback && typeof callback === 'function') {
switch (hook) {
case Hooks.SignIn:
@@ -1109,7 +1096,7 @@ export class AsgardeoSPAClient {
* @preserve
*/
public async enableHttpHandler(): Promise {
- await this._isInitialized();
+ await this.isInitialized();
return this._client?.enableHttpHandler();
}
@@ -1131,7 +1118,7 @@ export class AsgardeoSPAClient {
* @preserve
*/
public async disableHttpHandler(): Promise {
- await this._isInitialized();
+ await this.isInitialized();
return this._client?.disableHttpHandler();
}
@@ -1144,26 +1131,26 @@ export class AsgardeoSPAClient {
* @example
* ```
* const config = {
- * signInRedirectURL: "http://localhost:3000/sign-in",
- * clientID: "client ID",
+ * afterSignInUrl: "http://localhost:3000/sign-in",
+ * clientId: "client ID",
* baseUrl: "https://api.asgardeo.io"
* }
- * const auth.updateConfig(config);
+ * const auth.reInitialize(config);
* ```
- * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master/lib#updateConfig
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master/lib#reInitialize
*
* @memberof AsgardeoAuthClient
*
* @preserve
*/
- public async updateConfig(config: Partial>): Promise {
- await this._isInitialized();
- if (this._storage === Storage.WebWorker) {
+ public async reInitialize(config: Partial>): Promise {
+ await this.isInitialized();
+ if (this._storage === BrowserStorage.WebWorker) {
const client = this._client as WebWorkerClientInterface;
- await client.updateConfig(config as Partial>);
+ await client.reInitialize(config as Partial>);
} else {
const client = this._client as WebWorkerClientInterface;
- await client.updateConfig(config as Partial>);
+ await client.reInitialize(config as Partial>);
}
return;
diff --git a/packages/browser/src/__legacy__/clients/main-thread-client.ts b/packages/browser/src/__legacy__/clients/main-thread-client.ts
index 639ac72a..0abfa445 100755
--- a/packages/browser/src/__legacy__/clients/main-thread-client.ts
+++ b/packages/browser/src/__legacy__/clients/main-thread-client.ts
@@ -19,36 +19,37 @@
import {
AsgardeoAuthClient,
AuthClientConfig,
- BasicUserInfo,
+ User,
IsomorphicCrypto,
- DataLayer,
+ StorageManager,
IdTokenPayload,
- FetchResponse,
- GetAuthURLConfig,
+ ExtendedAuthorizeRequestUrlParams,
OIDCEndpoints,
- ResponseMode,
OIDCRequestConstants,
SessionData,
- Store,
+ Storage,
extractPkceStorageKeyFromState,
+ initializeApplicationNativeAuthentication,
+ handleApplicationNativeAuthentication,
+ TemporaryStore,
} from '@asgardeo/javascript';
import {SILENT_SIGN_IN_STATE, TOKEN_REQUEST_CONFIG_KEY} from '../constants';
import {AuthenticationHelper, SPAHelper, SessionManagementHelper} from '../helpers';
import {HttpClient, HttpClientInstance} from '../http-client';
import {HttpError, HttpRequestConfig, HttpResponse, MainThreadClientConfig, MainThreadClientInterface} from '../models';
import {SPACustomGrantConfig} from '../models/request-custom-grant';
-import {Storage} from '../models/storage';
+import {BrowserStorage} from '../models/storage';
import {LocalStore, MemoryStore, SessionStore} from '../stores';
import {SPAUtils} from '../utils';
import {SPACryptoUtils} from '../utils/crypto-utils';
-const initiateStore = (store: Storage | undefined): Store => {
+const initiateStore = (store: BrowserStorage | undefined): Storage => {
switch (store) {
- case Storage.LocalStorage:
+ case BrowserStorage.LocalStorage:
return new LocalStore();
- case Storage.SessionStorage:
+ case BrowserStorage.SessionStorage:
return new SessionStore();
- case Storage.BrowserMemory:
+ case BrowserStorage.BrowserMemory:
return new MemoryStore();
default:
return new SessionStore();
@@ -63,18 +64,18 @@ export const MainThreadClient = async (
spaHelper: SPAHelper,
) => AuthenticationHelper,
): Promise => {
- const _store: Store = initiateStore(config.storage as Storage);
+ const _store: Storage = initiateStore(config.storage as BrowserStorage);
const _cryptoUtils: SPACryptoUtils = new SPACryptoUtils();
const _authenticationClient = new AsgardeoAuthClient();
await _authenticationClient.initialize(config, _store, _cryptoUtils, instanceID);
const _spaHelper = new SPAHelper(_authenticationClient);
- const _dataLayer = _authenticationClient.getDataLayer();
+ const _dataLayer = _authenticationClient.getStorageManager();
const _sessionManagementHelper = await SessionManagementHelper(
async () => {
- return _authenticationClient.getSignOutURL();
+ return _authenticationClient.getSignOutUrl();
},
- (config.storage as Storage) ?? Storage.SessionStorage,
+ (config.storage as BrowserStorage) ?? BrowserStorage.SessionStorage,
(sessionState: string) =>
_dataLayer.setSessionDataParameter(
OIDCRequestConstants.Params.SESSION_STATE as keyof SessionData,
@@ -152,14 +153,14 @@ export const MainThreadClient = async (
};
const checkSession = async (): Promise => {
- const oidcEndpoints: OIDCEndpoints = await _authenticationClient.getOIDCServiceEndpoints() as OIDCEndpoints;
+ const oidcEndpoints: OIDCEndpoints = (await _authenticationClient.getOpenIDProviderEndpoints()) as OIDCEndpoints;
const config = await _dataLayer.getConfigData();
_authenticationHelper.initializeSessionManger(
config,
oidcEndpoints,
- async () => (await _authenticationClient.getBasicUserInfo()).sessionState,
- async (params?: GetAuthURLConfig): Promise => _authenticationClient.getAuthorizationURL(params),
+ async () => (await _authenticationClient.getUserSession()).sessionState,
+ async (params?: ExtendedAuthorizeRequestUrlParams): Promise => _authenticationClient.getSignInUrl(params),
_sessionManagementHelper,
);
};
@@ -179,14 +180,21 @@ export const MainThreadClient = async (
};
const signIn = async (
- signInConfig?: GetAuthURLConfig,
+ signInConfig?: ExtendedAuthorizeRequestUrlParams,
authorizationCode?: string,
sessionState?: string,
state?: string,
tokenRequestConfig?: {
params: Record;
},
- ): Promise => {
+ ): Promise => {
+ if (signInConfig['flow']) {
+ return handleApplicationNativeAuthentication({
+ url: signInConfig['flow']['requestConfig']['url'],
+ payload: signInConfig['flow']['payload'],
+ });
+ }
+
const basicUserInfo = await _authenticationHelper.handleSignIn(shouldStopAuthn, checkSession, undefined);
if (basicUserInfo) {
@@ -199,7 +207,7 @@ export const MainThreadClient = async (
params: Record;
} = {params: {}};
- if (config?.responseMode === ResponseMode.FormPost && authorizationCode) {
+ if (config?.responseMode === 'form_post' && authorizationCode) {
resolvedAuthorizationCode = authorizationCode;
resolvedSessionState = sessionState ?? '';
resolvedState = state ?? '';
@@ -227,8 +235,8 @@ export const MainThreadClient = async (
);
}
- return _authenticationClient.getAuthorizationURL(signInConfig).then(async (url: string) => {
- if (config.storage === Storage.BrowserMemory && config.enablePKCE) {
+ return _authenticationClient.getSignInUrl(signInConfig).then(async (url: string) => {
+ if (config.storage === BrowserStorage.BrowserMemory && config.enablePKCE) {
const pkceKey: string = extractPkceStorageKeyFromState(resolvedState);
SPAUtils.setPKCE(pkceKey, (await _authenticationClient.getPKCECode(resolvedState)) as string);
@@ -238,7 +246,16 @@ export const MainThreadClient = async (
_dataLayer.setTemporaryDataParameter(TOKEN_REQUEST_CONFIG_KEY, JSON.stringify(tokenRequestConfig));
}
- location.href = url;
+ if (signInConfig['response_mode'] === 'direct') {
+ const authorizeUrl: URL = new URL(url);
+
+ return initializeApplicationNativeAuthentication({
+ url: `${authorizeUrl.origin}${authorizeUrl.pathname}`,
+ payload: Object.fromEntries(authorizeUrl.searchParams.entries()),
+ });
+ } else {
+ location.href = url;
+ }
await SPAUtils.waitTillPageRedirect();
@@ -256,10 +273,10 @@ export const MainThreadClient = async (
};
const signOut = async (): Promise => {
- if ((await _authenticationClient.isAuthenticated()) && !_getSignOutURLFromSessionStorage) {
- location.href = await _authenticationClient.getSignOutURL();
+ if ((await _authenticationClient.isSignedIn()) && !_getSignOutURLFromSessionStorage) {
+ location.href = await _authenticationClient.getSignOutUrl();
} else {
- location.href = SPAUtils.getSignOutURL(config.clientID, instanceID);
+ location.href = SPAUtils.getSignOutUrl(config.clientId, instanceID);
}
_spaHelper.clearRefreshTokenTimeout();
@@ -280,11 +297,11 @@ export const MainThreadClient = async (
}
};
- const requestCustomGrant = async (config: SPACustomGrantConfig): Promise => {
- return await _authenticationHelper.requestCustomGrant(config, enableRetrievingSignOutURLFromSession);
+ const exchangeToken = async (config: SPACustomGrantConfig): Promise => {
+ return await _authenticationHelper.exchangeToken(config, enableRetrievingSignOutURLFromSession);
};
- const refreshAccessToken = async (): Promise => {
+ const refreshAccessToken = async (): Promise => {
try {
return await _authenticationHelper.refreshAccessToken(enableRetrievingSignOutURLFromSession);
} catch (error) {
@@ -313,7 +330,7 @@ export const MainThreadClient = async (
tokenRequestConfig?: {
params: Record;
},
- ): Promise => {
+ ): Promise => {
return await _authenticationHelper.requestAccessToken(
resolvedAuthorizationCode,
resolvedSessionState,
@@ -326,7 +343,7 @@ export const MainThreadClient = async (
const constructSilentSignInUrl = async (additionalParams: Record = {}): Promise => {
const config = await _dataLayer.getConfigData();
- const urlString: string = await _authenticationClient.getAuthorizationURL({
+ const urlString: string = await _authenticationClient.getSignInUrl({
prompt: 'none',
state: SILENT_SIGN_IN_STATE,
...additionalParams,
@@ -337,7 +354,7 @@ export const MainThreadClient = async (
urlObject.searchParams.set('response_mode', 'query');
const url: string = urlObject.toString();
- if (config.storage === Storage.BrowserMemory && config.enablePKCE) {
+ if (config.storage === BrowserStorage.BrowserMemory && config.enablePKCE) {
const state = urlObject.searchParams.get(OIDCRequestConstants.Params.STATE);
SPAUtils.setPKCE(
@@ -353,13 +370,13 @@ export const MainThreadClient = async (
* This method checks if there is an active user session in the server by sending a prompt none request.
* If the user is signed in, this method sends a token request. Returns false otherwise.
*
- * @return {Promise,
tokenRequestConfig?: {params: Record},
- ): Promise => {
+ ): Promise => {
return await _authenticationHelper.trySignInSilently(
constructSilentSignInUrl,
requestAccessToken,
@@ -369,47 +386,47 @@ export const MainThreadClient = async (
);
};
- const getBasicUserInfo = async (): Promise => {
- return _authenticationHelper.getBasicUserInfo();
+ const getUser = async (): Promise => {
+ return _authenticationHelper.getUser();
};
- const getDecodedIDToken = async (): Promise => {
- return _authenticationHelper.getDecodedIDToken();
+ const getDecodedIdToken = async (): Promise => {
+ return _authenticationHelper.getDecodedIdToken();
};
- const getCryptoHelper = async (): Promise => {
- return _authenticationHelper.getCryptoHelper();
+ const getCrypto = async (): Promise => {
+ return _authenticationHelper.getCrypto();
};
- const getIDToken = async (): Promise => {
- return _authenticationHelper.getIDToken();
+ const getIdToken = async (): Promise => {
+ return _authenticationHelper.getIdToken();
};
- const getOIDCServiceEndpoints = async (): Promise => {
- return _authenticationHelper.getOIDCServiceEndpoints();
+ const getOpenIDProviderEndpoints = async (): Promise => {
+ return _authenticationHelper.getOpenIDProviderEndpoints();
};
const getAccessToken = async (): Promise => {
return _authenticationHelper.getAccessToken();
};
- const getDataLayer = async (): Promise> => {
- return _authenticationHelper.getDataLayer();
+ const getStorageManager = async (): Promise> => {
+ return _authenticationHelper.getStorageManager();
};
const getConfigData = async (): Promise> => {
return await _dataLayer.getConfigData();
};
- const isAuthenticated = async (): Promise => {
- return _authenticationHelper.isAuthenticated();
+ const isSignedIn = async (): Promise => {
+ return _authenticationHelper.isSignedIn();
};
const isSessionActive = async (): Promise => {
return (await _dataLayer.getSessionStatus()) === 'true';
};
- const updateConfig = async (newConfig: Partial>): Promise => {
+ const reInitialize = async (newConfig: Partial>): Promise => {
const existingConfig = await _dataLayer.getConfigData();
const isCheckSessionIframeDifferent: boolean = !(
existingConfig &&
@@ -421,7 +438,7 @@ export const MainThreadClient = async (
existingConfig.endpoints.checkSessionIframe === newConfig.endpoints.checkSessionIframe
);
const config = {...existingConfig, ...newConfig};
- await _authenticationClient.updateConfig(config);
+ await _authenticationClient.reInitialize(config);
// Re-initiates check session if the check session endpoint is updated.
if (config.enableOIDCSessionManagement && isCheckSessionIframeDifferent) {
@@ -435,20 +452,20 @@ export const MainThreadClient = async (
disableHttpHandler,
enableHttpHandler,
getAccessToken,
- getBasicUserInfo,
+ getUser,
getConfigData,
- getCryptoHelper,
- getDataLayer,
- getDecodedIDToken,
+ getCrypto,
+ getStorageManager,
+ getDecodedIdToken,
getHttpClient,
- getIDToken,
- getOIDCServiceEndpoints,
+ getIdToken,
+ getOpenIDProviderEndpoints,
httpRequest,
httpRequestAll,
- isAuthenticated,
+ isSignedIn,
isSessionActive,
refreshAccessToken,
- requestCustomGrant,
+ exchangeToken,
revokeAccessToken,
setHttpRequestErrorCallback,
setHttpRequestFinishCallback,
@@ -457,6 +474,6 @@ export const MainThreadClient = async (
signIn,
signOut,
trySignInSilently,
- updateConfig,
+ reInitialize,
};
};
diff --git a/packages/browser/src/__legacy__/clients/web-worker-client.ts b/packages/browser/src/__legacy__/clients/web-worker-client.ts
index 9a4ab493..84444cbd 100755
--- a/packages/browser/src/__legacy__/clients/web-worker-client.ts
+++ b/packages/browser/src/__legacy__/clients/web-worker-client.ts
@@ -20,16 +20,14 @@ import {
AsgardeoAuthClient,
AsgardeoAuthException,
AuthClientConfig,
- BasicUserInfo,
+ User,
IsomorphicCrypto,
- CustomGrantConfig,
+ TokenExchangeRequestConfig,
IdTokenPayload,
- FetchResponse,
- GetAuthURLConfig,
+ ExtendedAuthorizeRequestUrlParams,
OIDCEndpoints,
- ResponseMode,
OIDCRequestConstants,
- Store,
+ Storage,
extractPkceStorageKeyFromState,
} from '@asgardeo/javascript';
import {
@@ -75,18 +73,18 @@ import {
WebWorkerClientInterface,
} from '../models';
import {SPACustomGrantConfig} from '../models/request-custom-grant';
-import {Storage} from '../models/storage';
+import {BrowserStorage} from '../models/storage';
import {LocalStore, MemoryStore, SessionStore} from '../stores';
import {SPAUtils} from '../utils';
import {SPACryptoUtils} from '../utils/crypto-utils';
-const initiateStore = (store: Storage | undefined): Store => {
+const initiateStore = (store: BrowserStorage | undefined): Storage => {
switch (store) {
- case Storage.LocalStorage:
+ case BrowserStorage.LocalStorage:
return new LocalStore();
- case Storage.SessionStorage:
+ case BrowserStorage.SessionStorage:
return new SessionStore();
- case Storage.BrowserMemory:
+ case BrowserStorage.BrowserMemory:
return new MemoryStore();
default:
return new SessionStore();
@@ -113,7 +111,7 @@ export const WebWorkerClient = async (
let _isHttpHandlerEnabled: boolean = true;
let _getSignOutURLFromSessionStorage: boolean = false;
- const _store: Store = initiateStore(config.storage as Storage);
+ const _store: Storage = initiateStore(config.storage as BrowserStorage);
const _cryptoUtils: SPACryptoUtils = new SPACryptoUtils();
const _authenticationClient = new AsgardeoAuthClient();
await _authenticationClient.initialize(config, _store, _cryptoUtils, instanceID);
@@ -130,10 +128,10 @@ export const WebWorkerClient = async (
return signOutURL;
} catch {
- return SPAUtils.getSignOutURL(config.clientID, instanceID);
+ return SPAUtils.getSignOutUrl(config.clientId, instanceID);
}
},
- config.storage as Storage,
+ config.storage as BrowserStorage,
(sessionState: string) => setSessionState(sessionState),
);
@@ -189,13 +187,13 @@ export const WebWorkerClient = async (
* @returns {Promise} A promise that resolves with a boolean value or the request
* response if the the `returnResponse` attribute in the `requestParams` object is set to `true`.
*/
- const requestCustomGrant = (requestParams: SPACustomGrantConfig): Promise => {
- const message: Message = {
+ const exchangeToken = (requestParams: SPACustomGrantConfig): Promise => {
+ const message: Message = {
data: requestParams,
type: REQUEST_CUSTOM_GRANT,
};
- return communicate(message)
+ return communicate(message)
.then(response => {
if (requestParams.preventSignOutURLUpdate) {
_getSignOutURLFromSessionStorage = true;
@@ -380,21 +378,22 @@ export const WebWorkerClient = async (
};
const checkSession = async (): Promise => {
- const oidcEndpoints: OIDCEndpoints = await getOIDCServiceEndpoints();
+ const oidcEndpoints: OIDCEndpoints = await getOpenIDProviderEndpoints();
const config: AuthClientConfig = await getConfigData();
_authenticationHelper.initializeSessionManger(
config,
oidcEndpoints,
- async () => (await getBasicUserInfo()).sessionState,
- async (params?: GetAuthURLConfig): Promise => (await getAuthorizationURL(params)).authorizationURL,
+ async () => (await _authenticationClient.getUserSession()).sessionState,
+ async (params?: ExtendedAuthorizeRequestUrlParams): Promise =>
+ (await getSignInUrl(params)).authorizationURL,
_sessionManagementHelper,
);
};
const constructSilentSignInUrl = async (additionalParams: Record = {}): Promise => {
const config: AuthClientConfig = await getConfigData();
- const message: Message = {
+ const message: Message = {
data: {
prompt: 'none',
state: SILENT_SIGN_IN_STATE,
@@ -403,7 +402,9 @@ export const WebWorkerClient = async (
type: GET_AUTH_URL,
};
- const response: AuthorizationResponse = await communicate(message);
+ const response: AuthorizationResponse = await communicate(
+ message,
+ );
const pkceKey: string = extractPkceStorageKeyFromState(
new URL(response.authorizationURL).searchParams.get(OIDCRequestConstants.Params.STATE) ?? '',
@@ -425,13 +426,13 @@ export const WebWorkerClient = async (
* This method checks if there is an active user session in the server by sending a prompt none request.
* If the user is signed in, this method sends a token request. Returns false otherwise.
*
- * @return {Promise,
tokenRequestConfig?: {params: Record},
- ): Promise => {
+ ): Promise => {
return await _authenticationHelper.trySignInSilently(
constructSilentSignInUrl,
requestAccessToken,
@@ -444,18 +445,18 @@ export const WebWorkerClient = async (
/**
* Generates an authorization URL.
*
- * @param {GetAuthURLConfig} params Authorization URL params.
+ * @param {ExtendedAuthorizeRequestUrlParams} params Authorization URL params.
* @returns {Promise} Authorization URL.
*/
- const getAuthorizationURL = async (params?: GetAuthURLConfig): Promise => {
+ const getSignInUrl = async (params?: ExtendedAuthorizeRequestUrlParams): Promise => {
const config: AuthClientConfig = await getConfigData();
- const message: Message = {
+ const message: Message = {
data: params,
type: GET_AUTH_URL,
};
- return communicate(message).then(
+ return communicate(message).then(
async (response: AuthorizationResponse) => {
if (response.pkce && config.enablePKCE) {
const pkceKey: string = extractPkceStorageKeyFromState(
@@ -477,7 +478,7 @@ export const WebWorkerClient = async (
tokenRequestConfig?: {
params: Record;
},
- ): Promise => {
+ ): Promise => {
const config: AuthClientConfig = await getConfigData();
const pkceKey: string = extractPkceStorageKeyFromState(resolvedState);
@@ -494,7 +495,7 @@ export const WebWorkerClient = async (
config.enablePKCE && SPAUtils.removePKCE(pkceKey);
- return communicate(message)
+ return communicate(message)
.then(response => {
const message: Message = {
type: GET_SIGN_OUT_URL,
@@ -502,7 +503,7 @@ export const WebWorkerClient = async (
return communicate(message)
.then((url: string) => {
- SPAUtils.setSignOutURL(url, config.clientID, instanceID);
+ SPAUtils.setSignOutURL(url, config.clientId, instanceID);
// Enable OIDC Sessions Management only if it is set to true in the config.
if (config.enableOIDCSessionManagement) {
@@ -528,8 +529,8 @@ export const WebWorkerClient = async (
});
};
- const tryRetrievingUserInfo = async (): Promise => {
- if (await isAuthenticated()) {
+ const tryRetrievingUserInfo = async (): Promise => {
+ if (await isSignedIn()) {
await startAutoRefreshToken();
// Enable OIDC Sessions Management only if it is set to true in the config.
@@ -537,9 +538,9 @@ export const WebWorkerClient = async (
checkSession();
}
- return getBasicUserInfo();
+ return getUser();
}
-
+
return Promise.resolve(undefined);
};
@@ -549,14 +550,14 @@ export const WebWorkerClient = async (
* @returns {Promise} A promise that resolves when authentication is successful.
*/
const signIn = async (
- params?: GetAuthURLConfig,
+ params?: ExtendedAuthorizeRequestUrlParams,
authorizationCode?: string,
sessionState?: string,
state?: string,
tokenRequestConfig?: {
params: Record;
},
- ): Promise => {
+ ): Promise => {
const basicUserInfo = await _authenticationHelper.handleSignIn(
shouldStopAuthn,
checkSession,
@@ -570,7 +571,7 @@ export const WebWorkerClient = async (
let resolvedSessionState: string;
let resolvedState: string;
- if (config?.responseMode === ResponseMode.FormPost && authorizationCode) {
+ if (config?.responseMode === 'form_post' && authorizationCode) {
resolvedAuthorizationCode = authorizationCode;
resolvedSessionState = sessionState ?? '';
resolvedState = state ?? '';
@@ -588,7 +589,7 @@ export const WebWorkerClient = async (
return requestAccessToken(resolvedAuthorizationCode, resolvedSessionState, resolvedState, tokenRequestConfig);
}
- return getAuthorizationURL(params)
+ return getSignInUrl(params)
.then(async (response: AuthorizationResponse) => {
location.href = response.authorizationURL;
@@ -634,7 +635,7 @@ export const WebWorkerClient = async (
return reject(error);
});
} else {
- window.location.href = SPAUtils.getSignOutURL(config.clientID, instanceID);
+ window.location.href = SPAUtils.getSignOutUrl(config.clientId, instanceID);
return SPAUtils.waitTillPageRedirect().then(() => {
return Promise.resolve(true);
@@ -663,7 +664,7 @@ export const WebWorkerClient = async (
});
};
- const getOIDCServiceEndpoints = (): Promise => {
+ const getOpenIDProviderEndpoints = (): Promise => {
const message: Message = {
type: GET_OIDC_SERVICE_ENDPOINTS,
};
@@ -691,12 +692,12 @@ export const WebWorkerClient = async (
});
};
- const getBasicUserInfo = (): Promise => {
+ const getUser = (): Promise => {
const message: Message = {
type: GET_BASIC_USER_INFO,
};
- return communicate(message)
+ return communicate(message)
.then(response => {
return Promise.resolve(response);
})
@@ -705,7 +706,7 @@ export const WebWorkerClient = async (
});
};
- const getDecodedIDToken = (): Promise => {
+ const getDecodedIdToken = (): Promise => {
const message: Message = {
type: GET_DECODED_ID_TOKEN,
};
@@ -733,7 +734,7 @@ export const WebWorkerClient = async (
});
};
- const getCryptoHelper = (): Promise => {
+ const getCrypto = (): Promise => {
const message: Message = {
type: GET_CRYPTO_HELPER,
};
@@ -747,7 +748,7 @@ export const WebWorkerClient = async (
});
};
- const getIDToken = (): Promise => {
+ const getIdToken = (): Promise => {
const message: Message = {
type: GET_ID_TOKEN,
};
@@ -761,7 +762,7 @@ export const WebWorkerClient = async (
});
};
- const isAuthenticated = (): Promise => {
+ const isSignedIn = (): Promise => {
const message: Message = {
type: IS_AUTHENTICATED,
};
@@ -775,12 +776,12 @@ export const WebWorkerClient = async (
});
};
- const refreshAccessToken = (): Promise => {
+ const refreshAccessToken = (): Promise => {
const message: Message = {
type: REFRESH_ACCESS_TOKEN,
};
- return communicate(message);
+ return communicate(message);
};
const setHttpRequestSuccessCallback = (callback: (response: HttpResponse) => void): void => {
@@ -807,7 +808,7 @@ export const WebWorkerClient = async (
}
};
- const updateConfig = async (newConfig: Partial>): Promise => {
+ const reInitialize = async (newConfig: Partial>): Promise => {
const existingConfig = await getConfigData();
const isCheckSessionIframeDifferent: boolean = !(
existingConfig &&
@@ -838,19 +839,19 @@ export const WebWorkerClient = async (
return {
disableHttpHandler,
enableHttpHandler,
- getBasicUserInfo,
+ getUser,
getConfigData,
- getCryptoHelper,
+ getCrypto,
getDecodedIDPIDToken,
- getDecodedIDToken,
- getIDToken,
- getOIDCServiceEndpoints,
+ getDecodedIdToken,
+ getIdToken,
+ getOpenIDProviderEndpoints,
httpRequest,
httpRequestAll,
initialize,
- isAuthenticated,
+ isSignedIn,
refreshAccessToken,
- requestCustomGrant,
+ exchangeToken,
revokeAccessToken,
setHttpRequestErrorCallback,
setHttpRequestFinishCallback,
@@ -859,6 +860,6 @@ export const WebWorkerClient = async (
signIn,
signOut,
trySignInSilently,
- updateConfig,
+ reInitialize,
};
};
diff --git a/packages/browser/src/__legacy__/helpers/authentication-helper.ts b/packages/browser/src/__legacy__/helpers/authentication-helper.ts
index cb9f83e0..0763ba27 100644
--- a/packages/browser/src/__legacy__/helpers/authentication-helper.ts
+++ b/packages/browser/src/__legacy__/helpers/authentication-helper.ts
@@ -20,13 +20,12 @@ import {
AsgardeoAuthClient,
AsgardeoAuthException,
AuthClientConfig,
- BasicUserInfo,
+ User,
IsomorphicCrypto,
- CustomGrantConfig,
- DataLayer,
+ TokenExchangeRequestConfig,
+ StorageManager,
IdTokenPayload,
- FetchResponse,
- GetAuthURLConfig,
+ ExtendedAuthorizeRequestUrlParams,
OIDCEndpoints,
TokenResponse,
extractPkceStorageKeyFromState,
@@ -56,21 +55,21 @@ import {
WebWorkerClientConfig,
} from '../models';
import {SPACustomGrantConfig} from '../models/request-custom-grant';
-import {Storage} from '../models/storage';
+import {BrowserStorage} from '../models/storage';
import {SPAUtils} from '../utils';
export class AuthenticationHelper {
protected _authenticationClient: AsgardeoAuthClient;
- protected _dataLayer: DataLayer;
+ protected _storageManager: StorageManager;
protected _spaHelper: SPAHelper;
protected _instanceID: number;
protected _isTokenRefreshing: boolean;
public constructor(authClient: AsgardeoAuthClient, spaHelper: SPAHelper) {
this._authenticationClient = authClient;
- this._dataLayer = this._authenticationClient.getDataLayer();
+ this._storageManager = this._authenticationClient.getStorageManager();
this._spaHelper = spaHelper;
- this._instanceID = this._authenticationClient.getInstanceID();
+ this._instanceID = this._authenticationClient.getInstanceId();
this._isTokenRefreshing = false;
}
@@ -86,24 +85,24 @@ export class AuthenticationHelper,
oidcEndpoints: OIDCEndpoints,
getSessionState: () => Promise,
- getAuthzURL: (params?: GetAuthURLConfig) => Promise,
+ getAuthzURL: (params?: ExtendedAuthorizeRequestUrlParams) => Promise,
sessionManagementHelper: SessionManagementHelperInterface,
): void {
sessionManagementHelper.initialize(
- config.clientID,
+ config.clientId,
oidcEndpoints.checkSessionIframe ?? '',
getSessionState,
config.checkSessionInterval ?? 3,
config.sessionRefreshInterval ?? 300,
- config.signInRedirectURL,
+ config.afterSignInUrl,
getAuthzURL,
);
}
- public async requestCustomGrant(
+ public async exchangeToken(
config: SPACustomGrantConfig,
enableRetrievingSignOutURLFromSession?: (config: SPACustomGrantConfig) => void,
- ): Promise {
+ ): Promise {
let useDefaultEndpoint = true;
let matches = false;
@@ -112,7 +111,7 @@ export class AuthenticationHelper {
+ .exchangeToken(config)
+ .then(async (response: Response | TokenResponse) => {
if (enableRetrievingSignOutURLFromSession && typeof enableRetrievingSignOutURLFromSession === 'function') {
enableRetrievingSignOutURLFromSession(config);
}
@@ -135,9 +134,9 @@ export class AuthenticationHelper {
@@ -156,8 +155,8 @@ export class AuthenticationHelper | null> {
- const configString = await this._dataLayer.getTemporaryDataParameter(CUSTOM_GRANT_CONFIG);
+ public async getCustomGrantConfigData(): Promise | null> {
+ const configString = await this._storageManager.getTemporaryDataParameter(CUSTOM_GRANT_CONFIG);
if (configString) {
return JSON.parse(configString as string);
@@ -168,16 +167,16 @@ export class AuthenticationHelper void,
- ): Promise {
+ ): Promise {
try {
await this._authenticationClient.refreshAccessToken();
const customGrantConfig = await this.getCustomGrantConfigData();
if (customGrantConfig) {
- await this.requestCustomGrant(customGrantConfig, enableRetrievingSignOutURLFromSession);
+ await this.exchangeToken(customGrantConfig, enableRetrievingSignOutURLFromSession);
}
this._spaHelper.refreshAccessTokenAutomatically(this);
- return this._authenticationClient.getBasicUserInfo();
+ return this._authenticationClient.getUser();
} catch (error) {
const refreshTokenError: Message = {
type: REFRESH_ACCESS_TOKEN_ERR0R,
@@ -225,7 +224,7 @@ export class AuthenticationHelper void,
): Promise {
let matches = false;
- const config = await this._dataLayer.getConfigData();
+ const config = await this._storageManager.getConfigData();
for (const baseUrl of [...((await config?.resourceServerURLs) ?? []), (config as any).baseUrl]) {
if (baseUrl && requestConfig?.url?.startsWith(baseUrl)) {
@@ -256,7 +255,7 @@ export class AuthenticationHelper void,
): Promise {
let matches = true;
- const config = await this._dataLayer.getConfigData();
+ const config = await this._storageManager.getConfigData();
for (const requestConfig of requestConfigs) {
let urlMatches = false;
@@ -372,7 +371,7 @@ export class AuthenticationHelper {
if (error?.response?.status === 401 || !error?.response) {
- let refreshTokenResponse: TokenResponse | BasicUserInfo;
+ let refreshTokenResponse: TokenResponse | User;
try {
refreshTokenResponse = await this._authenticationClient.refreshAccessToken();
} catch (refreshError: any) {
@@ -453,14 +452,14 @@ export class AuthenticationHelper;
},
- ): Promise