Skip to content

Commit

Permalink
B2B sample app improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sadilchamishka committed Oct 26, 2023
1 parent bbe3551 commit ec0911f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 32 deletions.
6 changes: 3 additions & 3 deletions b2b-sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 8 additions & 13 deletions b2b-sample/apps/business-admin-app/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 0 additions & 8 deletions b2b-sample/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
"CommonConfig": {
"AuthorizationConfig": {
"BaseOrganizationUrl": "<PARENT ORGANIZATION URL> ex: https://api.asgardeo.io/t/guardio"
},
"ApplicationConfig": {
"SampleOrganization": [
{
"id": "<SUB ORGANIZATION ID>",
"name": "<SUB ORGANIZATION NAME>"
}
]
}
},
"BusinessAppConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ec0911f

Please sign in to comment.