Skip to content

Commit 23909aa

Browse files
committed
remove organization claim logging and add keycloak configuration guide
1 parent 1601010 commit 23909aa

2 files changed

Lines changed: 68 additions & 13 deletions

File tree

‎backend/api/context.py‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import logging
32
from typing import Any
43

54
import strawberry
@@ -82,19 +81,7 @@ async def get_context(
8281
email = user_payload.get("email")
8382
picture = user_payload.get("picture")
8483

85-
logger = logging.getLogger(__name__)
8684
organizations_raw = user_payload.get("organization")
87-
88-
if organizations_raw is None:
89-
scope = user_payload.get("scope", "")
90-
has_org_scope = "organization" in scope.split() if scope else False
91-
logger.warning(
92-
f"Organization claim not found in token for user {user_payload.get('sub', 'unknown')}. "
93-
f"Has organization scope: {has_org_scope}. "
94-
f"Token scope: {scope}. "
95-
f"Available claims: {sorted(user_payload.keys())}"
96-
)
97-
9885
organizations = None
9986
if organizations_raw:
10087
if isinstance(organizations_raw, list):

‎keycloak/README.md‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,73 @@ The realm includes:
2424
- Test user: `test` / `test`
2525
- Realm name: `tasks`
2626

27+
## Organization Configuration
28+
29+
The application uses an organization claim to associate users with organizations. This claim is included in access tokens and is used to determine which locations a user can access.
30+
31+
### Setting Up Organization Client Scope
32+
33+
The organization client scope should already be configured in the imported realm. To verify or configure it manually:
34+
35+
1. Navigate to **Client scopes** in the left sidebar
36+
2. Find the **organization** client scope
37+
3. Verify it has the following settings:
38+
- **Name**: `organization`
39+
- **Description**: "Additional claims about the organization a subject belongs to"
40+
- **Include in token scope**: Enabled
41+
- **Display on consent screen**: Enabled
42+
43+
4. Under **Mappers**, verify there is a mapper named **organization** with:
44+
- **Mapper Type**: User Attribute
45+
- **User Attribute**: `organization`
46+
- **Token Claim Name**: `organization`
47+
- **Claim JSON Type**: String
48+
- **Multivalued**: Enabled
49+
- **Add to access token**: Enabled
50+
- **Add to ID token**: Enabled
51+
- **Add to userinfo**: Enabled
52+
53+
### Adding Organization Scope to Clients
54+
55+
The organization scope should be included in the default client scopes for `tasks-backend`. To verify or configure:
56+
57+
1. Navigate to **Clients** in the left sidebar
58+
2. Select the **tasks-backend** client
59+
3. Go to the **Client scopes** tab
60+
4. Under **Default Client Scopes**, verify that **organization** is listed
61+
5. If not present, move it from **Optional Client Scopes** to **Default Client Scopes**
62+
63+
### Adding Users to Organizations
64+
65+
To assign a user to one or more organizations:
66+
67+
1. Navigate to **Users** in the left sidebar
68+
2. Select the user you want to configure (or create a new user)
69+
3. Go to the **Attributes** tab
70+
4. Click **Add** to add a new attribute
71+
5. Set the **Key** to: `organization`
72+
6. Set the **Value** to a comma-separated list of organization IDs (e.g., `test-org-1,test-org-2`)
73+
7. Click **Save**
74+
75+
**Note**: The organization attribute is multivalued, so you can add multiple values. Each value should be a single organization ID. For multiple organizations, add them as separate attribute entries or use a comma-separated string.
76+
77+
### Verifying Organization Claim in Tokens
78+
79+
To verify that the organization claim is being included in tokens:
80+
81+
1. Navigate to **Clients** → **tasks-backend** → **Client scopes** tab
82+
2. Ensure **organization** is in the **Default Client Scopes** list
83+
3. When a user authenticates, the access token should include an `organization` claim with the values from the user's `organization` attribute
84+
85+
### Realm-Level Default Client Scopes
86+
87+
To ensure the organization scope is available by default for all clients:
88+
89+
1. Navigate to **Client scopes** in the left sidebar
90+
2. Click on the **Default** tab at the top
91+
3. Verify that **organization** is listed in the **Default Default Client Scopes**
92+
4. If not, you can move it from **Optional** to **Default** using the arrow buttons
93+
2794
## Production
2895

2996
For production deployments, you should:
@@ -32,3 +99,4 @@ For production deployments, you should:
3299
3. Set up proper redirect URIs
33100
4. Configure SSL/TLS
34101
5. Review and adjust security settings
102+
6. Ensure organization attributes are properly configured for all users

0 commit comments

Comments
 (0)