OAuth2 Endpoints
Developer keys issued after Oct 2015 generate tokens with a 1 hour expiration. Applications must use refresh tokens to generate new access tokens.
GET login/oauth2/auth
GET https://<canvas-install-url>/login/oauth2/auth?client_id=XXX&response_type=code&redirect_uri=https://example.com/oauth_complete&state=YYY&scope=<value_1>%20<value_2>%20<value_n>
Parameters
Parameter | Required | Description |
---|---|---|
client_id | Required | The client id for your registered application. |
response_type | Required | The type of OAuth2 response requested. The only currently supported value is |
redirect_uri | Required | The URL where the user will be redirected after authorization. The domain of this URL must match the domain of the redirect_uri stored on the developer key, or it must be a subdomain of that domain. For native applications, currently the only supported value is |
state | Optional | Your application can pass Canvas an arbitrary piece of state in this parameter, which will be passed back to your application in Step 2. It's strongly encouraged that your application pass a unique identifier in the state parameter, and then verify in Step 2 that the state you receive back from Canvas is the same expected value. Failing to do this opens your application to the possibility of logging the wrong person in, as described here. |
scope | Optional | This can be used to specify what information the Canvas API access token will provide access to. Canvas API scopes may be found beneath their corresponding endpoints in the "resources" documentation pages. If the developer key does not require scopes and no scope parameter is specified, the access token will have access to all scopes. If the developer key does require scopes and no scope parameter is specified, Canvas will respond with "invalid_scope." To successfully pass multiple scope values, the scope parameter is included once, with multiple values separated by spaces. Passing multiple scope parameters, as is common in other areas of Canvas, causes only the last value to be applied to the generated token. |
purpose | Optional | This can be used to help the user identify which instance of an application this token is for. For example, a mobile device application could provide the name of the device. |
force_login | Optional | Set to '1' if you want to force the user to enter their credentials, even if they're already logged into Canvas. By default, if a user already has an active Canvas web session, they will not be asked to re-enter their credentials. |
unique_id | Optional | Set to the user's username to be populated in the login form in the event that the user must authenticate. |
prompt | Optional | If set to |
POST login/oauth2/token
See Section 4.1.3 of the OAuth2 RFC for more information about this process.
POST /login/oauth2/token
Parameters
Parameter | Required | Description |
---|---|---|
grant_type | Required | Values currently supported: "authorization_code", "refresh_token", and "client_credentials". |
client_id | Required for grant_types: authorization_code, refresh_token | The client id for your registered application. |
client_secret | Required for grant_types: authorization_code, refresh_token | The client secret for your registered application. |
redirect_uri | Required for grant_types: authorization_code, refresh_token | If a redirect_uri was passed to the initial request in step 1, the same redirect_uri must be given here. |
code | Required for grant_type: authorization_code | Required if grant_type is authorization_code. The code you received in a redirect response. |
refresh_token | Required for grant_type: refresh_token | Required if grant_type is refresh_token. The refresh_token you received in a redirect response. |
client_assertion_type | Required for grant_type: client_credentials | Currently the only supported value for this field is `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`. |
client_assertion | Required for grant_type: client_credentials | The signed jwt used to request an access token. Includes the value of Developer Key id as the sub claim of the jwt body. Should be signed by the private key of the stored public key on the DeveloperKey. |
scope | Required for grant_type: client_credentials | A list of scopes to be granted to the token. Currently only IMS defined scopes may be used. |
Canvas API example responses
For grant_type of code or refresh_token:
Parameter | Description |
---|---|
access_token | The OAuth2 Canvas API access token. |
token_type | The type of token that is returned. |
user | A JSON object of canvas user id and user name. |
refresh_token | The OAuth2 refresh token. |
expires_in | Seconds until the access token expires. |
canvas_region | For hosted Canvas, the AWS region (e.g. us-east-1) in which the institution that provided this token resides. For local or open source Canvas, this will have a value of "unknown". This field is safe to ignore. |
When using grant_type=code (ex: for Canvas API access):
When using grant_type=refresh_token, the response will not contain a new refresh token since the same refresh token can be used multiple times:
If scope=/auth/userinfo was specified in the GET login/oauth2/auth request (ex: when using Canvas as an authentication service) then the response that results from POST login/oauth2/token would be:
Examples using client_credentials
When using grant_type=client_credentials (ex: to access LTI Advantage Services):
Example request
This request must be signed by an RSA256 private key with a public key that is configured on the developer key as described in Step 1: Developer Key Setup.
Below is an example of the decoded client_assertion JWT in the above request:
NOTE:
the value of the sub claim should match the client_id of the developer key in Canvas.
the value of the aud claim should contain either the domain of the Canvas account where the desired data resides, or the domain of the LTI 1.3 OIDC Auth endpoint, as described here.
Example Response
Parameter | Description |
---|---|
access_token | The OAuth2 client_credentials access token. |
token_type | The type of token that is returned. |
expires_in | Seconds until the access token expires. |
scope | The scope or space delimited list of scopes granted for the access token. |
DELETE login/oauth2/token
If your application supports logout functionality, you can revoke your own access token. This is useful for security reasons, as well as removing your application from the list of tokens on the user's profile page. Simply make an authenticated request to the following endpoint by including an Authorization header or providing the access_token as a request parameter.
DELETE /login/oauth2/token
Parameters
Parameter | Required | Description |
---|---|---|
expire_sessions | Optional | Set this to '1' if you want to end all of the user's Canvas web sessions. Without this argument, the endpoint will leave web sessions intact. Additionally, if the user logged in to Canvas via a delegated authentication provider, and the provider supports Single Log Out functionality, the response will contain a forward_url key. If you are still in control of the user's browsing session, it is recommended to then redirect them to this URL, in order to also log them out from where their session originated. Beware that it is unlikely that control will be returned to your application after this redirect. |
Example responses
GET login/session_token
If your application needs to begin a normal web session in order to access features not supported via API (such as quiz taking), you can use your API access token in order to get a time-limited URL that can be fed to a browser or web view to begin a new web session.
GET /login/session_token
Parameters
Parameter | Required | Description |
---|---|---|
return_to | Optional | An optional URL to begin the web session at. Otherwise the user will be sent to the dashboard. |
Example responses
© Instructure, Inc. Generated on Wed Nov 6 14:19:59 2024 This documentation is generated directly from the Canvas LMS source code, available on Github.
Last updated