The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December. Read our blog post for more info about this change.
Found this content helpful? Log in or sign up to leave a like!
Hi,
I have built a very simple OAUTH connection to a canvas instance, but I'm not getting the expected response. Can someone spot where I have gone wrong?
Thanks
A) Start at: http://nick.lms.cm-hosting.com/canvas/login.php
B) The Oauth initial handshake works, and returns (as specified) back to http://nick.lms.cm-hosting.com/canvas/return.php
C) The PHP $_GET array looks like:
Array ( [code] => 846684a9818d06bf19b639f2f19f5bdbb50188e1440c9e897b7d3abb7250fede81043025b34b3c57a738c5ee111bc52b7f6d3c03a1f502b15b7b7911bc25afb6 [state] => CHECK_THIS ) D) A curl POST is then made to this URL:
https://oup.instructure.com/login/oauth2/token?
code=846684a9818d06bf19b639f2f19f5bdbb50188e1440c9e897b7d3abb7250fede81043025b34b3c57a738c5ee111bc52b7f6d3c03a1f502b15b7b7911bc25afb6
&grant_type=authorization_code
&client_id=130650000000000007
&redirect_uri=http://nick.lms.cm-hosting.com/canvas/return.php&client_secret=ABCDEF (not the real secret)
E) The response returned is: � ]�KO�0 ����� �2 ,IPQ�ix�� �@�JyX^�L��n�ąws��s�{� �<'��M}C:� �;������* � 9 ȏ ���E��K?@��m i���1Am ���w2����!��� �� 0��@ �%� �����s ��aZ �p� B�ט wф�B �@��3f�&� ���2* )K�Ot! �s�6�2�4�I��X���t(�� �s�� �E�����,]�$�V� ����� u� �8�m� �>�_�0�>��*rF �t�� `�|�>
Solved! Go to Solution.
Ah, yes, it was the zip encoding. The simple exemplar I was using was wrong.
Could the problem be the zip encoding on the curl?
$json = getToken($code, $access_token_url, $client_id, $client_secret, $callback_url);function getToken($code, $access_token_url, $client_id, $client_secret, $callback_url){
$curl = curl_init();
$url = $access_token_url."?"
."code=".$code
."&grant_type=authorization_code"
."&client_id=". $client_id
."&redirect_uri=". $callback_url;
printf("<p> url: %s (without client secret) </p>\n",$url);
$url .= '&client_secret='. $client_secret;
$params = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_NOBODY => false,
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded",
"accept: *",
"accept-encoding: gzip, deflate",
),
);
curl_setopt_array($curl, $params);
printf("<p> executing curl POST to url");
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
printf("<p> response (a): \n");
print_r($response);
printf("</p>\n");
printf("<p>json return: %s </p>\n",$response);
if ($err) {
echo "cURL Error #01: " . $err;
} else {
$array_response = json_decode($response, true);
printf("<p>response: %s </p>\n",print_r($array_response,true));
if(array_key_exists("access_token", $array_response)) return $array_response;
if(array_key_exists("error", $array_response)) echo $array_response["error_description"];
echo "<p>cURL Error #02: Something went wrong! Please contact admin.</p>";
}
}
Ah, yes, it was the zip encoding. The simple exemplar I was using was wrong.
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in