How to use OAuth to get access to the Rest API?

Jump to solution
fabiocunha
Community Explorer

I recently created a PHP page that accesses the Rest API from Canvas for my institution.

It works perfectly, but the token that I use is created by "Manual Token Generation", this is for testing application before implement OAuth.

Now, this is the time to implement OAuth to get access to the Rest API.

But I don't know how to get an OAuth token to access the Canvas Rest API.

I check the get request to get an OAuth token in Canvas documentation

https://mycanvas-url/login/oauth2/auth?client_id=XXX&response_type=code&state=YYY&redirect_uri=https...

In the Canvas documentation page:

https://canvas.instructure.com/doc/api/file.oauth_endpoints.html#get-login-oauth2-auth

the client id is defined as: "The client id for your registered application."

I register an LTI app using the External Tool and pass the string 12345 as "Chave do cliente" (My Canvas installation is in Brazilian Portuguese)

Is the client_id is the "Chave do Cliente"(Client key I suppose)?

What exactly is the client_id?

Any help will be appreciated.

Labels (1)
1 Solution
william_diehl
Community Novice

The client_id will be the numeric value of the developer key you’ve pre-created for use with your tool. For example, we’ve created a developer key for our REST API web utility in the “Developer Keys” section of our Canvas account named “REST API Key.” After the key is generated, under the “Details” column, you’ll see a long number – that’s the client_id value.

You still need a client_id and shared secret (aka Developer Key) for Canvas to trust your external program. Once Canvas trusts your program, you can use it to perform OAuth2 logins and get a REST API access token from the account of whichever user logs in through OAuth2.

In my humble opinion, getting the OAuth2 set up and working was the hardest part of writing our utility. OAuth2 by its very nature requires a web user interface which makes it overly complicated for web apps and extremely difficult to implement with command line utilities (although we were successful in doing so by scraping the Canvas login screen HTML and passing the required login form values from a command ling login prompt).

Hope that helps!

View solution in original post