diff --git a/b2b-sample/README.md b/b2b-sample/README.md index da86d7444..1c9c2b625 100644 --- a/b2b-sample/README.md +++ b/b2b-sample/README.md @@ -60,11 +60,11 @@ Also, On the User Attributes tab, click on + Add User Attributes. Select `Email`, `First Name`, `Last Name`, and `Username` from the list of attributes. #### Step 2.2: In the Guardio-Admin-App ->| Property | Value/s | +>| Property | Value/s | >|--------------------------|:----------------------------------------------------------------------------:| ->| Allowed Grant types | `Organization Switch`, `Code` | +>| Allowed Grant types | `Code` | >| Authorized redirect URLs | `http://localhost:3001/api/auth/callback/wso2isAdmin` and `http://localhost:3001` | ->| Allowed origin | `http://localhost:3001` | +>| Allowed origin | `http://localhost:3001` | ### Step 3: Create a user and assign roles You need to create new users on the sub-organizations with the required permissions. diff --git a/b2b-sample/apps/business-admin-app/pages/api/auth/[...nextauth].ts b/b2b-sample/apps/business-admin-app/pages/api/auth/[...nextauth].ts index 475366689..c656a5796 100644 --- a/b2b-sample/apps/business-admin-app/pages/api/auth/[...nextauth].ts +++ b/b2b-sample/apps/business-admin-app/pages/api/auth/[...nextauth].ts @@ -51,23 +51,18 @@ const wso2ISProvider = (req: NextApiRequest, res: NextApiResponse) => NextAuth(r return `${baseUrl}/o/moveOrg`; }, async session({ session, token }) { - const orgSession = await controllerDecodeSwitchOrg(token); - if (!orgSession) { + if (!session) { session.error = true; - } else if (orgSession.expires_in <= 0) { - session.expires = true; - } - else { - session.accessToken = orgSession.access_token; - session.idToken = orgSession.id_token; - session.scope = orgSession.scope; - session.refreshToken = orgSession.refresh_token; + } else { + session.error = false; session.expires = false; - session.userId = getLoggedUserId(session.idToken); + session.accessToken = token.accessToken; + session.scope = token.scope; + //session.userId = getLoggedUserId(session.idToken); session.user = getLoggedUserFromProfile(token.user); - session.orgId = getOrgId(session.idToken); - session.orgName = getOrgName(session.idToken); + session.orgId = token.user.org_id; + session.orgName = token.user.org_name; session.orginalIdToken = token.idToken; } diff --git a/b2b-sample/config.json b/b2b-sample/config.json index d14c794cd..ab4bd5bd0 100644 --- a/b2b-sample/config.json +++ b/b2b-sample/config.json @@ -2,14 +2,6 @@ "CommonConfig": { "AuthorizationConfig": { "BaseOrganizationUrl": " ex: https://api.asgardeo.io/t/guardio" - }, - "ApplicationConfig": { - "SampleOrganization": [ - { - "id": "", - "name": "" - } - ] } }, "BusinessAppConfig": { diff --git a/b2b-sample/libs/business-app/data-access/data-access-controller/src/lib/controller/controllerSwitchOrg/controllerDecodeSwitchOrg.ts b/b2b-sample/libs/business-app/data-access/data-access-controller/src/lib/controller/controllerSwitchOrg/controllerDecodeSwitchOrg.ts index d61697909..c4a89d87d 100644 --- a/b2b-sample/libs/business-app/data-access/data-access-controller/src/lib/controller/controllerSwitchOrg/controllerDecodeSwitchOrg.ts +++ b/b2b-sample/libs/business-app/data-access/data-access-controller/src/lib/controller/controllerSwitchOrg/controllerDecodeSwitchOrg.ts @@ -25,16 +25,13 @@ import config from "../../../../../../../../config.json"; function getOrgId(token: JWT): string { if (token.user) { - if (token.user.user_organization) { - - return token.user.user_organization; - } else if (config.CommonConfig.ApplicationConfig.SampleOrganization[0]) { - - return config.CommonConfig.ApplicationConfig.SampleOrganization[0].id; - } else { + if (token.user.org_id) { return token.user.org_id; - } + } + + return config.CommonConfig.ApplicationConfig.SampleOrganization[0].id; + } else { return config.CommonConfig.ApplicationConfig.SampleOrganization[0].id;