callback.php (1193B)
1 <?php 2 3 require_once 'vendor/autoload.php'; 4 5 $clientConfig = new fkooman\OAuth\Client\ClientConfig( 6 array( 7 "authorize_endpoint" => "http://localhost/oauth/php-oauth/authorize.php", 8 "client_id" => "php-oauth-client-example", 9 "client_secret" => "f00b4r", 10 "token_endpoint" => "http://localhost/oauth/php-oauth/token.php", 11 ) 12 ); 13 14 try { 15 $tokenStorage = new fkooman\OAuth\Client\SessionStorage(); 16 $httpClient = new Guzzle\Http\Client(); 17 $cb = new fkooman\OAuth\Client\Callback("foo", $clientConfig, $tokenStorage, $httpClient); 18 $cb->handleCallback($_GET); 19 20 header("HTTP/1.1 302 Found"); 21 header("Location: http://localhost/php-oauth-client-example/index.php"); 22 exit; 23 } catch (fkooman\OAuth\Client\Exception\AuthorizeException $e) { 24 // this exception is thrown by Callback when the OAuth server returns a 25 // specific error message for the client, e.g.: the user did not authorize 26 // the request 27 die(sprintf("ERROR: %s, DESCRIPTION: %s", $e->getMessage(), $e->getDescription())); 28 } catch (Exception $e) { 29 // other error, these should never occur in the normal flow 30 die(sprintf("ERROR: %s", $e->getMessage())); 31 }