Skip to content

Commit

Permalink
Merge pull request #7363 from Shenali-SJ/custom-authentication-api
Browse files Browse the repository at this point in the history
  • Loading branch information
ashanthamara authored Jan 27, 2025
2 parents aa4e594 + bf5cedb commit 34296b6
Show file tree
Hide file tree
Showing 32 changed files with 2,795 additions and 1,060 deletions.
9 changes: 9 additions & 0 deletions .changeset/small-paws-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@wso2is/admin.connections.v1": minor
"@wso2is/admin.identity-providers.v1": patch
"@wso2is/admin.validation.v1": patch
"@wso2is/admin.actions.v1": patch
"@wso2is/admin.core.v1": patch
---

Add custom authenticator UI
14 changes: 14 additions & 0 deletions apps/console/src/configs/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,20 @@ export const getAppViewRoutes = (): RouteInterface[] => {
path: AppConstants.getPaths().get("IDP_EDIT"),
protected: true,
showOnSidePanel: false
},
{
component: lazy(() =>
import("@wso2is/admin.connections.v1/pages/authenticator-edit")
),
exact: true,
icon: {
icon: getSidePanelIcons().childIcon
},
id: "authenticatorEdit",
name: "Local Authenticators Edit",
path: AppConstants.getPaths().get("AUTH_EDIT"),
protected: true,
showOnSidePanel: false
}
],
component: lazy(() => import("@wso2is/admin.connections.v1/pages/connections")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ import { useSelector } from "react-redux";
import { Icon } from "semantic-ui-react";
import { ActionsConstants } from "../constants/actions-constants";
import {
ActionConfigFormPropertyInterface,
AuthenticationType,
AuthenticationTypeDropdownOption
AuthenticationTypeDropdownOption,
EndpointConfigFormPropertyInterface
} from "../models/actions";
import "./action-endpoint-config-form.scss";

interface ActionEndpointConfigFormInterface extends IdentifiableComponentInterface {
/**
* Action's initial values.
*/
initialValues: ActionConfigFormPropertyInterface;
initialValues: EndpointConfigFormPropertyInterface;
/**
* Specifies action creation state.
*/
Expand Down Expand Up @@ -89,10 +89,10 @@ const ActionEndpointConfigForm: FunctionComponent<ActionEndpointConfigFormInterf
* The following useEffect is used to set the current Action Authentication Type.
*/
useEffect(() => {
if (!initialValues?.id) {
if (!initialValues) {
setIsAuthenticationUpdateFormState(true);
} else {
setAuthenticationType(initialValues.authenticationType as AuthenticationType);
setAuthenticationType(initialValues?.authenticationType as AuthenticationType);
setIsAuthenticationUpdateFormState(false);
}
}, [ initialValues ]);
Expand Down
5 changes: 4 additions & 1 deletion features/admin.actions.v1/models/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ export interface ActionTypesCountInterface {
/**
* Action config form property Interface.
*/
export interface ActionConfigFormPropertyInterface {
export interface ActionConfigFormPropertyInterface extends EndpointConfigFormPropertyInterface {
/**
* Id of the Action.
*/
Expand All @@ -368,6 +368,9 @@ export interface ActionConfigFormPropertyInterface {
* Name of the Action.
*/
name: string;
}

export interface EndpointConfigFormPropertyInterface {
/**
* Endpoint Uri of the Action.
*/
Expand Down
5 changes: 3 additions & 2 deletions features/admin.connections.v1/api/authenticators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
} from "../models/authenticators";
import {
ConnectionInterface,
CustomAuthConnectionInterface,
FederatedAuthenticatorListItemInterface,
FederatedAuthenticatorListResponseInterface,
FederatedAuthenticatorMetaInterface
Expand Down Expand Up @@ -252,7 +253,7 @@ export const updateMultiFactorAuthenticatorDetails = (
* @returns Response as a promise.
* @throws IdentityAppsApiException
*/
export const getLocalAuthenticator = (id: string): Promise<AuthenticatorInterface> => {
export const getLocalAuthenticator = (id: string): Promise<AuthenticatorInterface | CustomAuthConnectionInterface> => {

const requestConfig: AxiosRequestConfig = {
headers: {
Expand All @@ -264,7 +265,7 @@ export const getLocalAuthenticator = (id: string): Promise<AuthenticatorInterfac
};

return httpClient(requestConfig)
.then((response: AxiosResponse<AuthenticatorInterface>) => {
.then((response: AxiosResponse<AuthenticatorInterface | CustomAuthConnectionInterface>) => {
if (response.status !== 200) {
throw new IdentityAppsApiException(
ConnectionUIConstants.ERROR_MESSAGES.LOCAL_AUTHENTICATOR_FETCH_INVALID_STATUS_CODE_ERROR,
Expand Down
124 changes: 122 additions & 2 deletions features/admin.connections.v1/api/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
ConnectionListResponseInterface,
ConnectionRolesInterface,
ConnectionTemplateInterface,
CustomAuthConnectionInterface,
FederatedAuthenticatorListItemInterface,
FederatedAuthenticatorListResponseInterface,
FederatedAuthenticatorMetaInterface,
Expand Down Expand Up @@ -86,6 +87,100 @@ export const createConnection = (
});
};

/**
* Function to create a custom authentication
*
* @param connection - Connection settings data.
*/
export const createCustomAuthentication = (
connection: CustomAuthConnectionInterface
): Promise<AxiosResponse<CustomAuthConnectionInterface>> => {

const requestConfig: AxiosRequestConfig = {
data: connection,
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
method: HttpMethods.POST,
url: store.getState().config.endpoints.customAuthenticators
};

return httpClient(requestConfig)
.then((response: AxiosResponse) => {
if ((response.status !== 201)) {
return Promise.reject(new Error("Failed to create the application."));
}

return Promise.resolve(response);
}).catch((error: AxiosError) => {
return Promise.reject(error);
});
};

/**
* Function to update custom local authenticator.
*
* @param id - ID of the custom authentication.
* @param connection - Connection settings data.
*/
export const updateCustomAuthentication = (
id: string,
connection: CustomAuthConnectionInterface
): Promise<AxiosResponse<CustomAuthConnectionInterface>> => {

const requestConfig: AxiosRequestConfig = {
data: connection,
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
method: HttpMethods.PUT,
url: store.getState().config.endpoints.customAuthenticators + "/" + id
};

return httpClient(requestConfig)
.then((response: AxiosResponse) => {
if ((response.status !== 200)) {
return Promise.reject(new Error("Failed to update the custom local authenticator."));
}

return Promise.resolve(response);
}).catch((error: AxiosError) => {
return Promise.reject(error);
});
};

/**
* Function to delete a custom authentication.
*
* @param id - ID of the custom authentication
*/
export const deleteCustomAuthentication = (
id: string
): Promise<AxiosResponse<CustomAuthConnectionInterface>> => {

const requestConfig: AxiosRequestConfig = {
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
method: HttpMethods.DELETE,
url: store.getState().config.endpoints.customAuthenticators + "/" + id
};

return httpClient(requestConfig)
.then((response: AxiosResponse) => {
if ((response.status !== 204)) {
return Promise.reject(new Error("Failed to delete the custom local authenticator."));
}

return Promise.resolve(response);
}).catch((error: AxiosError) => {
return Promise.reject(error);
});
};

/**
* Hook to get the connection list with limit and offset.
*
Expand Down Expand Up @@ -297,7 +392,6 @@ export const useGetConnectionTemplate = <Data = ConnectionTemplateInterface, Err
templateId: string,
shouldFetch: boolean = true
): RequestResultInterface<Data, Error> => {

const { resourceEndpoints } = useResourceEndpoints();

const requestConfig: RequestConfigInterface = {
Expand Down Expand Up @@ -377,7 +471,6 @@ export const getConnectionTemplates = (
offset?: number,
filter?: string
): Promise<any> => {

const requestConfig: RequestConfigInterface = {
headers: {
"Accept": "application/json",
Expand Down Expand Up @@ -495,6 +588,33 @@ export const getConnectionDetails = (id: string): Promise<any> => {
return Promise.reject(error);
});
};
/**
* Gets custom local authenticator details.
*
* @param id - Connection Id.
*/
export const getCustomLocalAuthenticatorDetails = (id: string): Promise<any> => {

const requestConfig: RequestConfigInterface = {
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
method: HttpMethods.GET,
url: store.getState().config.endpoints.customAuthenticators + "/" + id
};

return httpClient(requestConfig)
.then((response: AxiosResponse) => {
if (response.status !== 200) {
return Promise.reject(new Error("Failed to get custom local authenticator details from: "));
}

return Promise.resolve(response.data as any);
}).catch((error: AxiosError) => {
return Promise.reject(error);
});
};

/**
* Update role mappings of a specified IDP.
Expand Down
Loading

0 comments on commit 34296b6

Please sign in to comment.