1. Go to this page and download the library: Download smtech/oauth-negotiator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
smtech / oauth-negotiator example snippets
$oauth = new OAuthNegotiator(
$_REQUEST['url'] . '/login/oauth2',
'0000000001', // Canvas developer ID
'6987c1e292a98deff97c97f2cbc49985', // Canvas developer key/secret (referred to both ways in their documentation)
'page3.php', // where to go when we're done
'OAuthNegotiator' // your purpose for this token (displayed on the user settings page in Canvas)
);
$oauth = new OAuthNegotiator();
// get your token
echo $oauth->getToken();
// get the user information associated with that token
print_r($oauth->getUser());
/* attempt to create a simple OAuthNegotiator for the intermediate steps in the workflow */
try {
$oauth = new OAuthNegotiator();
} catch (OAuthNegotiator_Exception $e) {}
/* otherwise, check what step in the workflow we're at */
if (isset($_REQUEST['oauth'])) {
switch ($_REQUEST['oauth']) {
case 'request': { // explain what's up to the user
echo '
<html>
<body>
<h1>Token Request</h1>
<p>Explain why you’re requesting a token.</p>
<p><a href="' . $_SERVER['PHP_SELF'] . '?oauth=process">Click to continue</a></p>
</body>
</html>';
exit;
}
case 'process': { // start the negotiation process
$oauth = new OAuthNegotiator(
"https://canvas.instructure.com/login/oauth2", // replace with your OAuth provider endpoint
(string) $secrets->oauth->id,
(string) $secrets->oauth->key,
"{$_SERVER['PHP_SELF']}?oauth=complete",
(string) $secrets->app->name
);
break;
}
case 'complete': { // negotiation is complete
/* do something productive with your token */
$_SESSION['apiToken'] = $oauth->getToken();
/* on to the next page, token in hand! */
header("Location: ./next.php");
exit;
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.