-
Notifications
You must be signed in to change notification settings - Fork 204
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
Show error messages when OAuth access token and refresh token requests fail #376
Conversation
Show an error if the initial request for an OAuth access token fails. When the client is embedded in a page that includes a services configuration setting (see <http://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-services>) then it tries to login to Hypothesis using OAuth, exchanging the grant token from the services config setting for an access token from the Hypothesis API. If this request for an access token fails (for example, if the Hypothesis server responds with an error) then the client ends up in an invalid state. Some of the sidebar components are not fully rendered, with visible parts missing, no annotations are shown, and actions such as trying to create an annotation fail in broken ways. We should really fix the completely broken appearance and behavior of the client in this state, but that'll be a big job. For now, at least show an error message to the user telling them that they need to reload the page. There's currently no facility to retry the access token request but if the user reloads the page the whole process will begin again and the request will be tried again.
When the client is embedded in a page that includes a services configuration setting then it logs in to Hypothesis using OAuth, getting an access token from the Hypothesis API. The Hypothesis API's OAuth access tokens currently expire after an hour and must be refreshed by the client before then. When the request to refresh an access token fails the client continues to look and work exactly as before from the user's point of view, except that all actions that require communicating with the API such as creating an annotation fail and show error messages. Some actions, such as dismissing the sidebar tutorial, fail with no error message. Currently we only try the refresh request once for each access token and don't retry is the request fails. Even if we did retry the refresh request can't succeed after the access token has expired - it's always possible for the client to get into a situation where the access token is expired and can no longer be refreshed. The only fix (currently) is for the user to reload the page which will re-do the initial grant token request to get a new access token. So when a refresh request fails show an error message to the user telling them that they need to reload the page.
1191f66
to
d826fd7
Compare
This is done but just needs tests. When refreshing the access token fails I'd like it to show the error when the token expires, rather than when the request fails (when the access token could still have 5 mins before expiry) but I think doing that would require a little refactoring so I'd do it in a follow-up. I'm gonna mark this as needs review as I'd like to check that this is an acceptable fix for hypothesis/product-backlog#169 before taking the time to write the tests for it. |
Discussed in Slack, I'll finish up this PR with an aim to getting it reviewed and merged. It may not be the final fix that we want for this problem but it's an improvement over what's on master now and it shouldn't be much work to finish it |
I'm gonna close this because I've realised that when I wrote the refresh token code (that is already on master) I missed something about how It shouldn't be too difficult to fix (I think we need to use |
Show an error if the initial request for an OAuth access token or a later request to refresh an access token fails.
When the client is embedded in a page that includes a services
configuration setting (see http://h.readthedocs.io/projects/client/en/latest/publishers/config/#cmdoption-arg-services)
then it tries to login to Hypothesis using OAuth, exchanging the grant
token from the services config setting for an access token from the
Hypothesis API.
If this request for an access token fails (for example, if the
Hypothesis server responds with an error) then the client ends up in an
invalid state. Some of the sidebar components are not fully rendered,
with visible parts missing, no annotations are shown, and actions such
as trying to create an annotation fail in broken ways.
For example you can hack h to always return an error for the access token request like this:
and then the client will look like this:
We should really fix the completely broken appearance and behavior of
the client in this state, but that'll be a big job. For now, at least show an
error message to the user telling them that they need to reload the page:
(This error message doesn't disappear until the page reloads, not even if the user clicks on it.)
There's currently no facility to retry the access token request but if
the user reloads the page the whole process will begin again and the
request will be tried again.
Additionally, when embedded in a publisher site like this the client needs to refresh the access token every hour. If the refresh request fails then things stop working. For example here trying to dismiss the sidebar tutorial fails silently, while trying to create an annotation gives an unfriendly error message:
You can hack h to make access tokens expire after 5 seconds and to make all requests to refresh them fail like this:
Again, the user has to reload the page. We don't retry the refresh request (and even if we did, once the access token has expired it can no longer succeed). When a refresh request fails show a permanent error message telling the user to reload the page: