Skip to content

Commit 99123cf

Browse files
committed
feat(oauth): add oidc groups scope
1 parent a134a18 commit 99123cf

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

intranet/apps/oauth/validators.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33

44
class IonOIDCValidator(OAuth2Validator):
5+
oidc_claim_scope = OAuth2Validator.oidc_claim_scope.copy()
6+
oidc_claim_scope.update({"groups": "groups"}) # manually add it since groups is not part of the standard OIDC spec
7+
58
def get_additional_claims(self, request):
69
claims = {}
710
user = request.user
@@ -24,4 +27,11 @@ def get_additional_claims(self, request):
2427
}
2528
)
2629

30+
if "groups" in request.scopes:
31+
claims.update(
32+
{
33+
"groups": list(user.groups.values_list("name", flat=True)),
34+
}
35+
)
36+
2737
return claims

intranet/settings/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,9 @@ def get_oidc_private_key():
648648
"email": (
649649
"Access your notification email using OpenID Connect. This is either your personal email or, if unset, your @tjhsst.edu email address."
650650
),
651+
"groups": (
652+
"Access groups you are in using OpenID Connect, such as your grade level."
653+
)
651654
},
652655
# OAuth refresh tokens expire in 30 days
653656
"REFRESH_TOKEN_EXPIRE_SECONDS": 60 * 60 * 24 * 30,

0 commit comments

Comments
 (0)