From 7036546fa87140b1ba336af35a8739914ddee44b Mon Sep 17 00:00:00 2001 From: Movin Silva Date: Thu, 18 Apr 2024 17:42:49 +0530 Subject: [PATCH 01/18] feat(core): :sparkles: add custom exception class - AsgardeoUIException --- packages/core/package.json | 3 +++ packages/core/src/api/authenticate.ts | 0 packages/core/src/api/authorize.ts | 0 packages/core/src/exception.ts | 32 +++++++++++++++++++++++++++ packages/core/src/index.ts | 0 pnpm-lock.yaml | 8 +++++++ 6 files changed, 43 insertions(+) create mode 100644 packages/core/src/api/authenticate.ts create mode 100644 packages/core/src/api/authorize.ts create mode 100644 packages/core/src/exception.ts create mode 100644 packages/core/src/index.ts diff --git a/packages/core/package.json b/packages/core/package.json index 698f6f5f..b43c220a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -40,5 +40,8 @@ }, "publishConfig": { "access": "public" + }, + "dependencies": { + "@asgardeo/auth-js": "^5.0.1" } } diff --git a/packages/core/src/api/authenticate.ts b/packages/core/src/api/authenticate.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/core/src/api/authorize.ts b/packages/core/src/api/authorize.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/core/src/exception.ts b/packages/core/src/exception.ts new file mode 100644 index 00000000..252c23f1 --- /dev/null +++ b/packages/core/src/exception.ts @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export default class AsgardeoUIException extends Error { + public override name: string; + + public override stack: string; + + public code: string; + + constructor(code: string, message: string, stack?: any) { + super(message); + this.code = `ASG-${code}`; + this.name = this.constructor.name; + this.stack = stack; + } +} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts new file mode 100644 index 00000000..e69de29b diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 575c3859..936e91ff 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13,6 +13,10 @@ importers: version: 18.2.4 packages/core: + dependencies: + '@asgardeo/auth-js': + specifier: ^5.0.1 + version: 5.0.1 devDependencies: '@types/node': specifier: ^20.12.7 @@ -48,6 +52,10 @@ packages: '@jridgewell/trace-mapping': 0.3.25 dev: true + /@asgardeo/auth-js@5.0.1: + resolution: {integrity: sha512-XTb/+jPPBAnNGlZYeHVz2Ut5hI8DeJiMmX5YcAijiAvtW4Ove82lT4aLXm+FL8XmCYc+61hFNG1QLf8q2nMfSQ==} + dev: false + /@babel/code-frame@7.24.2: resolution: {integrity: sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==} engines: {node: '>=6.9.0'} From 6816344574014eb276df84ebbcf2cdcc67e7e46e Mon Sep 17 00:00:00 2001 From: Movin Silva Date: Thu, 18 Apr 2024 22:17:56 +0530 Subject: [PATCH 02/18] feat(core): :sparkles: add auth client add auth client to initialize and access AsgardeoAuthClient from auth-js. --- packages/core/package.json | 1 + packages/core/src/auth-client.ts | 43 +++++++++++++++++++ packages/core/src/models/auth-api-response.ts | 0 packages/core/src/models/auth-config.ts | 34 +++++++++++++++ pnpm-lock.yaml | 3 ++ 5 files changed, 81 insertions(+) create mode 100644 packages/core/src/auth-client.ts create mode 100644 packages/core/src/models/auth-api-response.ts create mode 100644 packages/core/src/models/auth-config.ts diff --git a/packages/core/package.json b/packages/core/package.json index b43c220a..107b67f6 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -36,6 +36,7 @@ "@wso2/prettier-config": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?5bf60cabe9e9a2571e8b1dd16d0c3bdc76db2c4f", "eslint": "~8.57.0", "prettier": "^3.2.5", + "tslib": "^2.6.2", "typescript": "^5.4.5" }, "publishConfig": { diff --git a/packages/core/src/auth-client.ts b/packages/core/src/auth-client.ts new file mode 100644 index 00000000..a846bdbb --- /dev/null +++ b/packages/core/src/auth-client.ts @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import {AsgardeoAuthClient, Store, CryptoUtils} from '@asgardeo/auth-js'; +import {UIAuthClient, UIAuthConfig} from './models/auth-config'; + +export class AuthClient { + private static instance: UIAuthClient; + + /** + * Private constructor to prevent direct object creation. + * This is necessary because this is a singleton class. + * @private + */ + // eslint-disable-next-line @typescript-eslint/no-empty-function + private constructor() {} + + static getInstance(authClientConfig?: UIAuthConfig, store?: Store, cryptoUtils?: CryptoUtils): UIAuthClient { + if (!AuthClient.instance) { + AuthClient.instance = new AsgardeoAuthClient(); + AuthClient.instance.initialize(authClientConfig, store, cryptoUtils); + } + return AuthClient.instance; + } +} + +/* Interfaces, classes and enums required from the auth-js package */ +export {CryptoUtils, JWKInterface, Store, AsgardeoAuthClient, TokenResponse, ResponseMode} from '@asgardeo/auth-js'; diff --git a/packages/core/src/models/auth-api-response.ts b/packages/core/src/models/auth-api-response.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/core/src/models/auth-config.ts b/packages/core/src/models/auth-config.ts new file mode 100644 index 00000000..fde4dddc --- /dev/null +++ b/packages/core/src/models/auth-config.ts @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import {AsgardeoAuthClient, AuthClientConfig} from '@asgardeo/auth-js'; + +interface AuthClientConfigExtension { + /* If enabled, the branding from the console will be used. Default value is true */ + enableConsoleBranding?: boolean; + /* If enabled, the text branding from the console will be used for the text. Default value is true */ + enableConsoleTextBranding?: boolean; + /* Language code of the locale. */ + locale?: string; + name?: string; + type?: string; +} + +export type UIAuthConfig = AuthClientConfig; + +export type UIAuthClient = AsgardeoAuthClient; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 936e91ff..af919abb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -33,6 +33,9 @@ importers: prettier: specifier: ^3.2.5 version: 3.2.5 + tslib: + specifier: ^2.6.2 + version: 2.6.2 typescript: specifier: ^5.4.5 version: 5.4.5 From ef0bedc26b9228b0c47167880374a4b9b4c8d46f Mon Sep 17 00:00:00 2001 From: Movin Silva Date: Thu, 18 Apr 2024 22:59:28 +0530 Subject: [PATCH 03/18] feat(core): :sparkles: add authorize function --- packages/core/src/api/authorize.ts | 71 ++++++++++ packages/core/src/models/auth-api-response.ts | 129 ++++++++++++++++++ 2 files changed, 200 insertions(+) diff --git a/packages/core/src/api/authorize.ts b/packages/core/src/api/authorize.ts index e69de29b..1b656049 100644 --- a/packages/core/src/api/authorize.ts +++ b/packages/core/src/api/authorize.ts @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import {AsgardeoAuthClient} from '@asgardeo/auth-js'; +import {AuthClient} from '../auth-client'; +import AsgardeoUIException from '../exception'; +import {AuthApiResponse} from '../models/auth-api-response'; + +const authorize = async (): Promise => { + let response: Response; + let requestOptions: RequestInit; + let authzURL: string; + try { + const authInstace: AsgardeoAuthClient = AuthClient.getInstance(); + const params: Map = await authInstace.getAuthorizationURLParams(); + + const formBody: URLSearchParams = new URLSearchParams(); + + Array.from(params.entries()).forEach(([key, value]: [string, string]) => { + formBody.append(key, value); + }); + + /* Save the state temporarily in the data layer, this needs to be passed when token is requested */ + await authInstace.getDataLayer().setTemporaryDataParameter('state', params.get('state')); + + const headers: Headers = new Headers(); + headers.append('Accept', 'application/json'); + headers.append('Content-Type', 'application/x-www-form-urlencoded'); + + requestOptions = { + body: formBody.toString(), + headers, + method: 'POST', + }; + + authzURL = (await authInstace.getOIDCServiceEndpoints()).authorizationEndpoint; + } catch (error) { + throw new AsgardeoUIException('JS_UI_CORE-AUTHZ-A-NF', 'Authorization request building failed', error.stack); + } + + try { + response = await fetch(authzURL, requestOptions); + } catch (error) { + throw new AsgardeoUIException('JS_UI_CORE-AUTHZ-A-NE', 'Authorization API call failed', error.stack); + } + + if (response.ok) { + return (await response.json()) as AuthApiResponse; + } + throw new AsgardeoUIException( + 'UI_CORE-AUTHZ-A-HE', + 'Failed to receive a successful response from the authorization server', + ); +}; + +export default authorize; diff --git a/packages/core/src/models/auth-api-response.ts b/packages/core/src/models/auth-api-response.ts index e69de29b..0709a4a0 100644 --- a/packages/core/src/models/auth-api-response.ts +++ b/packages/core/src/models/auth-api-response.ts @@ -0,0 +1,129 @@ +/** + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export interface AuthApiResponse { + /* If user is successfully authenticated, contains the authentication data. */ + authData?: AuthData; + /* A unique identifier for the authentication flow. */ + flowId: string; + /* The status of the authentication flow. */ + flowStatus: FlowStatus; + /* The type of the authentication flow. */ + flowType: string; + /* Contains the urls related to the authentication flow. */ + links: Link[]; + /* Contains the authenticator data related to the next step. */ + nextStep: AuthStep; +} + +export interface AuthData { + code: string; + session_state: string; +} + +export enum FlowStatus { + FailIncomplete = 'FAIL_INCOMPLETE', + Incomplete = 'INCOMPLETE', + SuccessCompleted = 'SUCCESS_COMPLETED', +} + +export interface Link { + /* The relative url of the link. */ + href: string; + /* The supported http methods of the link. */ + method: LinkMethod; + /* The identifier of the link. */ + name: string; +} + +export enum LinkMethod { + Get = 'GET', + Post = 'POST', +} + +export interface AuthStep { + /* Contains the data related to the available authentication steps. */ + authenticators: Authenticator[]; + /* The type of the next step in the authentication flow. */ + stepType: StepType; +} + +export enum StepType { + /* The next step is for authenticating the user through a configured authenticator. */ + AuthenticatorPrompt = 'AUTHENTICATOR_PROMPT', + /* The next step is for authenticator selection. */ + MultiOptionsPrompt = 'MULTI_OPTIONS_PROMPT', +} + +export interface Authenticator { + /* The authenticator name. */ + authenticator: string; + /* The authenticator identifier. */ + authenticatorId: string; + /* The identity provider identifier. */ + idp: string; + /* Contains the metadata related to an authenticator. */ + metadata: Metadata; + /* Contains the required parameters that should be sent to the server for processing the current step of the authentication request. */ + requiredParams: string[]; +} + +export interface Metadata { + /* Contains any additional data related to the authenticator which would be needed for the application to perform authentication. */ + additionalData?: AdditionalData; + /* The i18n key for the authenticator. */ + i18nKey: string; + /* If the promptType is USER_PROMPT, contains the data related to input parameters of the authenticator. */ + params?: Params; + /* The type of the prompt. */ + promptType: PromptType; +} + +export enum PromptType { + /* The prompt is for the system to perform an internal action which will result in obtaining the required parameters. */ + InternalPrompt = 'INTERNAL_PROMPT', + /* The prompt is for the user to be redirected to a different url which will result in obtaining the required parameters. */ + RedirectionPromt = 'REDIRECTION_PROMPT', + /* The prompt is for the user to input the required parameters for the authenticator. */ + UserPrompt = 'USER_PROMPT', +} + +export interface Params { + /* Indicates whether the parameter is confidential or not. */ + confidential: boolean; + /* Display name when prompting for the user. */ + displayName: string; + i18nKey: string; + /* Indicates the recommended display order of the parameter. */ + order: number; + /* The parameter identifier. */ + param: string; + /* Indicates the data type of the parameter. */ + type: ParamsType; +} + +export enum ParamsType { + Boolean = 'BOOLEAN', + Integer = 'INTEGER', + String = 'STRING', +} + +export interface AdditionalData { + redirectUrl: string; + state: string; +} From 829591f5d55790c83ce218c308760d23d88480b3 Mon Sep 17 00:00:00 2001 From: Movin Silva Date: Thu, 18 Apr 2024 23:52:33 +0530 Subject: [PATCH 04/18] feat(core): :sparkles: add authenticate function --- packages/core/src/api/authenticate.ts | 78 ++++++++++++++++++++ packages/core/src/models/auth-api-request.ts | 31 ++++++++ 2 files changed, 109 insertions(+) create mode 100644 packages/core/src/models/auth-api-request.ts diff --git a/packages/core/src/api/authenticate.ts b/packages/core/src/api/authenticate.ts index e69de29b..8bfe2374 100644 --- a/packages/core/src/api/authenticate.ts +++ b/packages/core/src/api/authenticate.ts @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import {AuthClient} from 'src/auth-client'; +import {AuthApiRequestBody} from 'src/models/auth-api-request'; +import AsgardeoUIException from '../exception'; +import {AuthApiResponse} from '../models/auth-api-response'; + +interface Authenticate { + authenticatorID: string; + authenticatorParametres?: Record; + flowID: string; +} + +const authenticate = async (props: Authenticate): Promise => { + const {flowID, authenticatorID, authenticatorParametres} = props; + + let authnRequest: Request; + let response: Response; + + try { + const authBody: AuthApiRequestBody = { + flowId: flowID, + selectedAuthenticator: { + authenticatorId: authenticatorID, + ...(authenticatorParametres && {params: authenticatorParametres}), + }, + }; + + const formBody: string = JSON.stringify(authBody); + + const headers: Headers = new Headers(); + headers.append('Content-Type', 'application/json'); + + const requestOptions: RequestInit = { + body: formBody, + headers, + method: 'POST', + }; + + /* Getting baseURL from authClient's data layer */ + const {baseUrl} = await AuthClient.getInstance().getDataLayer().getConfigData(); + + authnRequest = new Request(`${baseUrl}/oauth2/authn`, requestOptions); + } catch (error) { + throw new AsgardeoUIException('JS_UI_CORE-AUTHN-A-NF', 'Authentication request building failed', error.stack); + } + + try { + response = await fetch(authnRequest); + } catch (error) { + throw new AsgardeoUIException('JS_UI_CORE-AUTHN-A-NE', `Authentication API call Failed: ${error}`, error.stack); + } + if (response.ok) { + return (await response.json()) as AuthApiResponse; + } + throw new AsgardeoUIException( + 'JS_UI_CORE-AUTHN-AN-HE', + 'Failed to receive a successful response from the authentication endpoint', + ); +}; + +export default authenticate; diff --git a/packages/core/src/models/auth-api-request.ts b/packages/core/src/models/auth-api-request.ts new file mode 100644 index 00000000..017fc5f1 --- /dev/null +++ b/packages/core/src/models/auth-api-request.ts @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export interface AuthApiRequestBody { + /* The authentication flow id. */ + flowId: string; + /* Contains selected authenticator's required details. */ + selectedAuthenticator: SelectedAuthenticator; +} + +export interface SelectedAuthenticator { + /* The authentication authenticator id. */ + authenticatorId: string; + /* Required parameters for the selected authenticator. */ + params?: Record; +} From 4a94d23b616100b81c92fb35d3f2be604e4edd89 Mon Sep 17 00:00:00 2001 From: Movin Silva Date: Fri, 19 Apr 2024 06:53:51 +0530 Subject: [PATCH 05/18] feat(core): :sparkles: improve config types --- packages/core/src/models/auth-config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/models/auth-config.ts b/packages/core/src/models/auth-config.ts index fde4dddc..2f878023 100644 --- a/packages/core/src/models/auth-config.ts +++ b/packages/core/src/models/auth-config.ts @@ -29,6 +29,6 @@ interface AuthClientConfigExtension { type?: string; } -export type UIAuthConfig = AuthClientConfig; +export type UIAuthConfig = AuthClientConfig; -export type UIAuthClient = AsgardeoAuthClient; +export type UIAuthClient = AsgardeoAuthClient; From ca7398fa46dc56512b145c6fffb1189e4ed768f4 Mon Sep 17 00:00:00 2001 From: Movin Silva Date: Fri, 19 Apr 2024 09:52:52 +0530 Subject: [PATCH 06/18] style(core): :art: Change the comment structure, add jsdoc comments & modify props interface of authenticate function --- packages/core/src/api/authenticate.ts | 26 +-- packages/core/src/api/authorize.ts | 8 +- packages/core/src/models/auth-api-request.ts | 22 +- packages/core/src/models/auth-api-response.ts | 188 +++++++++++++++--- packages/core/src/models/auth-config.ts | 34 +++- 5 files changed, 221 insertions(+), 57 deletions(-) diff --git a/packages/core/src/api/authenticate.ts b/packages/core/src/api/authenticate.ts index 8bfe2374..c0d60505 100644 --- a/packages/core/src/api/authenticate.ts +++ b/packages/core/src/api/authenticate.ts @@ -21,28 +21,18 @@ import {AuthApiRequestBody} from 'src/models/auth-api-request'; import AsgardeoUIException from '../exception'; import {AuthApiResponse} from '../models/auth-api-response'; -interface Authenticate { - authenticatorID: string; - authenticatorParametres?: Record; - flowID: string; -} - -const authenticate = async (props: Authenticate): Promise => { - const {flowID, authenticatorID, authenticatorParametres} = props; - +/** + * Sends an authentication request to the authentication API. + * + * @param {AuthApiRequestBody} props - The authentication request body. + * @returns {Promise} A promise that resolves with the authentication API response. + */ +const authenticate = async (props: AuthApiRequestBody): Promise => { let authnRequest: Request; let response: Response; try { - const authBody: AuthApiRequestBody = { - flowId: flowID, - selectedAuthenticator: { - authenticatorId: authenticatorID, - ...(authenticatorParametres && {params: authenticatorParametres}), - }, - }; - - const formBody: string = JSON.stringify(authBody); + const formBody: string = JSON.stringify(props); const headers: Headers = new Headers(); headers.append('Content-Type', 'application/json'); diff --git a/packages/core/src/api/authorize.ts b/packages/core/src/api/authorize.ts index 1b656049..bbf9297e 100644 --- a/packages/core/src/api/authorize.ts +++ b/packages/core/src/api/authorize.ts @@ -16,17 +16,21 @@ * under the License. */ -import {AsgardeoAuthClient} from '@asgardeo/auth-js'; +import {UIAuthClient} from 'src/models/auth-config'; import {AuthClient} from '../auth-client'; import AsgardeoUIException from '../exception'; import {AuthApiResponse} from '../models/auth-api-response'; +/** + * This function is used to authorize the user. + * @returns {Promise} A promise that resolves with the authorization response. + */ const authorize = async (): Promise => { let response: Response; let requestOptions: RequestInit; let authzURL: string; try { - const authInstace: AsgardeoAuthClient = AuthClient.getInstance(); + const authInstace: UIAuthClient = AuthClient.getInstance(); const params: Map = await authInstace.getAuthorizationURLParams(); const formBody: URLSearchParams = new URLSearchParams(); diff --git a/packages/core/src/models/auth-api-request.ts b/packages/core/src/models/auth-api-request.ts index 017fc5f1..4e0fcb09 100644 --- a/packages/core/src/models/auth-api-request.ts +++ b/packages/core/src/models/auth-api-request.ts @@ -16,16 +16,30 @@ * under the License. */ +/** + * Interface for the Authn API request body. + */ export interface AuthApiRequestBody { - /* The authentication flow id. */ + /** + * The authentication flow id. + */ flowId: string; - /* Contains selected authenticator's required details. */ + /** + * Contains selected authenticator's required details. + */ selectedAuthenticator: SelectedAuthenticator; } +/** + * Interface for the selected authenticator. + */ export interface SelectedAuthenticator { - /* The authentication authenticator id. */ + /** + * The authentication authenticator id. + */ authenticatorId: string; - /* Required parameters for the selected authenticator. */ + /** + *Required parameters for the selected authenticator. + */ params?: Record; } diff --git a/packages/core/src/models/auth-api-response.ts b/packages/core/src/models/auth-api-response.ts index 0709a4a0..7903de49 100644 --- a/packages/core/src/models/auth-api-response.ts +++ b/packages/core/src/models/auth-api-response.ts @@ -16,114 +16,242 @@ * under the License. */ +/** + * Interface for the Authn and Authz API response. + */ export interface AuthApiResponse { - /* If user is successfully authenticated, contains the authentication data. */ + /** + *If user is successfully authenticated, contains the authentication data. + */ authData?: AuthData; - /* A unique identifier for the authentication flow. */ + /** + *A unique identifier for the authentication flow. + */ flowId: string; - /* The status of the authentication flow. */ + /** + * The status of the authentication flow. + */ flowStatus: FlowStatus; - /* The type of the authentication flow. */ + /** + * The type of the authentication flow. + */ flowType: string; - /* Contains the urls related to the authentication flow. */ + /** + * Contains the urls related to the authentication flow. + */ links: Link[]; - /* Contains the authenticator data related to the next step. */ + /** + * Contains the authenticator data related to the next step. + */ nextStep: AuthStep; } +/** + * Interface for the authentication data after flow status become SUCCESS_COMPLETED. + */ export interface AuthData { + /** + * Code of the authentication flow + */ code: string; + /** + * Session state of the authentication flow + */ session_state: string; } +/** + * Enum for the flow status. + */ export enum FlowStatus { + /** + * The authentication flow is failed. + */ FailIncomplete = 'FAIL_INCOMPLETE', + /** + * The authentication flow is incomplete. + */ Incomplete = 'INCOMPLETE', + /** + * The authentication flow is success. + */ SuccessCompleted = 'SUCCESS_COMPLETED', } +/** + * Interface for the link. + */ export interface Link { - /* The relative url of the link. */ + /** + * The relative url of the link. + */ href: string; - /* The supported http methods of the link. */ + /** + * The supported http methods of the link. + */ method: LinkMethod; - /* The identifier of the link. */ + /** + * The identifier of the link. + */ name: string; } +/** + * Enum for the link method. + */ export enum LinkMethod { Get = 'GET', Post = 'POST', } +/** + * Interface for the authentication step. + */ export interface AuthStep { - /* Contains the data related to the available authentication steps. */ + /** + * Contains the data related to the available authentication steps. + */ authenticators: Authenticator[]; - /* The type of the next step in the authentication flow. */ + /** + * The type of the next step in the authentication flow. + */ stepType: StepType; } +/** + * Enum for the step type. + */ export enum StepType { - /* The next step is for authenticating the user through a configured authenticator. */ + /** + * The next step is for authenticating the user through a configured authenticator. + */ AuthenticatorPrompt = 'AUTHENTICATOR_PROMPT', - /* The next step is for authenticator selection. */ + /** + * The next step is for authenticator selection. + */ MultiOptionsPrompt = 'MULTI_OPTIONS_PROMPT', } +/** + * Interface for the authenticator. + */ export interface Authenticator { - /* The authenticator name. */ + /** + * The authenticator name. + */ authenticator: string; - /* The authenticator identifier. */ + /** + * The authenticator identifier. + */ authenticatorId: string; - /* The identity provider identifier. */ + /** + * The identity provider identifier. + */ idp: string; - /* Contains the metadata related to an authenticator. */ + /** + * The metadata related to the authenticator. + */ metadata: Metadata; - /* Contains the required parameters that should be sent to the server for processing the current step of the authentication request. */ + /** + * Contains the required parameters that should be sent to the server for + * processing the current step of the authentication request. + */ requiredParams: string[]; } +/** + * Interface for the metadata. + */ export interface Metadata { - /* Contains any additional data related to the authenticator which would be needed for the application to perform authentication. */ + /** + * Contains any additional data related to the authenticator which would be + * needed for the application to perform authentication. + */ additionalData?: AdditionalData; - /* The i18n key for the authenticator. */ + /** + * The i18n key for the authenticator. + */ i18nKey: string; - /* If the promptType is USER_PROMPT, contains the data related to input parameters of the authenticator. */ + /** + * If the promptType is USER_PROMPT, contains the data related to input parameters of the authenticator. + * */ params?: Params; - /* The type of the prompt. */ + /** + * The type of the prompt. + */ promptType: PromptType; } +/** + * Enum for the prompt type. + */ export enum PromptType { - /* The prompt is for the system to perform an internal action which will result in obtaining the required parameters. */ + /** + * The prompt is for the system to perform an internal action which + * will result in obtaining the required parameters. + */ InternalPrompt = 'INTERNAL_PROMPT', - /* The prompt is for the user to be redirected to a different url which will result in obtaining the required parameters. */ + /** + * The prompt is for the user to be redirected to a different url which + * will result in obtaining the required parameters. + */ RedirectionPromt = 'REDIRECTION_PROMPT', - /* The prompt is for the user to input the required parameters for the authenticator. */ + /** + * The prompt is for the user to input the required parameters for the authenticator. + */ UserPrompt = 'USER_PROMPT', } +/** + * Interface for the params. + */ export interface Params { - /* Indicates whether the parameter is confidential or not. */ + /** + * Indicates whether the parameter is confidential or not. + */ confidential: boolean; - /* Display name when prompting for the user. */ + /** + * Display name when prompting for the user. + */ displayName: string; + /** + * The i18n key for the parameter. + */ i18nKey: string; - /* Indicates the recommended display order of the parameter. */ + + /** + * Indicates the recommended display order of the parameter. + */ order: number; - /* The parameter identifier. */ + /* + * The parameter identifier. + */ param: string; - /* Indicates the data type of the parameter. */ + /** + * Indicates the data type of the parameter. + */ type: ParamsType; } +/** + * Enum for the params type. + */ export enum ParamsType { Boolean = 'BOOLEAN', Integer = 'INTEGER', String = 'STRING', } +/** + * Interface for the additional data. + */ export interface AdditionalData { + /** + * Redirect URL for the redirection prompt. + */ redirectUrl: string; + /** + * The state of the authentication flow. + */ state: string; } diff --git a/packages/core/src/models/auth-config.ts b/packages/core/src/models/auth-config.ts index 2f878023..09bb7245 100644 --- a/packages/core/src/models/auth-config.ts +++ b/packages/core/src/models/auth-config.ts @@ -18,17 +18,45 @@ import {AsgardeoAuthClient, AuthClientConfig} from '@asgardeo/auth-js'; +/** + * Interface for the configuration extension from the AuthClientConfig of '@asgardeo/auth-js'. + */ interface AuthClientConfigExtension { - /* If enabled, the branding from the console will be used. Default value is true */ + /** + * If enabled, the branding from the console will be used. Default value is true. + */ enableConsoleBranding?: boolean; - /* If enabled, the text branding from the console will be used for the text. Default value is true */ + /** + * If enabled, the text branding from the console will be used for the text. Default value is true. + */ enableConsoleTextBranding?: boolean; /* Language code of the locale. */ locale?: string; + /** + * Tenant/Application name to filter the retrieval of customizations. + */ name?: string; - type?: string; + /** + * Type to filter the retrieval of customizations. + */ + type?: OrgType; +} + +/** + * Enum for the organization type. + */ +export enum OrgType { + App = 'APP', + Custom = 'CUSTOM', + Org = 'ORG', } +/** + * Type for the UI Auth configuration. + */ export type UIAuthConfig = AuthClientConfig; +/** + * Type for the UI Auth client. + */ export type UIAuthClient = AsgardeoAuthClient; From 0ae3ff9c332a76dfc64540f29a6d672b0513946d Mon Sep 17 00:00:00 2001 From: Movin Silva Date: Fri, 19 Apr 2024 09:58:55 +0530 Subject: [PATCH 07/18] refactor(core): :art: update custom exception class and add docs --- packages/core/src/exception.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/core/src/exception.ts b/packages/core/src/exception.ts index 252c23f1..c45531b6 100644 --- a/packages/core/src/exception.ts +++ b/packages/core/src/exception.ts @@ -16,16 +16,39 @@ * under the License. */ +/** + * `AsgardeoUIException` is a custom error class that extends the built-in `Error` class. + * + * @extends {Error} + */ export default class AsgardeoUIException extends Error { + /** + * The name of the error, which is set to the name of the constructor. + * @override + */ public override name: string; + /** + * The stack trace of the error. + * @override + */ public override stack: string; + /** + * The code of the error. + */ public code: string; + /** + * Constructs a new `AsgardeoUIException`. + * + * @param {string} code - The error code. + * @param {string} message - The error message. + * @param {any} [stack] - The error stack trace. + */ constructor(code: string, message: string, stack?: any) { super(message); - this.code = `ASG-${code}`; + this.code = code; this.name = this.constructor.name; this.stack = stack; } From 94b14c17b868fb73619e28086e8d5b003bc5a304 Mon Sep 17 00:00:00 2001 From: Movin Silva Date: Fri, 19 Apr 2024 10:06:52 +0530 Subject: [PATCH 08/18] docs(core): :memo: update JSDocs for auth client --- packages/core/src/auth-client.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/core/src/auth-client.ts b/packages/core/src/auth-client.ts index a846bdbb..81582341 100644 --- a/packages/core/src/auth-client.ts +++ b/packages/core/src/auth-client.ts @@ -19,6 +19,9 @@ import {AsgardeoAuthClient, Store, CryptoUtils} from '@asgardeo/auth-js'; import {UIAuthClient, UIAuthConfig} from './models/auth-config'; +/** + * The `AuthClient` class is a singleton class that provides an instance of the `UIAuthClient`. + */ export class AuthClient { private static instance: UIAuthClient; @@ -30,6 +33,14 @@ export class AuthClient { // eslint-disable-next-line @typescript-eslint/no-empty-function private constructor() {} + /** + * Returns the singleton instance of `UIAuthClient`. If the instance does not exist, it is created. + * + * @param {UIAuthConfig} authClientConfig - The configuration for the `UIAuthClient`. + * @param {Store} store - The store for the `UIAuthClient`. + * @param {CryptoUtils} cryptoUtils - The crypto utilities for the `UIAuthClient`. + * @returns {UIAuthClient} The singleton instance of `UIAuthClient`. + */ static getInstance(authClientConfig?: UIAuthConfig, store?: Store, cryptoUtils?: CryptoUtils): UIAuthClient { if (!AuthClient.instance) { AuthClient.instance = new AsgardeoAuthClient(); From 3c525350a25e866958ed8286300540fbb7b26f5e Mon Sep 17 00:00:00 2001 From: Movin Silva Date: Wed, 24 Apr 2024 11:04:38 +0530 Subject: [PATCH 09/18] chore(workspace): :wrench: update issue template --- issue_template.md | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/issue_template.md b/issue_template.md index 757e13ef..4e2c2ae5 100644 --- a/issue_template.md +++ b/issue_template.md @@ -1,18 +1,20 @@ -**Description:** - +### Purpose + -**Suggested Labels:** - +### Related Issues +- -**Suggested Assignees:** - +### Related PRs +- -**Affected Product Version:** +### Checklist +- [ ] Manual test round performed and verified. +- [ ] UX/UI review done on the final implementation. +- [ ] Documentation provided. (Add links if there are any) +- [ ] Unit tests provided. (Add links if there are any) +- [ ] Integration tests provided. (Add links if there are any) -**OS, DB, other environment details and versions:** - -**Steps to reproduce:** - - -**Related Issues:** - \ No newline at end of file +### Security checks +- [ ] Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? +- [ ] Ran FindSecurityBugs plugin and verified report? +- [ ] Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? From 21e44dada125e2a6d8b4a205c378099d4204f2d0 Mon Sep 17 00:00:00 2001 From: Movin Silva Date: Wed, 24 Apr 2024 12:32:01 +0530 Subject: [PATCH 10/18] style(core): :art: improve format & comments --- packages/core/src/api/authenticate.ts | 2 +- packages/core/src/models/auth-api-response.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/core/src/api/authenticate.ts b/packages/core/src/api/authenticate.ts index c0d60505..3018c2df 100644 --- a/packages/core/src/api/authenticate.ts +++ b/packages/core/src/api/authenticate.ts @@ -22,7 +22,7 @@ import AsgardeoUIException from '../exception'; import {AuthApiResponse} from '../models/auth-api-response'; /** - * Sends an authentication request to the authentication API. + * Send an authentication request to the authentication API. * * @param {AuthApiRequestBody} props - The authentication request body. * @returns {Promise} A promise that resolves with the authentication API response. diff --git a/packages/core/src/models/auth-api-response.ts b/packages/core/src/models/auth-api-response.ts index 7903de49..42e2dcee 100644 --- a/packages/core/src/models/auth-api-response.ts +++ b/packages/core/src/models/auth-api-response.ts @@ -218,7 +218,6 @@ export interface Params { * The i18n key for the parameter. */ i18nKey: string; - /** * Indicates the recommended display order of the parameter. */ From b236cc1a3f74c07b1318260786ce3c4fbcf4f923 Mon Sep 17 00:00:00 2001 From: Movin Silva Date: Thu, 25 Apr 2024 11:31:39 +0530 Subject: [PATCH 11/18] style(core): :art: update eslint and prettier config packages & internal headers --- packages/core/.eslintrc.cjs | 2 +- packages/core/package.json | 7 ++-- packages/core/prettier.config.cjs | 2 +- packages/core/src/api/authenticate.ts | 2 +- packages/core/src/api/authorize.ts | 2 +- packages/core/src/auth-client.ts | 2 +- packages/core/src/exception.ts | 2 +- packages/core/src/models/auth-api-request.ts | 2 +- packages/core/src/models/auth-api-response.ts | 2 +- packages/core/src/models/auth-config.ts | 2 +- pnpm-lock.yaml | 41 +++++++++---------- 11 files changed, 33 insertions(+), 33 deletions(-) diff --git a/packages/core/.eslintrc.cjs b/packages/core/.eslintrc.cjs index 38e0ff9b..3a1c39e7 100644 --- a/packages/core/.eslintrc.cjs +++ b/packages/core/.eslintrc.cjs @@ -1,5 +1,5 @@ /** - * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except diff --git a/packages/core/package.json b/packages/core/package.json index 107b67f6..db1073f6 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -32,8 +32,8 @@ }, "devDependencies": { "@types/node": "^20.12.7", - "@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?5bf60cabe9e9a2571e8b1dd16d0c3bdc76db2c4f", - "@wso2/prettier-config": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?5bf60cabe9e9a2571e8b1dd16d0c3bdc76db2c4f", + "@wso2/eslint-plugin": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?fa0b844715320a3953d6d055997c0770f8695082", + "@wso2/prettier-config": "https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?fa0b844715320a3953d6d055997c0770f8695082", "eslint": "~8.57.0", "prettier": "^3.2.5", "tslib": "^2.6.2", @@ -43,6 +43,7 @@ "access": "public" }, "dependencies": { - "@asgardeo/auth-js": "^5.0.1" + "@asgardeo/auth-js": "^5.0.1", + "@asgardeo/js-ui-core": "link:" } } diff --git a/packages/core/prettier.config.cjs b/packages/core/prettier.config.cjs index 0f461af9..c07f730d 100644 --- a/packages/core/prettier.config.cjs +++ b/packages/core/prettier.config.cjs @@ -1,5 +1,5 @@ /** - * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except diff --git a/packages/core/src/api/authenticate.ts b/packages/core/src/api/authenticate.ts index 3018c2df..419dfb54 100644 --- a/packages/core/src/api/authenticate.ts +++ b/packages/core/src/api/authenticate.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except diff --git a/packages/core/src/api/authorize.ts b/packages/core/src/api/authorize.ts index bbf9297e..b1ecbaf4 100644 --- a/packages/core/src/api/authorize.ts +++ b/packages/core/src/api/authorize.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except diff --git a/packages/core/src/auth-client.ts b/packages/core/src/auth-client.ts index 81582341..2b4e3e72 100644 --- a/packages/core/src/auth-client.ts +++ b/packages/core/src/auth-client.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except diff --git a/packages/core/src/exception.ts b/packages/core/src/exception.ts index c45531b6..8cadecd3 100644 --- a/packages/core/src/exception.ts +++ b/packages/core/src/exception.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except diff --git a/packages/core/src/models/auth-api-request.ts b/packages/core/src/models/auth-api-request.ts index 4e0fcb09..6e48bb49 100644 --- a/packages/core/src/models/auth-api-request.ts +++ b/packages/core/src/models/auth-api-request.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except diff --git a/packages/core/src/models/auth-api-response.ts b/packages/core/src/models/auth-api-response.ts index 42e2dcee..81bd6a6e 100644 --- a/packages/core/src/models/auth-api-response.ts +++ b/packages/core/src/models/auth-api-response.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except diff --git a/packages/core/src/models/auth-config.ts b/packages/core/src/models/auth-config.ts index 09bb7245..db96624c 100644 --- a/packages/core/src/models/auth-config.ts +++ b/packages/core/src/models/auth-config.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index af919abb..606373e2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,16 +17,19 @@ importers: '@asgardeo/auth-js': specifier: ^5.0.1 version: 5.0.1 + '@asgardeo/js-ui-core': + specifier: 'link:' + version: 'link:' devDependencies: '@types/node': specifier: ^20.12.7 version: 20.12.7 '@wso2/eslint-plugin': - specifier: https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?5bf60cabe9e9a2571e8b1dd16d0c3bdc76db2c4f - version: '@gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?5bf60cabe9e9a2571e8b1dd16d0c3bdc76db2c4f(eslint@8.57.0)(typescript@5.4.5)' + specifier: https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?fa0b844715320a3953d6d055997c0770f8695082 + version: '@gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?fa0b844715320a3953d6d055997c0770f8695082(eslint@8.57.0)(typescript@5.4.5)' '@wso2/prettier-config': - specifier: https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?5bf60cabe9e9a2571e8b1dd16d0c3bdc76db2c4f - version: '@gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?5bf60cabe9e9a2571e8b1dd16d0c3bdc76db2c4f(prettier@3.2.5)(typescript@5.4.5)' + specifier: https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?fa0b844715320a3953d6d055997c0770f8695082 + version: '@gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?fa0b844715320a3953d6d055997c0770f8695082(prettier@3.2.5)(typescript@5.4.5)' eslint: specifier: ~8.57.0 version: 8.57.0 @@ -949,8 +952,8 @@ packages: engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} hasBin: true dependencies: - caniuse-lite: 1.0.30001610 - electron-to-chromium: 1.4.736 + caniuse-lite: 1.0.30001612 + electron-to-chromium: 1.4.747 node-releases: 2.0.14 update-browserslist-db: 1.0.13(browserslist@4.23.0) dev: true @@ -978,8 +981,8 @@ packages: engines: {node: '>=6'} dev: true - /caniuse-lite@1.0.30001610: - resolution: {integrity: sha512-QFutAY4NgaelojVMjY63o6XlZyORPaLfyMnsl3HgnWdJUcX6K0oaJymHjH8PT5Gk7sTm8rvC/c5COUQKXqmOMA==} + /caniuse-lite@1.0.30001612: + resolution: {integrity: sha512-lFgnZ07UhaCcsSZgWW0K5j4e69dK1u/ltrL9lTUiFOwNHs12S3UMIEYgBV0Z6C6hRDev7iRnMzzYmKabYdXF9g==} dev: true /chalk@2.4.2: @@ -1118,7 +1121,7 @@ packages: supports-color: optional: true dependencies: - ms: 2.1.3 + ms: 2.1.2 dev: true /debug@4.3.4: @@ -1216,8 +1219,8 @@ packages: resolution: {integrity: sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==} dev: true - /electron-to-chromium@1.4.736: - resolution: {integrity: sha512-Rer6wc3ynLelKNM4lOCg7/zPQj8tPOCB2hzD32PX9wd3hgRRi9MxEbmkFCokzcEhRVMiOVLjnL9ig9cefJ+6+Q==} + /electron-to-chromium@1.4.747: + resolution: {integrity: sha512-+FnSWZIAvFHbsNVmUxhEqWiaOiPMcfum1GQzlWCg/wLigVtshOsjXHyEFfmt6cFK6+HkS3QOJBv6/3OPumbBfw==} dev: true /emoji-regex@8.0.0: @@ -2578,10 +2581,6 @@ packages: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} dev: true - /ms@2.1.3: - resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} - dev: true - /natural-compare-lite@1.4.0: resolution: {integrity: sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==} dev: true @@ -3497,9 +3496,9 @@ packages: engines: {node: '>=10'} dev: true - '@gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?5bf60cabe9e9a2571e8b1dd16d0c3bdc76db2c4f(eslint@8.57.0)(typescript@5.4.5)': - resolution: {tarball: https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?5bf60cabe9e9a2571e8b1dd16d0c3bdc76db2c4f} - id: '@gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?5bf60cabe9e9a2571e8b1dd16d0c3bdc76db2c4f' + '@gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?fa0b844715320a3953d6d055997c0770f8695082(eslint@8.57.0)(typescript@5.4.5)': + resolution: {tarball: https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?fa0b844715320a3953d6d055997c0770f8695082} + id: '@gitpkg.now.sh/brionmario/wso2-ui-configs/packages/eslint-plugin?fa0b844715320a3953d6d055997c0770f8695082' name: '@wso2/eslint-plugin' version: 0.1.0 engines: {node: ^14.17.0 || ^16.0.0 || >= 18.0.0} @@ -3542,9 +3541,9 @@ packages: - supports-color dev: true - '@gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?5bf60cabe9e9a2571e8b1dd16d0c3bdc76db2c4f(prettier@3.2.5)(typescript@5.4.5)': - resolution: {tarball: https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?5bf60cabe9e9a2571e8b1dd16d0c3bdc76db2c4f} - id: '@gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?5bf60cabe9e9a2571e8b1dd16d0c3bdc76db2c4f' + '@gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?fa0b844715320a3953d6d055997c0770f8695082(prettier@3.2.5)(typescript@5.4.5)': + resolution: {tarball: https://gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?fa0b844715320a3953d6d055997c0770f8695082} + id: '@gitpkg.now.sh/brionmario/wso2-ui-configs/packages/prettier-config?fa0b844715320a3953d6d055997c0770f8695082' name: '@wso2/prettier-config' version: 0.1.0 engines: {node: '>=14.0.0'} From 23afc0e036c1608fbab7c162ce12264bde7527a1 Mon Sep 17 00:00:00 2001 From: Movin Silva Date: Thu, 25 Apr 2024 11:39:11 +0530 Subject: [PATCH 12/18] fix(core): :bug: update stack parameter type in AsgardeoUIException --- packages/core/src/exception.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/exception.ts b/packages/core/src/exception.ts index 8cadecd3..d8695d56 100644 --- a/packages/core/src/exception.ts +++ b/packages/core/src/exception.ts @@ -44,9 +44,9 @@ export default class AsgardeoUIException extends Error { * * @param {string} code - The error code. * @param {string} message - The error message. - * @param {any} [stack] - The error stack trace. + * @param {string} [stack] - The error stack trace. */ - constructor(code: string, message: string, stack?: any) { + constructor(code: string, message: string, stack?: string) { super(message); this.code = code; this.name = this.constructor.name; From 166f0319faf00289a997f174574eefca7d69cac5 Mon Sep 17 00:00:00 2001 From: Movin Silva Date: Thu, 25 Apr 2024 11:49:14 +0530 Subject: [PATCH 13/18] refactor(workspace): --- issue_template.md | 30 ++++++++--------- pull_request_template.md | 73 ++++++++++++---------------------------- 2 files changed, 35 insertions(+), 68 deletions(-) diff --git a/issue_template.md b/issue_template.md index 4e2c2ae5..757e13ef 100644 --- a/issue_template.md +++ b/issue_template.md @@ -1,20 +1,18 @@ -### Purpose - +**Description:** + -### Related Issues -- +**Suggested Labels:** + -### Related PRs -- +**Suggested Assignees:** + -### Checklist -- [ ] Manual test round performed and verified. -- [ ] UX/UI review done on the final implementation. -- [ ] Documentation provided. (Add links if there are any) -- [ ] Unit tests provided. (Add links if there are any) -- [ ] Integration tests provided. (Add links if there are any) +**Affected Product Version:** -### Security checks -- [ ] Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? -- [ ] Ran FindSecurityBugs plugin and verified report? -- [ ] Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? +**OS, DB, other environment details and versions:** + +**Steps to reproduce:** + + +**Related Issues:** + \ No newline at end of file diff --git a/pull_request_template.md b/pull_request_template.md index 9b32185a..7d7404b7 100644 --- a/pull_request_template.md +++ b/pull_request_template.md @@ -1,52 +1,21 @@ -## Purpose -> Describe the problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc. - -## Goals -> Describe the solutions that this feature/fix will introduce to resolve the problems described above - -## Approach -> Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here. - -## User stories -> Summary of user stories addressed by this change> - -## Release note -> Brief description of the new feature or bug fix as it will appear in the release notes - -## Documentation -> Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact - -## Training -> Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable - -## Certification -> Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why. - -## Marketing -> Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable - -## Automation tests - - Unit tests - > Code coverage information - - Integration tests - > Details about the test cases and coverage - -## Security checks - - Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? yes/no - - Ran FindSecurityBugs plugin and verified report? yes/no - - Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? yes/no - -## Samples -> Provide high-level details about the samples related to this feature - -## Related PRs -> List any other related PRs - -## Migrations (if applicable) -> Describe migration steps and platforms on which migration has been tested - -## Test environment -> List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested - -## Learning -> Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem. \ No newline at end of file +### Purpose + + +### Related Issues +- + +### Related PRs +- + +### Checklist +- [ ] e2e cypress tests locally verified. +- [ ] Manual test round performed and verified. +- [ ] UX/UI review done on the final implementation. +- [ ] Documentation provided. (Add links if there are any) +- [ ] Unit tests provided. (Add links if there are any) +- [ ] Integration tests provided. (Add links if there are any) + +### Security checks +- [ ] Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? +- [ ] Ran FindSecurityBugs plugin and verified report? +- [ ] Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? \ No newline at end of file From baf3fc6fa11b03df1fd3f5b4ec983be49c47a09c Mon Sep 17 00:00:00 2001 From: Brion Mario Date: Thu, 25 Apr 2024 12:18:58 +0530 Subject: [PATCH 14/18] chore: fix formatting issue --- packages/core/src/auth-client.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/auth-client.ts b/packages/core/src/auth-client.ts index 2b4e3e72..7a477405 100644 --- a/packages/core/src/auth-client.ts +++ b/packages/core/src/auth-client.ts @@ -46,6 +46,7 @@ export class AuthClient { AuthClient.instance = new AsgardeoAuthClient(); AuthClient.instance.initialize(authClientConfig, store, cryptoUtils); } + return AuthClient.instance; } } From 5a298eb1180b2b0790dab8bc41c65f5bd8bd92b0 Mon Sep 17 00:00:00 2001 From: Brion Mario Date: Thu, 25 Apr 2024 12:22:36 +0530 Subject: [PATCH 15/18] chore: fix formatting issue --- packages/core/src/api/authenticate.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/api/authenticate.ts b/packages/core/src/api/authenticate.ts index 419dfb54..f7839e24 100644 --- a/packages/core/src/api/authenticate.ts +++ b/packages/core/src/api/authenticate.ts @@ -56,6 +56,7 @@ const authenticate = async (props: AuthApiRequestBody): Promise } catch (error) { throw new AsgardeoUIException('JS_UI_CORE-AUTHN-A-NE', `Authentication API call Failed: ${error}`, error.stack); } + if (response.ok) { return (await response.json()) as AuthApiResponse; } From c76ee31a0417d9a2857d749b3a8279958660fb0b Mon Sep 17 00:00:00 2001 From: Brion Mario Date: Thu, 25 Apr 2024 12:22:44 +0530 Subject: [PATCH 16/18] chore: fix formatting issue --- packages/core/src/api/authenticate.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/api/authenticate.ts b/packages/core/src/api/authenticate.ts index f7839e24..c43a973e 100644 --- a/packages/core/src/api/authenticate.ts +++ b/packages/core/src/api/authenticate.ts @@ -60,6 +60,7 @@ const authenticate = async (props: AuthApiRequestBody): Promise if (response.ok) { return (await response.json()) as AuthApiResponse; } + throw new AsgardeoUIException( 'JS_UI_CORE-AUTHN-AN-HE', 'Failed to receive a successful response from the authentication endpoint', From 368c625f46d3502cdd56780314aaa14f6f7286f8 Mon Sep 17 00:00:00 2001 From: Brion Mario Date: Thu, 25 Apr 2024 12:22:54 +0530 Subject: [PATCH 17/18] chore: fix formatting issue --- packages/core/src/api/authorize.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/api/authorize.ts b/packages/core/src/api/authorize.ts index b1ecbaf4..836b39cc 100644 --- a/packages/core/src/api/authorize.ts +++ b/packages/core/src/api/authorize.ts @@ -29,6 +29,7 @@ const authorize = async (): Promise => { let response: Response; let requestOptions: RequestInit; let authzURL: string; + try { const authInstace: UIAuthClient = AuthClient.getInstance(); const params: Map = await authInstace.getAuthorizationURLParams(); From 6f3ed1c2988816d8d7afbc40270a2cc7fd6b5435 Mon Sep 17 00:00:00 2001 From: Brion Mario Date: Thu, 25 Apr 2024 12:23:00 +0530 Subject: [PATCH 18/18] chore: fix formatting issue --- packages/core/src/api/authorize.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/api/authorize.ts b/packages/core/src/api/authorize.ts index 836b39cc..2e7c2267 100644 --- a/packages/core/src/api/authorize.ts +++ b/packages/core/src/api/authorize.ts @@ -67,6 +67,7 @@ const authorize = async (): Promise => { if (response.ok) { return (await response.json()) as AuthApiResponse; } + throw new AsgardeoUIException( 'UI_CORE-AUTHZ-A-HE', 'Failed to receive a successful response from the authorization server',