Skip to content

Commit

Permalink
Merge pull request #4359 from Achintha444/master
Browse files Browse the repository at this point in the history
Fix `tenantDomain` not setting properly.
  • Loading branch information
Achintha Isuru authored Oct 26, 2023
2 parents 41f31b5 + 72b6c71 commit 57bd052
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
7 changes: 7 additions & 0 deletions .changeset/quick-pumas-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@wso2is/console": patch
"@wso2is/core": patch
"@wso2is/myaccount": patch
---

fix `tenantDomain` not setting properly.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const BrandingPreferenceProvider: FunctionComponent<BrandingPreferenceProviderPr

const {
data: brandingPreference
} = useGetBrandingPreferenceResolve("709f41e2-a5d3-4ff2-83f1-dad522ca72f8");
} = useGetBrandingPreferenceResolve(tenantDomain);

const {
data: customTextCommons
Expand Down
5 changes: 3 additions & 2 deletions apps/console/src/protected-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ export const ProtectedApp: FunctionComponent<AppPropsInterface> = (): ReactEleme
response = { ...grantResponse };
}
);


setTenant(response.orgId);
dispatch(setCurrentOrganization(response.orgName));
}
}
Expand Down Expand Up @@ -436,7 +437,7 @@ export const ProtectedApp: FunctionComponent<AppPropsInterface> = (): ReactEleme
dispatch(
setSignIn<AuthenticatedUserInfo & TenantListInterface>(
Object.assign(
CommonAuthenticateUtils.getSignInState(response),
CommonAuthenticateUtils.getSignInState(response, response.orgId),
{
associatedTenants: isPrivilegedUser
? tenantDomain
Expand Down
45 changes: 22 additions & 23 deletions modules/core/src/utils/authenticate-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2020, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
* Copyright (c) 2020, 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
Expand Down Expand Up @@ -27,49 +27,48 @@ export class AuthenticateUtils {
* Private constructor to avoid object instantiation from outside
* the class.
*
* @hideconstructor
*/
// eslint-disable-next-line @typescript-eslint/no-empty-function
private constructor() {}

/**
* Checks if the logged in user has login scope.
*
* @return {boolean} True or false.
* @returns `boolean` True or false.
*/
public static hasLoginPermission(allowedScopes: string): boolean {
const scopes = allowedScopes?.split(" ");
const scopes: string[] = allowedScopes?.split(" ");

return scopes?.includes(TokenConstants.LOGIN_SCOPE);
}

/**
* Checks if the logged in user has a specific scope.
*
* @return {boolean} True or false.
* @returns `boolean` True or false.
*/
public static hasScope(scope: string, allowedScopes: string): boolean {
const scopes = allowedScopes?.split(" ");
const scopes: string[] = allowedScopes?.split(" ");

return scopes?.includes(scope);
}

/**
* Check if the logged in user has atleast one scope.
*
* @return {boolean} True or false.
* @returns `boolean` True or false.
*/
public static hasScopes(scope: string[], allowedScopes: string): boolean {
const userScopes: string[] = allowedScopes?.split(" ");

return scope.every(i => userScopes?.includes(i));
return scope.every((i:string) => userScopes?.includes(i));
}

/**
* Get the authentication callback URL from the session storage.
*
* @param {string} app - The name of the app.
* @return {string} Authentication Callback from session.
* @param app - `string` The name of the app.
* @returns Authentication Callback from session.
*/
public static getAuthenticationCallbackUrl(app: string): string {
return window.sessionStorage.getItem(`auth_callback_url_${app}`);
Expand All @@ -78,9 +77,9 @@ export class AuthenticateUtils {
/**
* Validates the authentication callback URL by checking if starts with the matcher value.
*
* @param {string} app - The name of the app.
* @param {string} matcher - Matcher value.
* @return {boolean} Authentication Callback from session.
* @param app - `string` The name of the app.
* @param matcher - `string` Matcher value.
* @returns `boolean` Authentication Callback from session.
*/
public static isValidAuthenticationCallbackUrl(app: string, matcher: string): boolean {

Expand All @@ -97,26 +96,26 @@ export class AuthenticateUtils {
* Update the authentication callback URL in the session storage.
* This is used to improve UX in automatic sign-out scenarios due to session timeouts etc.
*
* @param {string} app - The name of the app.
* @param {string} location - history path.
* @param app - `string` The name of the app.
* @param location - `string` history path.
*/
public static updateAuthenticationCallbackUrl(app: string, location: string): void {
window.sessionStorage.setItem(`auth_callback_url_${app}`, location);
}

/**
* @param {string} app - The name of the app.
* @param app - `string` The name of the app.
* Removes the authentication callback URL from the session storage.
*/
public static removeAuthenticationCallbackUrl(app: string): void {
window.sessionStorage.removeItem(`auth_callback_url_${app}`);
}

/**
/**
* Tenant domain decoded from the subject claim of the ID Token.
*
* @param {string} sub - Subject claim of the ID Token.
* @return {string} Tenant domain.
* @param sub - `string` Subject claim of the ID Token.
* @returns `string` Tenant domain.
*/
public static deriveTenantDomainFromSubject(sub: string): string {
const subParts: string[] = sub.split("@");
Expand All @@ -128,18 +127,18 @@ export class AuthenticateUtils {
/**
* Get sign in data of the user
*
* @param {BasicUserInfo} response - Sign in user data response
* @return {AuthenticatedUserInfo} Associated user's information
* @param response - `BasicUserInfo` Sign in user data response
* @returns `AuthenticatedUserInfo` Associated user's information
*/
public static getSignInState(response: BasicUserInfo): AuthenticatedUserInfo {
public static getSignInState(response: BasicUserInfo, tenantDomain?: string): AuthenticatedUserInfo {

return {
allowedScopes: response?.allowedScopes,
displayName: response?.displayName,
display_name: response?.displayName,
email: response?.email,
scope: response?.allowedScopes,
tenantDomain: AuthenticateUtils.deriveTenantDomainFromSubject(response?.sub) ,
tenantDomain: tenantDomain ? tenantDomain : AuthenticateUtils.deriveTenantDomainFromSubject(response?.sub),
username: response?.sub
};
}
Expand Down

0 comments on commit 57bd052

Please sign in to comment.