Skip to content

Instantly share code, notes, and snippets.

@kiall
Created August 25, 2011 00:44
Show Gist options
  • Save kiall/1169681 to your computer and use it in GitHub Desktop.
Save kiall/1169681 to your computer and use it in GitHub Desktop.
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Test2 {
public function action_index()
{
// State can be used to bring the user back to where they originally were before the redirect..
$state = json_decode($this->request->query('state'));
// Load up the right consumer
$client = OAuth2_Consumer::factory('mip');
// Store the client token/refresh token
$client->exchange_code_for_token($this->request, 1);
echo 'Have a token now .. try again';
}
}
<?php defined('SYSPATH') or die('No direct script access.');
/**
*
*
* @category Controller
* @author Managed I.T.
* @copyright (c) 2011 Managed I.T.
*/
class Controller_Test extends Controller {
public function action_index()
{
try
{
$client = OAuth2_Consumer::factory('mip');
$request = Request::factory('http://wk01-lmst.managedit.ie/mip-api/api/roles');
$response = json_decode($client->execute($request, 1));
echo Debug::vars($response);
}
catch (OAuth2_Exception_InvalidToken $e)
{
$state = 'some_state_to_be_passed_through_the_authorize_request';
$this->request->redirect($client->authorize_url($state));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment