Skip to content

Commit

Permalink
fix: allow schema introspection for unauthenticated users
Browse files Browse the repository at this point in the history
KK-1108
  • Loading branch information
nikomakela committed Aug 22, 2024
1 parent 501fb82 commit 2084067
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions kukkuu/graphene.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

from kukkuu.exceptions import AuthenticationExpiredError

SCHEMA_INTROSPECTION_OPERATION = "operation_definition"
SCHEMA_INTROSPECTION_OPERATION_NAME = "IntrospectionQuery"


# pretty much copied from https://github.com/City-of-Helsinki/open-city-profile/blob/4f46f9f9f195c4254f79f5dfbd97d03b7fa87a5b/open_city_profile/graphene.py#L18 # noqa
class JWTMiddleware:
Expand All @@ -11,6 +14,13 @@ def resolve(self, next, root, info, **kwargs):

auth_error = getattr(request, "auth_error", None)
if isinstance(auth_error, Exception):
# The GraphQL schema introspection can be allowed for unauthenticated users
if (
info.operation.kind == SCHEMA_INTROSPECTION_OPERATION
and info.operation.name.value == SCHEMA_INTROSPECTION_OPERATION_NAME
):
return next(root, info, **kwargs)

# TODO with the current version of django-helusers (v0.7.0) there is no
# proper way to catch only expired token errors, so this kind of hax is
# needed for that. If/when helusers offers a way to do this properly
Expand Down

0 comments on commit 2084067

Please sign in to comment.