Skip to content

Commit 98e6d4a

Browse files
authored
refactor: refactor the organization experience docs (#1278)
* refactor: refactor the organization experience docs * chore: sync i18n translation and rewrite heading IDs * refactor: update index file and add a missing image
1 parent 073d1e1 commit 98e6d4a

File tree

97 files changed

+4510
-1922
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+4510
-1922
lines changed

docs/end-user-flows/organization-experience/README.mdx

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,77 @@ import OrganizationIcon from '@site/src/assets/organization.svg';
99

1010
# Organization experience
1111

12-
[Organization](/organizations) experience refers to the user interfaces and flows used by your business clients and their employees, particularly in [multi-tenant applications](https://auth.wiki/multi-tenancy). Logto provides several guides to help you quickly integrate this experience into your app using the Logto Management API.
12+
The [organization](/organizations) experience is the set of UIs and flows your business customers and their employees use—especially in [multi-tenant applications](https://auth.wiki/multi-tenancy). This guide shows how to integrate it into your app using the Logto Management API.
13+
14+
This section helps you design the **organization experience** for your end users—for example:
15+
16+
1. Admins can create their own organizations.
17+
2. Admins can manage organization members.
18+
3. Admins can invite members to join their organizations.
19+
4. and more.
1320

1421
<center>
1522
<img src="/img/assets/organization-experience.webp" width="100%" alt="Organization experience" />
1623
</center>
1724

18-
## Features for organization experience \{#features-for-organization-experience}
25+
## Understand the authentication flow \{#understand-the-authentication-flow}
26+
27+
```mermaid
28+
sequenceDiagram
29+
actor User
30+
participant Frontend
31+
participant Backend
32+
participant Logto
33+
34+
User->>Frontend: Request to create organization
35+
Frontend->>Backend: POST /organizations
36+
Backend->>Logto: POST /api/organizations
37+
Logto-->>Backend: Organization created
38+
Backend->>Logto: POST /api/organizations/{id}/users
39+
Logto-->>Backend: User added to organization
40+
Backend-->>Frontend: Success response
41+
Frontend-->>User: Show success message
42+
```
43+
44+
To integrate with the Logto Management API, first understand the basic authentication flow. It has two key requirements:
45+
46+
### Protect your backend API \{#protect-your-backend-api}
47+
48+
- Frontend calls to your backend API require authentication.
49+
- Protect API endpoints by validating the user's Logto access token.
50+
- Ensure only authenticated users can access your services.
51+
52+
### Access the Logto Management API \{#access-the-logto-management-api}
53+
54+
- Your backend service securely calls the Logto Management API.
55+
- Follow the [Interact with Management API](/integrate-logto/interact-with-management-api) guide for setup.
56+
- Use machine-to-machine authentication to obtain access credentials.
57+
58+
The next few chapters explain how to set up the Logto Management API and walk through common use cases for building your organization experience.
59+
60+
## Organization experience features \{#features-for-organization-experience}
1961

2062
<DocCardList
2163
items={[
64+
{
65+
type: 'link',
66+
label: 'Define organization management features',
67+
href: '/end-user-flows/organization-experience/organization-management',
68+
description: 'Design your own multi-tenant app with organization roles and permissions.',
69+
customProps: {
70+
icon: <OrganizationIcon />,
71+
},
72+
},
73+
{
74+
type: 'link',
75+
label: 'Set up your app service with the Logto Management API',
76+
href: '/end-user-flows/organization-experience/setup-app-service-with-management-api',
77+
description:
78+
'Securely connect your backend to Logto Management API using machine-to-machine authentication.',
79+
customProps: {
80+
icon: <GearIcon />,
81+
},
82+
},
2283
{
2384
type: 'link',
2485
label: 'Create organization',
@@ -31,27 +92,54 @@ import OrganizationIcon from '@site/src/assets/organization.svg';
3192
},
3293
{
3394
type: 'link',
34-
label: 'Invite members to organization',
35-
href: '/end-user-flows/organization-experience/invite-organization-members',
36-
description:
37-
'Use Logto Management API to let organization admins invite members to their organizations.',
95+
label: 'Get user info within an organization',
96+
href: '/end-user-flows/organization-experience/get-user-info',
97+
description: 'Fetch user information within an organization.',
3898
customProps: {
3999
icon: <OrganizationIcon />,
40100
},
41101
},
42102
{
43103
type: 'link',
44-
label: 'Organization management',
45-
href: '/end-user-flows/organization-experience/organization-management',
46-
description:
47-
'Use Logto Management API to let organization admins manage their members inside the organization.',
104+
label: 'Organization switcher',
105+
href: '/end-user-flows/organization-experience/organization-switcher',
106+
description: 'Implement organization switching in your app.',
107+
customProps: {
108+
icon: <GearIcon />,
109+
},
110+
},
111+
{
112+
type: 'link',
113+
label: 'Invite organization members',
114+
href: '/end-user-flows/organization-experience/invite-organization-members',
115+
description: 'Use Logto Management API to implement organization invitations.',
116+
customProps: {
117+
icon: <GearIcon />,
118+
},
119+
},
120+
{
121+
type: 'link',
122+
label: 'Join the organization',
123+
href: '/end-user-flows/organization-experience/join-the-organization',
124+
description: 'Implement the joining organization flows in your app.',
125+
customProps: {
126+
icon: <GearIcon />,
127+
},
128+
},
129+
{
130+
type: 'link',
131+
label: 'Permission and resource management',
132+
href: '/end-user-flows/organization-experience/permission-and-resource-management',
133+
description: 'Manage permissions and resources within an organization',
48134
customProps: {
49135
icon: <GearIcon />,
50136
},
51137
},
52138
]}
53139
/>
54140

141+
For a detailed explanation of organization definitions, member concepts, and organization templates, see [Understand how organizations work](/organizations/understand-how-organizations-work).
142+
55143
## Related resources \{#related-resources}
56144

57145
<Url href="https://blog.logto.io/build-multi-tenant-saas-application">
Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
---
2-
sidebar_position: 1
2+
sidebar_position: 3
33
---
44

55
# Create organization
66

7-
Imagine you are building a [multi-tenant app](https://auth.wiki/multi-tenancy) (e.g., multi-tenant SaaS app) that servers numerous customers, and each customer owns a dedicated tenant. When a new customer arrives, they create a new account, as well as a new tenant for their own business.
7+
Imagine you’re building a [multi-tenant app](https://auth.wiki/multi-tenancy) (e.g., a multi-tenant SaaS app) that serves many customers, and each customer owns a dedicated tenant.
88

9-
Just like how you registered your [Logto Cloud](https://cloud.logto.io/) account and have your own Logto tenant. You can implement the very same architecture in your app as well, using Logto's "[organization](/organizations)" feature.
9+
Organizations are typically created when:
1010

11-
## Create your organizations \{#create-your-organizations}
11+
1. New customers sign up and create both an account and a tenant for their business.
12+
2. Existing users can create a new organization from within the app.
13+
14+
<img src="/img/assets/new-account-creates-org.png" alt="New account creates organization" />
15+
<img src="/img/assets/existing-user-creates-org.png" alt="Existing user creates organization" />
16+
17+
## Implement organization creation \{#implement-organization-creation}
1218

1319
There are two ways to create organizations for your app.
1420

1521
### Create via Logto Console \{#create-via-logto-console}
1622

17-
Manually create your organizations through Logto Console UI. Go to <CloudLink to="/organizations">Console > Organizations</CloudLink> to create organization, assign members and roles, and customize organization sign-in experience UI.
23+
Manually create organizations in the Logto Console UI. Go to <CloudLink to="/organizations">Console > Organizations</CloudLink> to create organizations, assign members and roles, and customize the organization signin experience.
1824

19-
Create an "[organization template](/authorization/organization-template)" if you want to batch create similar organizations that share the same role and permission settings.
25+
Create an [organization template](/authorization/organization-template) to batchcreate similar organizations that share the same roles and permissions.
2026

2127
### Create via Logto Management API \{#create-via-logto-management-api}
2228

23-
Clicking buttons on the Console UI works great, but we really want to have the end-users self-serve and create organizations, manage the organizations themselves In **YOUR App**. Thus, you’ll have to implement these features in your app, with the help of Logto Management API.
29+
The Console is great for manual setup, but most apps let end users selfserve—create and manage organizations directly in your app. To do that, implement these features with the Logto Management API.
2430

2531
:::note
2632

27-
If you are not familiar with Logto Management API, please make sure you read these docs first.
33+
If you’re new to the Logto Management API, read these first:
2834

2935
<Url href="/concepts/core-service/#management-api">Management API</Url>
3036
<Url href="/integrate-logto/interact-with-management-api">Interact with Management API</Url>
3137

3238
:::
3339

34-
Assuming you have already connected your API backend server to Logto Management API endpoint through the Machine-to-Machine (M2M) mechanism, and acquired the M2M access token.
40+
Assume your backend is connected to the Logto Management API via the machine‑to‑machine (M2M) mechanism, and you’ve obtained an M2M access token.
3541

3642
Create an organization with Management API ([API references](https://openapi.logto.io/operation/operation-createorganization)):
3743

@@ -43,30 +49,24 @@ curl \
4349
-d '{"tenantId":"string","name":"string","description":"string","customData":{},"isMfaRequired":false,"branding":{"logoUrl":"string","darkLogoUrl":"string","favicon":"string","darkFavicon":"string"},"createdAt":1234567890}'
4450
```
4551

46-
Response example (201)
47-
48-
```json
49-
{
50-
"tenantId": "string",
51-
"id": "string",
52-
"name": "string",
53-
"description": "string",
54-
"customData": {},
55-
"isMfaRequired": false,
56-
"branding": {
57-
"logoUrl": "string",
58-
"darkLogoUrl": "string",
59-
"favicon": "string",
60-
"darkFavicon": "string"
61-
},
62-
"createdAt": 1234567890
63-
}
52+
Then add the user as a member of the organization ([API reference](https://openapi.logto.io/operation/operation-addorganizationusers)):
53+
54+
```bash
55+
curl \
56+
-X POST https://[tenant_id].logto.app/api/organizations/{id}/users \
57+
-H "Authorization: Bearer $M2M_ACCESS_TOKEN" \
58+
-H "Content-Type: application/json" \
59+
-d '{"userIds":["string"]}'
6460
```
6561

66-
Next, you can implement your own API for your app. So when your users perform the "create organization" action in your app, you can validate the request by checking their permissions, and then call Logto Management API to do the rest of the job.
62+
Optionally, assign specific organization roles to the user ([API reference](https://openapi.logto.io/operation/operation-assignorganizationrolestousers)).
63+
64+
Check the [full API specs](https://openapi.logto.io/group/endpoint-organizations) for more details.
65+
66+
Wrap these calls in your own API layer. When users perform the “create organization” action in your app, validate the request by checking their permissions, then call the Logto Management API to complete the operation.
6767

68-
## Validating organization token in user request \{#validating-organization-token-in-user-request}
68+
## Validate the organization token in user requests \{#validating-organization-token-in-user-request}
6969

70-
In your app, when users perform actions in the context of an organization, they need to use the organization token instead of the regular access token. The organization token is a special kind of [JWT](https://auth.wiki/jwt) that contains organization permissions. And just like any JWT [access tokens](https://auth.wiki/access-token), you can decode the token claims and verify the "scope" claim for permission check.
70+
In your app, when users perform actions in the context of an organization, they must use an organization token instead of a regular access token. The organization token is a [JWT](https://auth.wiki/jwt) that contains organization permissions. Like any [access token](https://auth.wiki/access-token), you can decode the claims and verify the "scope" claim to enforce permissions.
7171

72-
See <Url href="/authorization">Authorization</Url> for more details about authorization scenarios and how to validate organization tokens.
72+
See <Url href="/authorization">Authorization</Url> for more on authorization scenarios and how to validate organization tokens.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
sidebar_position: 4
3+
---
4+
5+
# Get user info within an organization
6+
7+
## Where to use it \{#where-to-use-it}
8+
9+
This is usually used in the user profile page where users need to show their organization information.
10+
11+
<img src="/img/assets/user-info-page.png" alt="Organization user info" />
12+
13+
## How to implement it \{#how-to-implement-it}
14+
15+
There are two ways to get user info within an organization.
16+
17+
### 1. Decode the ID token \{#1-decode-the-id-token}
18+
19+
The ID token is a standard JWT that contains user profile information and organization‑related claims. Call the SDK method `decodeIdToken()` to get a JSON object like this:
20+
21+
```json
22+
{
23+
"sub": "aauqbb63vg4s",
24+
"name": "John Doe",
25+
"picture": "https://example.com/johndoe.png",
26+
"email": "johndoe@example.com",
27+
// ...
28+
"organizations": [
29+
"organization-id-1",
30+
"organization-id-2",
31+
"organization-id-3"
32+
// ...
33+
],
34+
"organization_roles": [
35+
"organization-id-1:admin",
36+
"organization-id-2:member",
37+
"organization-id-3:viewer"
38+
// ...
39+
],
40+
"aud": "admin-console"
41+
// ...
42+
}
43+
```
44+
45+
However, the ID token is only issued during authentication and may become stale if the user profile changes afterward.
46+
For the most up‑to‑date info, use the second approach below, or call `clearAllTokens()` and re‑initiate an authentication flow to get a fresh ID token.
47+
48+
```ts
49+
await logtoClient.clearAllTokens();
50+
logtoClient.signIn({
51+
redirectUri: 'https://your-app.com/callback',
52+
prompt: 'consent',
53+
});
54+
```
55+
56+
If the session is still valid, the `signIn` call will redirect back to your app without requiring credentials. From the user’s perspective, the app simply refreshes and a new ID token is issued behind the scenes.
57+
58+
### 2. Fetch user info from the `/oidc/me` endpoint \{#2-fetch-user-info-from-the-oidc-me-endpoint}
59+
60+
You can also request `/oidc/me` to get real‑time user info in the organization context. Call the SDK method `fetchUserInfo()`.

0 commit comments

Comments
 (0)