@@ -30,9 +30,10 @@ import { ConfigReducerStateInterface } from "@wso2is/admin.core.v1/models/reduce
3030import { AppState } from "@wso2is/admin.core.v1/store" ;
3131import { EventPublisher } from "@wso2is/admin.core.v1/utils/event-publisher" ;
3232import { commonConfig } from "@wso2is/admin.extensions.v1" ;
33+ import { useGetCurrentOrganizationType } from "@wso2is/admin.organizations.v1/hooks/use-get-organization-type" ;
3334import { IdentityAppsError } from "@wso2is/core/errors" ;
34- import { AlertLevels , IdentifiableComponentInterface ,
35- HttpErrorResponseDataInterface
35+ import { AlertLevels , HttpErrorResponseDataInterface ,
36+ IdentifiableComponentInterface
3637} from "@wso2is/core/models" ;
3738import { addAlert } from "@wso2is/core/store" ;
3839import { URLUtils } from "@wso2is/core/utils" ;
@@ -163,6 +164,9 @@ export const EnterpriseConnectionCreateWizard: FC<EnterpriseConnectionCreateWiza
163164 const [ isUserInputIdpNameAlreadyTaken , setIsUserInputIdpNameAlreadyTaken ] = useState < boolean > ( undefined ) ;
164165
165166 const config : ConfigReducerStateInterface = useSelector ( ( state : AppState ) => state . config ) ;
167+ const currentOrganizationId : string = useSelector ( ( state : AppState ) => state . organization . organization . id ) ;
168+
169+ const { isSubOrganization } = useGetCurrentOrganizationType ( ) ;
166170
167171 const dispatch : Dispatch = useDispatch ( ) ;
168172 const { t } = useTranslation ( ) ;
@@ -298,7 +302,14 @@ export const EnterpriseConnectionCreateWizard: FC<EnterpriseConnectionCreateWiza
298302 { "key" : "ClientSecret" , "value" : values ?. clientSecret ?. toString ( ) } ,
299303 { "key" : "OAuth2AuthzEPUrl" , "value" : values ?. authorizationEndpointUrl ?. toString ( ) } ,
300304 { "key" : "OAuth2TokenEPUrl" , "value" : values ?. tokenEndpointUrl ?. toString ( ) } ,
301- { "key" : "callbackUrl" , "value" : config ?. deployment ?. customServerHost + "/commonauth" }
305+ {
306+ "key" : "callbackUrl" ,
307+ "value" : isSubOrganization ( ) &&
308+ config ?. deployment ?. organizations ?. connections ?. useTenantQualifiedOrgPatternCommonauth
309+ ? `${ config ?. deployment ?. serverOrigin } /t/${ config ?. deployment ?. tenant } ` +
310+ `/${ config ?. deployment ?. organizationPrefix } /${ currentOrganizationId } /commonauth`
311+ : `${ config ?. deployment ?. customServerHost } /commonauth`
312+ }
302313 ] ;
303314 // Certificates: bind the JWKS URL if exists otherwise pem
304315 identityProvider [ "certificate" ] [ "jwksUri" ] = values . jwks_endpoint ?? EMPTY_STRING ;
0 commit comments