Set Up Canvas Authentication#
Authentication […] is the act of proving an assertion, such as the identity of a computer system user.
Canvas is a Learning Management System built by Instructure Holdings that is widely used across educational instutions to provide students with online learning. With the jupyterhub_oauthenticator_authz_helpers.canvas, it is possible to use Canvas as an authentication provider which allows users with access to a particular Canvas instance to log-in to a JupyterHub.
Installing the Library#
To use these helpers, you must first install the jupyterhub-oauthenticator_authz_helpers package from PyPI into the same environment as your JupyterHub itself. For Zero to JupyterHub users, this means creating a custom Docker image that installs this package alongside the JupyterHub dependencies.
Authenticating the Canvas User#
Together, the authorize_url and token_url endpoints returns an access token that provides authorization to a Canvas instance’s resources on behalf of the current Canvas user. This alone is insufficient to set-up Canvas authentication, as the authenticator does not have the ability to determine who is accessing the hub from this token alone.
For this, we’ll need to query a user-data URL that returns identity information about the current token holder. Let’s now configure the userdata_url to obtain structured information about the Canvas user’s identity, and configure the authenticator to derive a username from this data. For example, if the Canvas API returns a login_id field in the userdata_url response:
from jupyterhub_oauthenticator_authz_helpers import build_auth_urls
canvas_url = "<CANVAS-URL>"
cfg = c.GenericOAuthenticator
# Configure various auth URLs
cfg.authorize_url, cfg.token_url, cfg.userdata_url = build_auth_urls(canvas_url)
# Scopes that this token will need
cfg.scope = build_auth_urls.scopes
# Indicate which user-data item yields the username
cfg.username_claim = "login_id"
Now we’ve successfully configured our JupyterHub with the ability to identify the username of user that log-in with Canvas. However, these users will not, by default, be able to access the hub. For that, we must visit the topic of authentication.