Skip to content

Commit 9169f46

Browse files
committed
Support a querystring to filter groups.
1 parent 3fd34c7 commit 9169f46

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

django_auth_adfs/backend.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@ def get_obo_access_token(self, access_token):
8888
logger.debug("Received OBO access token: %s", obo_access_token)
8989
return obo_access_token
9090

91+
def get_group_memberships_from_ms_graph_params(self):
92+
"""
93+
Return the parameters to be used in the querystring
94+
when fetching the user's group memberships.
95+
96+
Possible keys to be used:
97+
- $count
98+
- $expand
99+
- $filter
100+
- $orderby
101+
- $search
102+
- $select
103+
- $top
104+
105+
Docs:
106+
https://learn.microsoft.com/en-us/graph/api/group-list-transitivememberof?view=graph-rest-1.0&tabs=python#http-request
107+
"""
108+
return {}
109+
91110
def get_group_memberships_from_ms_graph(self, obo_access_token):
92111
"""
93112
Looks up a users group membership from the MS Graph API
@@ -105,6 +124,7 @@ def get_group_memberships_from_ms_graph(self, obo_access_token):
105124
response = self._ms_request(
106125
action=provider_config.session.get,
107126
url=graph_url,
127+
data=self.get_group_memberships_from_ms_graph_params(),
108128
headers=headers,
109129
)
110130
claim_groups = []

docs/settings_ref.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ GROUPS_CLAIM
244244
Name of the claim in the JWT access token from ADFS that contains the groups the user is member of.
245245
If an entry in this claim matches a group configured in Django, the user will join it automatically.
246246

247+
If using Azure AD and there are too many groups to fit in the JWT access token, the application will
248+
make a request to the Microsoft GraphQL API to find the groups. If you have many groups but only
249+
need a specific few, you can customize the request by overriding
250+
``AdfsBaseBackend.get_group_memberships_from_ms_graph_params`` and specifying the
251+
`OData query parameters <https://learn.microsoft.com/en-us/graph/api/group-list-transitivememberof?view=graph-rest-1.0&tabs=python#http-request>`_.
252+
247253
Set this setting to ``None`` to disable automatic group handling. The group memberships of the user
248254
will not be touched.
249255

0 commit comments

Comments
 (0)