-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make User.from_token
robust to invalid token
#337
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previously, when an API request was made using an expired or invalid access token, a `Faraday::UnauthorizedError` was raised and the request failed. Recently we've seen a bunch of these exceptions happening due to some other problems in editor-standalone and/or in the editor-ui web component - see this issue [1] for more details. Failing hard with an exception like this seems a bit over the top when the user is trying to view a public project for which they don't need to be logged-in. And it seems as if `User.from_token` might have been expecting `HydraPublicApiClient.fetch_oauth_user` to return `nil` when the token was invalid [2]. This commit rescues the `Faraday::UnauthorizedError` exception, captures the exception in Sentry in case we want to know about it, but then returns `nil`. This means that if the user is trying to carry out an action that does not require them to be logged-in, they can still do so despite their access token not being valid. [1]: RaspberryPiFoundation/editor-ui#1044 [2]: https://github.com/RaspberryPiFoundation/editor-api/blob/055741503b0ad295e44993c9f55b2fc95e912beb/app/models/user.rb#L91
raspberrypiherokubot
temporarily deployed
to
editor-api-p-make-user--pirhik
June 19, 2024 16:06
Inactive
sra405
approved these changes
Jun 19, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 nice!
floehopper
added a commit
to RaspberryPiFoundation/editor-ui
that referenced
this pull request
Jun 20, 2024
This reverts commit eac96dd. The problem that this fix was addressing has been more effectively addressed in this editor-api PR [1]. [1]: RaspberryPiFoundation/editor-api#337.
floehopper
added a commit
to RaspberryPiFoundation/editor-ui
that referenced
this pull request
Jun 20, 2024
This reverts commit 4be26c8. This was in preparation for fixing a problem that has now been more effectively addressed in this editor-api PR [1]. [1]: RaspberryPiFoundation/editor-api#337.
floehopper
added a commit
to RaspberryPiFoundation/editor-ui
that referenced
this pull request
Jun 20, 2024
This reverts commit eac96dd. This commit was part of #1046. The problem that this fix was addressing has been more effectively addressed in this editor-api PR [1]. [1]: RaspberryPiFoundation/editor-api#337.
floehopper
added a commit
to RaspberryPiFoundation/editor-ui
that referenced
this pull request
Jun 20, 2024
This reverts commit 4be26c8. This commit was part of #1046. This was in preparation for fixing a problem that has now been more effectively addressed in this editor-api PR [1]. [1]: RaspberryPiFoundation/editor-api#337.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, when an API request was made using an expired or invalid access token, a
Faraday::UnauthorizedError
was raised and the request failed.Recently we've seen a bunch of these exceptions happening due to some other problems in editor-standalone and/or in the editor-ui web component - see this issue for more details.
Failing hard with an exception like this seems a bit over the top when the user is trying to view a public project for which they don't need to be logged-in. And it seems as if
User.from_token
might have been expectingHydraPublicApiClient.fetch_oauth_user
to returnnil
when the token was invalid when in fact it returns a401 Unauthorized
HTTP status code which results in aFaraday::UnauthorizedError
exception being raised.This commit rescues the
Faraday::UnauthorizedError
exception, captures the exception in Sentry in case we want to know about it, but then returnsnil
. This means that if the user is trying to carry out an action that does not require them to be logged-in, they can still do so despite their access token not being valid.