The OAuth flow is two steps: the first step returns a unique code you post back to Canvas to receive the final token.
1. In your app, direct the user to a URL with the following structure:
https://<canvas-install-url>/login/oauth2/auth?client_id=XXX&response_type=code&state=YYY&redirect_uri=https://example.com/oauth_complete
- Your client_id should match the Developer Key you set up in Canvas.
- The code param is required to retrieve the unique code in the response.
- Pass the current oauth state value for the user making the request. This is typically generated by a library handling OAuth.
- The redirect URI is a page you control which makes the final request to Canvas for an API token.
2. On your redirect page, extract the code parameter from the URL querystring. This code is then POSTed back to Canvas for the user.
https://<canvas-install-url>/login/oauth2/token
The payload object should have:
- grant_type: request the type you need for the request
- client_id: your registered client ID in the Canvas Admin Developer Key section
- client_secret: your registered client secret in the Canvas Admin Developer Key section
- redirect_uri: this must match the URI specified in step 1.
- code: The code received in step 1.
You can store the response from Canvas for your user to reuse the token for subsequent calls. You'll also get a refresh token which can be used to reauthorize after the initial timeout. Check to make sure you're making the second call with the correct call, etc. I also have a Python project validating with OAuth and you can see how that is structured if you would like.