Skip to content

Commit 5d590b6

Browse files
committed
Change Graphql Query auth method to QUERY
1 parent fca1c3f commit 5d590b6

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

oauth2_lib/fastapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def __init__(self, opa_url: str, auto_error: bool = False, opa_kwargs: Mapping[s
366366
# By default don't raise HTTP 403 because partial results are preferred
367367
super().__init__(opa_url, auto_error, opa_kwargs)
368368

369-
async def authorize(self, request: RequestPath, user_info: OIDCUserModel) -> bool | None:
369+
async def authorize(self, request: RequestPath, method: str, user_info: OIDCUserModel) -> bool | None:
370370
if not (oauth2lib_settings.OAUTH2_ACTIVE and oauth2lib_settings.OAUTH2_AUTHORIZATION_ACTIVE):
371371
return None
372372

@@ -375,7 +375,7 @@ async def authorize(self, request: RequestPath, user_info: OIDCUserModel) -> boo
375375
**(self.opa_kwargs or {}),
376376
**(user_info or {}),
377377
"resource": request,
378-
"method": "POST",
378+
"method": method,
379379
}
380380
}
381381

oauth2_lib/strawberry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ async def is_authenticated(info: OauthInfo) -> bool:
105105
return current_user is not None
106106

107107

108-
async def is_authorized(info: OauthInfo, path: str) -> bool:
108+
async def is_authorized(info: OauthInfo, path: str, method: str) -> bool:
109109
"""Check that the user is allowed to query/mutate this path."""
110110
context = info.context
111111
current_user = await context.get_current_user
112112
if not current_user:
113113
return False
114114

115-
authorization_decision = await context.auth_manager.graphql_authorization.authorize(path, current_user)
115+
authorization_decision = await context.auth_manager.graphql_authorization.authorize(path, method, current_user)
116116
authorized = bool(authorization_decision)
117117
logger.debug(
118118
"Received graphql authorization decision",
@@ -172,7 +172,7 @@ async def has_permission(self, source: Any, info: OauthInfo, **kwargs) -> bool:
172172
return True
173173

174174
path = get_query_path(info)
175-
if await is_authorized(info, path):
175+
if await is_authorized(info, path, "QUERY"):
176176
return True
177177

178178
self.message = f"User is not authorized to query `{path}`"
@@ -192,7 +192,7 @@ async def has_permission(self, source: Any, info: OauthInfo, **kwargs) -> bool:
192192
return skip_mutation_auth_checks()
193193

194194
path = get_mutation_path(info)
195-
if await is_authorized(info, path):
195+
if await is_authorized(info, path, "POST"):
196196
return True
197197

198198
self.message = f"User is not authorized to execute mutation `{path}`"

0 commit comments

Comments
 (0)