Skip to content

Instantly share code, notes, and snippets.

@drmmr763
Created April 1, 2013 03:18
Show Gist options
  • Save drmmr763/5283072 to your computer and use it in GitHub Desktop.
Save drmmr763/5283072 to your computer and use it in GitHub Desktop.
working on a simple oauth2 app
<?php
session_start();
// define Joomla's framework path
// get bootstrap
require dirname(dirname(dirname(__FILE__))).'/bootstrap.php';
// Increase error reporting to that any errors are displayed.
// Note, you would not use these settings in production.
error_reporting(E_ALL);
ini_set('display_errors', true);
// Setup the autoloaders.
JLoader::setup();
//namespace
use Joomla\Application\Web;
use Joomla\Input\Input;
use Joomla\Oauth2\Client;
use Joomla\Http\Http;
use Joomla\Registry\Registry;
// you must extend the web class since the web class is abstract
class HelloWww extends Web
{
// override the execute class
protected function doExecute()
{
$this->setBody('<body>Hello Www!</body>');
}
}
// set Oauth2 parameters
$data = array();
//$data['redirect_uri'] = 'https://www.cohesivewebsites.com/jplatform/oauth.php';
$data['clientid'] = 'xxx';
$data['clientsecret'] = 'yyy';
$data['authurl'] = 'https://www.box.com/api/oauth2/authorize';
$data['tokenurl'] = 'https://www.box.com/api/oauth2/authorize';
// load params it JRegistry
$options = new Registry($data);
// set up necessary objects
$app = new HelloWww;
$input = new Input;
$http = new Http($options);
// set the Oauth2 Client
$oauth = new Client($options, $http, $input, $app);
if ($input->get('code'))
{
print_r($input->get('code'));
$token = $oauth->authenticate();
//print_r($token);
}
else
{
$box = $http->get($oauth->createUrl());
print_r($box);
}
// finally, we can execute!
$app->execute();
?>
@dsiemon2
Copy link

how do i use it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment