Repository navigation
Handle unexpected ORCID token replies instead of returning a 500 - #2899
Open
tompollard wants to merge 1 commit into
Open
tompollard wants to merge 1 commit into
tompollard wants to merge 1 commit into
Conversation
Linking or logging in with ORCID only caught InvalidGrantError from the token request. Any other reply without a token (an error page, an empty body) raised MissingTokenError, and a network error raised a requests exception, both giving the user a 500. Catch any OAuth error and request error, show a message asking the user to try again, and log ORCID's status, content type and the start of the reply (left out if it might contain a token).
This branch has not been deployed
This file contains hidden or 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
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.
Fixes a 500 error seen in production on
/authorcid/:Cause
When someone links (or logs in with) ORCID, the server exchanges the code from ORCID for a token.
_fetch_and_validate_tokenonly caughtInvalidGrantError, which is what a standard rejection such as an expired or reused code raises. Two other cases weren't caught, and both gave the user a 500:MissingTokenErrorfor these. That's what happened here; a standard rejection would have raisedInvalidGrantErrorinstead.requestsexception.We can't tell what ORCID actually sent, because the reply wasn't logged.
Changes
_fetch_and_validate_tokennow also catchesOAuth2Errorandrequests.RequestException. The user is sent back to the ORCID settings page (or the login page) with "ORCID did not respond as expected. Please try again in a few minutes."requests_oauthlibcompliance hook keeps the reply. The log line has the status, the content type and the first 300 characters of the body. The body is left out if it contains "token", so a token can't end up in the logs.Testing
user/test_orcid.py:physionet.test_urlsfor the anonymous access URL ofdemoecg, which also fails ondevlocally without this change.