Skip to content

Commit 35e9811

Browse files
authored
Merge pull request #48 from alan-turing-institute/47-reduce-entra-verification-scope
Reduce entra verification scope
2 parents 2ed58aa + 4a0310a commit 35e9811

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

apricot/oauth/keycloak_client.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def __init__(
3333

3434
super().__init__(
3535
redirect_uri=redirect_uri,
36-
scopes=scopes,
36+
scopes_application=scopes,
37+
scopes_delegated=scopes,
3738
token_url=token_url,
3839
**kwargs,
3940
)

apricot/oauth/microsoft_entra_client.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ def __init__(
2323
@param entra_tenant_id: Tenant ID for the Entra ID
2424
"""
2525
redirect_uri = "urn:ietf:wg:oauth:2.0:oob" # this is the "no redirect" URL
26-
scopes = ["https://graph.microsoft.com/.default"] # this is the default scope
2726
token_url = (
2827
f"https://login.microsoftonline.com/{entra_tenant_id}/oauth2/v2.0/token"
2928
)
30-
self.tenant_id = entra_tenant_id
29+
# Use default application scope and minimal delegated scopes
3130
super().__init__(
3231
redirect_uri=redirect_uri,
33-
scopes=scopes,
32+
scopes_application=["https://graph.microsoft.com/.default"],
33+
scopes_delegated=["openid"],
3434
token_url=token_url,
3535
**kwargs,
3636
)

apricot/oauth/oauth_client.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def __init__(
2929
client_secret: str,
3030
debug: bool, # noqa: FBT001
3131
redirect_uri: str,
32-
scopes: list[str],
32+
scopes_application: list[str],
33+
scopes_delegated: list[str],
3334
token_url: str,
3435
uid_cache: UidCache,
3536
) -> None:
@@ -61,7 +62,7 @@ def __init__(
6162
self.session_application = OAuth2Session(
6263
client=BackendApplicationClient(
6364
client_id=client_id,
64-
scope=scopes,
65+
scope=scopes_application,
6566
redirect_uri=redirect_uri,
6667
),
6768
)
@@ -76,7 +77,7 @@ def __init__(
7677
self.session_interactive = OAuth2Session(
7778
client=LegacyApplicationClient(
7879
client_id=client_id,
79-
scope=scopes,
80+
scope=scopes_delegated,
8081
redirect_uri=redirect_uri,
8182
),
8283
)
@@ -180,7 +181,7 @@ def verify(self: Self, username: str, password: str) -> bool:
180181
client_secret=self.client_secret,
181182
)
182183
except InvalidGrantError as exc:
183-
log.msg(f"Authentication failed.\n{exc}")
184+
log.msg(f"Authentication failed for user '{username}'.\n{exc}")
184185
return False
185186
else:
186187
return True

0 commit comments

Comments
 (0)