Closed (fixed)
Project:
Simple OAuth (OAuth2) & OpenID Connect
Version:
5.2.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
23 Sep 2019 at 05:11 UTC
Updated:
14 Jan 2025 at 13:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
e0ipsoComment #3
gueguerreiroFrom what I understand, these error logs come from
SimpleOauthAuthenticationProvider'sauthenticate()function.The
validateAuthenticatedRequest()function from League's Oauth2 package, at least on version 7.1, which is the one this module is using, will always throw anOAuthServerException::accessDenied()exception:And
validateAuthorization():With that being the case, it seems that these can be reduced to a notice log instead? Some of those messages could still prove useful for debugging, so I don't think the logging should be outright removed.
Let me know if my assumptions are correct here. I'm providing a patch with the change to a notice level log for now. It should apply on both the 8.x-3.x and 8.x-4.x branches, as the class was unaffected by the sub-module merge.
Comment #4
bradjones1Comment #5
rachel_norfolkretagging
Comment #6
matt_paz commentedAdding tangentially related issue ...
https://www.drupal.org/project/simple_oauth/issues/3143809
Comment #7
segi commentedMy solution is much more simple maybe isn't enough but we are using in our project, maybe it would be useful to someone.
Comment #8
segi commentedComment #9
matt_paz commentedThe technique used by @segi is interesting and something I think we should consider/evaluate. One thing that was nice about the other patch by @gueguerreiro was that it removed the procedural code logging as well, which might be advantageous?
Comment #10
bradjones13.x is no longer supported, needs to reroll/rebase against 5.x.
Comment #11
bradjones1Definitely all for removing functional calls to the logger.
Comment #12
simonbaeseThe following patch does:
- Injects the (new) simple_oauth logger channel.
- Logs a notice with the message and hint from the
OAuthServerException.- Throws a
UnauthorizedHttpException, which provides aWWW-Authenticatechallenge for the requester (e.g. frontend).- Catches the exception and forwards the response with the (new) event subscriber
UnauthorizedExceptionSubscriberbefore Drupal logging is triggered.- Adjust the unit test for the
SimpleOauthAuthenticationProviderOut of the scope of this issue:
- Replaces
watchdog_exception()calls throughout the module with the injections of the simple_oauth logger channel.Some thoughts:
Intercepting the authentication with an exception is actually a smart way to provide some information to the user, but we should decide where to direct this information. In my opinion it is more important to let the frontend know, that the authentication failed. Hence, I introduced the new header in the response. Further, the Drupal log should not be flooded with exceptions, if we are already passing on the notice. Introducing an event subscriber might be overkill - but we throw the exception in the first place and should also handle it.
Further, we should really consider, if logging a notice in the backend is really necessary. I can see that it might has some benefit when debugging, but in production it does not really hold any value. Maybe, we could even introduce a setting.
Comment #13
simonbaeseAfter further inspection, I think it would also be good to handle exceptions thrown by the
OAuthTokencontroller (see line 83).But, by now, I am convinced, it would be nice to have an adapter for the
OAuthServerExceptionto handle the errors comprehensively. I will give it a shot, when there is some time.Comment #14
bradjones1Rebased #12 on 5.2.x and switched to MR workflow.
Comment #15
bradjones1Comment #17
bradjones1Made a few changes, including renaming the logger service to fit the usual convention, and also removing the proposed EventSubscriber in favor of decorating core's exception logging subscriber. Main reason is that we don't want to be responsible for setting the response, particularly since core does/can do things like content-type negotiation for the payload.
Another reason for #3304981: JSON and other serialization formats now handle non-4xx exceptions in core (but this is not dependent on that patch.)
Comment #18
bradjones1Missed https://git.drupalcode.org/project/simple_oauth/-/blob/657af9ec51b86cd4a...
Comment #19
bradjones1Comment #20
segi commentedI re-rolled my patch if somebody use it. I have check the MR and it looks promising and it covers my little "fix" as well.
Update: This patch contains a bug. I forgot to include the RfcLogLevel class. I don't upload the new version because it's just confusing who see the issue first time.
Comment #21
bradjones1Thanks, although to be clear the MR is the code that is under review, the patch is outdated and is not the subject of the issue any longer.
Comment #22
Arnaud Kali commented@bradjones1 I don't seem to be able to review/test that patch from #12. I cant apply the patch to 5.2.x either as the code seems to be outdated. I'm seeing the merge request and actually needing it on one of my projects, I'd guess it's about to be merged and released?
Comment #23
bradjones1Yes, I'd consider that patch to be outdated so I can't help you here and not sure why you're trying to apply it.
It will get released when it gets to RTBC, so I welcome the effort to review it. Feel free to apply the diff from the MR to your project and tell me how it goes. The fact it's an MR doesn't mean anything regarding its timeline to release. Patches are going away imminently on drupal.org, anyway.
Comment #24
Arnaud Kali commentedThanks for your comment @bradjones1 - Even if I kinda know after I've been around on d.o for such a long time, I'm just never sure about the way to proceed. I'm re-rolling the patch against 5.2.x as I need an online link to be able to test on my platform (which already has an online API from which I need to test that code).
Thanks! I'll keep you informed of my findings.
Comment #25
Arnaud Kali commentedMissed including new files. Re-renerating the patch.
Comment #27
trevorbradley commentedAdding a request to also look at this issue for the new 6.x branch.
Would love to have a little more control over the >3,000 daily simple_oauth errors in the logs on our high volume site.
Comment #30
dieterholvoet commentedI created a MR based on 6.0.x.
Comment #32
bojan_dev commentedPlease address the phpcs issues on the MR.
Comment #33
dieterholvoet commentedDone!
Comment #35
bojan_dev commentedComment #36
bojan_dev commented