cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
pallavi_dhanuka
Community Member

Invalid code error on fetching oauth2 token

Jump to solution

I am using  PHP CURL to get the auth token from canvas.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $canvasUri.'/login/oauth2/token');

curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

$post_params = array("client_id"=>$clientId,"client_secret"=>$secret,"code"=>$code,

                       "grant_type" => 'authorization_code',

                       'redirect_uri' => $redirectUri);

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(

    'Accept: application/json'

));

$response = curl_exec($ch);

On authorizing the app from canvas, when I send the above POST request I get the below error:{"error":"invalid_request","error_description":"client does not have access to specified account","message":"invalid code"}

Tried several alternatives, used Postman ( a REST client to test), still the same error.
It would be really great if any help provided.
Thanks!

1 Solution

Accepted Solutions
dwahl_sales
Instructure
Instructure

Hi  @pallavi_dhanuka ​,

You will need a key/secret for each Canvas instance that you are trying to authenticate to.  See here (Issue in LTI App · Issue #723 · instructure/canvas-lms · GitHub ) for more information.

View solution in original post

2 Replies
kona
Community Coach
Community Coach

 @pallavi_dhanuka ​, due to the technical nature of this question I'm going to share this with the Canvas Developers​ group to see if they can assist with this!

dwahl_sales
Instructure
Instructure

Hi  @pallavi_dhanuka ​,

You will need a key/secret for each Canvas instance that you are trying to authenticate to.  See here (Issue in LTI App · Issue #723 · instructure/canvas-lms · GitHub ) for more information.

View solution in original post