Skip to content

Commit

Permalink
logging
Browse files Browse the repository at this point in the history
  • Loading branch information
pakelley committed Feb 21, 2025
1 parent aa60baa commit 18a8000
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions label_studio/jwt_auth/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ def __call__(self, request):
JWT_ACCESS_TOKEN_ENABLED = flag_set('fflag__feature_develop__prompts__dia_1829_jwt_token_auth')
logger.debug('JWT call')
if JWT_ACCESS_TOKEN_ENABLED:
logger.debug('JWT enabled')
logger.warning('JWT enabled')
try:
logger.debug('JWT attempt')
user_and_token = JWTAuthentication().authenticate(request)
if not user_and_token:
logger.debug('JWT auth could not resolve user/token')
logger.warning('JWT auth could not resolve user/token')
return self.get_response(request)

user = User.objects.get(pk=user_and_token[0].pk)
if user.active_organization.jwt.api_tokens_enabled:
logger.debug('JWT auth resolved user/token')
logger.warning('JWT auth resolved user/token')
request.user = user
request.is_jwt = True
else:
logger.debug('JWT auth resolved user/token, but org does not have jwt enabled')
logger.warning('JWT auth resolved user/token, but org does not have jwt enabled')

except User.DoesNotExist:
logger.info('JWT authentication failed: User no longer exists')
logger.warning('JWT authentication failed: User no longer exists')

Check warning on line 41 in label_studio/jwt_auth/middleware.py

View check run for this annotation

Codecov / codecov/patch

label_studio/jwt_auth/middleware.py#L41

Added line #L41 was not covered by tests
return JsonResponse({'detail': 'User not found'}, status=status.HTTP_401_UNAUTHORIZED)
except (AuthenticationFailed, InvalidToken, TokenError) as e:
logger.info('JWT authentication failed: %s', e)
logger.warning('JWT authentication failed: %s', e)
# don't raise 401 here, fallback to other auth methods (in case token is valid for them)
# (have unit tests verifying that this still results in a 401 if other auth mechanisms fail)
return self.get_response(request)

0 comments on commit 18a8000

Please sign in to comment.