Skip to content

Commit d98ca60

Browse files
author
ebagfey
committed
modified the process of fetching groups to send requests for them.
1 parent 96bef87 commit d98ca60

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

docs/web/authentication.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,11 @@ CodeChecker also supports OAuth-based authentication. The `authentication.method
374374

375375
* `user_emails_url`
376376

377-
The URL is used for making requests for emails associated with github account.
378-
This field only in relevant for github in current implementation.
377+
`GitHub` specific field to make requests for emails associated with github account.
378+
379+
* `user_groups_url`
380+
381+
`Microsoft` specific field to request security groups that the user is member of.
379382

380383
* `scope`
381384

@@ -424,7 +427,6 @@ providers' settings when issuing an OAuth application.
424427
* Important: At the time this code was written, GitHub doesn't support PKCE (Proof Key for Code Exchange).
425428
Therefore PKCE is not used when users log in using GitHub.
426429

427-
* Important: For the `Microsoft` provider, the `jwks_url` is used to fetch public keys that verify and decode the `id_token`. This token may include security groups, provided that Azure AD is configured to include groups as part of the token's optional claims.
428430

429431
# Client-side configuration <a name="client-side-configuration"></a>
430432

web/server/codechecker_server/api/authentication.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from authlib.integrations.requests_client import OAuth2Session
1515
from authlib.common.security import generate_token
1616
from authlib.oauth2.rfc7636 import create_s256_code_challenge
17-
from authlib.jose import JsonWebToken
1817

1918
from urllib.parse import urlparse, parse_qs
2019

@@ -379,15 +378,16 @@ def performLogin(self, auth_method, auth_string):
379378

380379
try:
381380
user_info = oauth2_session.get(user_info_url).json()
381+
# retrieve group memberships for Microsoft
382382
groups = []
383383
if provider == 'microsoft':
384-
id_token = oauth_token['id_token']
385-
jwks_url = oauth_config["jwks_url"]
386-
fetched_jwks = oauth2_session.get(jwks_url).json()
387-
jwt = JsonWebToken(['RS256'])
388-
claims = jwt.decode(id_token, fetched_jwks)
389-
claims.validate()
390-
groups = claims['groups']
384+
access_token = oauth_token['access_token']
385+
user_groups_url = oauth_config["user_groups_url"]
386+
response = oauth2_session.get(user_groups_url).json()
387+
for group in response["value"]:
388+
if group["onPremisesSyncEnabled"] and \
389+
group["securityEnabled"]:
390+
groups.append(group["displayName"])
391391
username = user_info[
392392
oauth_config["user_info_mapping"]["username"]]
393393
LOG.info("User info fetched, username: %s", username)

web/server/config/server_config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"authorization_url": "https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/authorize",
9292
"callback_url": "http://server_host/login/OAuthLogin/provider",
9393
"token_url": "https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/token",
94-
"jwks_url": "https://login.microsoftonline.com/{tenant-id}/discovery/v2.0/keys",
94+
"user_groups_url" : "https://graph.microsoft.com/v1.0/me/memberOf",
9595
"user_info_url": "https://graph.microsoft.com/v1.0/me",
9696
"scope": "User.Read email profile openid offline_access",
9797
"user_info_mapping": {

0 commit comments

Comments
 (0)