-
Notifications
You must be signed in to change notification settings - Fork 14
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
Change Canvas Studio admin token refresh to work more like other refreshes #6290
Conversation
8268d04
to
a7d0cad
Compare
…eshes Canvas Studio admin token refreshes used to be done transparently by the backend when needed, different to how this is handled for other APIs. We need to introduce a mechanism to prevent concurrent refreshes of access tokens, and this will be easier to do if all token refreshes work the same way. Hence this commit changes Canvas Studio APIs to fail with an error if an admin refresh token is needed, and the frontend will initiate a refresh. Unlike other token refreshes, if it fails, we show a custom error dialog to the user which doesn't prompt them to re-authorize (they can't, the current user is not the admin) and instead shows more specific instructions. This change only applies if the current user is *not* an admin, otherwise refreshes are handled exactly as with other APIs, including providing the option to re-authorize if the request fails. There is nothing in place currently to prevent multiple concurrent calls to the admin token refresh endpoint. This will be addressed in future changes.
a7d0cad
to
8d54a19
Compare
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.
Code looks fine and works for me 👍
I think the error messages need to be more specific. The last thing we want is for the feature to stop working for the whole school and to brick-wall users with an overly-generic error message that doesn't give them the information they need to fix the problem.
"Your Canvas LMS administrator needs to re-authorize the integration between Hypothesis and Canvas Studio." Which administrator? It needs to be the particular one whose email address we have (although as discussed on Slack, perhaps we should change that). Re-authorize Hypothesis how? (They need to launch an assignment.)
config.add_route( | ||
"canvas_studio_api.oauth.refresh_admin", | ||
"/api/canvas_studio/oauth/refresh_admin", | ||
) |
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.
You might be able to avoid the doubling up of refresh endpoints and views by using a ?admin
query param.
<p> | ||
Your Canvas LMS administrator needs to re-authorize the integration | ||
between Hypothesis and Canvas Studio. | ||
</p> |
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.
I'd recommend a more detailed error message than this.
- What exactly does the admin need to do in order to re-authorize the integration? Go into a course and launch an assignment? Whatever it is, it should be in the error message.
- Who exactly needs to do this? It's not just any admin, it has to be one particular admin whose email address we have
- I'd also make "Your Canvas LMS" clearer and more specific by including the URL of the LMS instance: "The hypothesis.instructure.com administrator [email protected] needs to..." (and avoid using the jargon term "LMS" which users may not understand).
These error messages are going to be screen-shotted or copy-pasted by students and sent to their instructors, or sent by instructors to their admins, or to us. The more detailed and specific the error message can be about exactly who needs to do exactly what, the better chance the users have of recovering quickly without a lot of time lost to confusion or back-and-forth with Hypothesis support.
I filed #6302 to track making the error message more specific. |
Canvas Studio admin token refreshes used to be done transparently by the backend when needed, which is different than how this is handled for other APIs. We need to introduce a mechanism to prevent concurrent refreshes of access tokens, and this will be easier to do if all token refreshes work the same way. Hence this commit changes Canvas Studio APIs to fail with an error if an admin refresh token is needed, and the frontend will initiate a refresh.
Unlike other token refreshes, if it fails, we show a custom error dialog to the user which doesn't prompt them to re-authorize (they can't, the current user is not the admin) and instead shows more specific instructions.
This change only applies if the current user is not an admin, otherwise refreshes are handled exactly as with other APIs, including providing the option to re-authorize if the request fails.
There is nothing in place currently to prevent multiple concurrent calls to the admin token refresh endpoint. This will be addressed in future changes.
Testing:
UPDATE oauth2_token SET access_token = 'foo' WHERE service = 'canvas_studio'
.This should result in an error dialog like: