You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/database-management/authentication-and-authorization/auth-system-integrations.mdx
+66-6Lines changed: 66 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ privileges will still apply but you won't be able to manage them.
27
27
### Roles
28
28
29
29
User roles must be defined in Memgraph before using auth modules because these
30
-
modules return the role associated with the user.
30
+
modules return the role(s) associated with the user. Memgraph now supports multiple roles per user, allowing auth modules to return either a single role or multiple roles.
31
31
32
32
### Flags
33
33
@@ -85,8 +85,9 @@ The protocol used between Memgraph and the module is as follows:
85
85
- Auth responses must be objects that contain the following fields:
86
86
-`authenticated` - a `bool` indicating whether the user is allowed to log
87
87
in to the database
88
-
-`role` - a `string` indicating which role the user should have (must be
89
-
supplied)
88
+
-`role` - a `string` indicating which role the user should have (backward compatible)
89
+
-`roles` - an array of strings indicating which roles the user should have (new format)
90
+
-`username` - the user's username (optional, can be derived from auth token)
90
91
-`errors` (optional) - if `authenticated` is false, Memgraph will put up a
91
92
warning with the error message returned by the module
92
93
@@ -95,6 +96,53 @@ Memgraph won't allow the user to log in to the database and will automatically
95
96
restart the auth module for the next auth request. All crash logs will be seen
96
97
in Memgraph's output (typically in `systemd` logs using `journalctl`).
97
98
99
+
### Multiple roles support
100
+
101
+
Memgraph now supports multiple roles per user in auth module responses. Auth modules can return either a single role (backward compatible) or multiple roles (new format).
102
+
103
+
#### Single role response (backward compatible)
104
+
105
+
```python
106
+
defauthenticate(username, password):
107
+
return {
108
+
"authenticated": True,
109
+
"role": "moderator"# Single role as string
110
+
}
111
+
```
112
+
113
+
#### Multiple roles response (new format)
114
+
115
+
```python
116
+
defauthenticate(username, password):
117
+
return {
118
+
"authenticated": True,
119
+
"roles": ["admin", "user"] # Multiple roles as array
120
+
}
121
+
```
122
+
123
+
#### Single role in array format
124
+
125
+
```python
126
+
defauthenticate(username, password):
127
+
return {
128
+
"authenticated": True,
129
+
"roles": ["admin"] # Single role in array
130
+
}
131
+
```
132
+
133
+
The system will:
134
+
1. First check for a `roles` field in the response
135
+
2. If `roles` is an array, use all roles in the array
136
+
3. If `roles` is a string, use it as a single role
137
+
4. If no `roles` field is found, fall back to the `role` field for backward compatibility
138
+
5. If no valid roles are found, authentication fails
139
+
140
+
When a user has multiple roles, their permissions are combined using the following rules:
141
+
-**Grants**: If any role grants a permission, the user has that permission
142
+
-**Denies**: If any role denies a permission, the user is denied that permission
143
+
-**Database Access**: If any role grants access to a database, the user has access
144
+
-**Fine-grained Permissions**: Combined using the same grant/deny logic
145
+
98
146
### Module example
99
147
100
148
This very simple example auth module is written in Python, but any programming
@@ -163,6 +219,10 @@ created in the Memgraph DB beforehand. Additionally, you have to grant [label-ba
163
219
164
220
</Callout>
165
221
222
+
<Callouttype="info">
223
+
SSO identity providers often return multiple roles for users. Memgraph now supports this natively - if your identity provider returns multiple roles, they will all be mapped to Memgraph roles and the user will have permissions from all assigned roles combined.
224
+
</Callout>
225
+
166
226
### SAML
167
227
168
228
Memgraph has built-in support for single sign-on (SSO) over the SAML protocol
0 commit comments