Skip to content

Instantly share code, notes, and snippets.

@kiall
Created August 29, 2011 21:37
Show Gist options
  • Save kiall/1179476 to your computer and use it in GitHub Desktop.
Save kiall/1179476 to your computer and use it in GitHub Desktop.
<?php defined('SYSPATH') or die('No direct script access.');
/**
*
*
* @package OAuth2
* @category Library
* @author Managed I.T.
* @copyright (c) 2011 Managed I.T.
* @license https://github.com/managedit/kohana-oauth2/blob/master/LICENSE.md
*/
class Controller_Test extends Controller {
public function action_index()
{
try
{
// 'provider' comes from the config file .. it might be 'github' or 'facebook' etc etc
$client = OAuth2_Consumer::factory('provider', OAuth2::GRANT_TYPE_CLIENT_CREDENTIALS);
// Prepare the request, sans OAuth .. (Eg set request method, add request params etc etc etc)
$request = Request::factory('http://wk01-lmst.managedit.ie/api/roles');
// Execute the request, via the client.
$response = json_decode($client->execute($request));
echo Debug::vars($response);
}
catch (OAuth2_Exception_InvalidGrant $e)
{
/**
* This means the request failed due to bad credentials.
*/
}
}
public function action_index()
{
try
{
// 'provider' comes from the config file .. it might be 'github' or 'facebook' etc etc
$client = OAuth2_Consumer::factory('provider', OAuth2::GRANT_TYPE_PASSWORD, array(
'username' => 'kiall',
'password' => 'kiall',
));
// Prepare the request, sans OAuth .. (Eg set request method, add request params etc etc etc)
$request = Request::factory('http://wk01-lmst.managedit.ie/api/roles');
// Optional user ID to associate this token with..
$user_id = 1;
// Execute the request, via the client.
$response = json_decode($client->execute($request, $user_id));
echo Debug::vars($response);
}
catch (OAuth2_Exception_InvalidGrant $e)
{
/**
* This means the request failed due to bad credentials.
*/
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment