/** * @covers HealthGraph\Authorization::authorize * @todo Implement better testAuthorize(). */ public function testAuthorize() { $token = Authorization::authorize($this->authorization_code, $this->client_id, $this->client_secret, $GLOBALS['redirect_url']); $this->assertFalse($token); }
<?php require_once '../vendor/autoload.php'; use HealthGraph\Authorization; use HealthGraph\Client; session_start(); if (isset($_SESSION['token'])) { $token = $_SESSION['token']; } $client_id = 'your_client_id'; $client_secret = 'your_client_secret'; $redirect_url = 'http://localhost/healthgraph/'; if (isset($_GET['code'])) { // user accepted access $token = Authorization::authorize($_GET['code'], $client_id, $client_secret, $redirect_url); if ($token) { $_SESSION['token'] = $token; } header("Location: {$redirect_url}"); } elseif (isset($_GET['error'])) { // user denied access $button = Authorization::getAuthorizationButton($client_id, $redirect_url); echo $button['html']; echo '<h2>Denied</h2>'; } elseif (isset($_GET['revoke'])) { // user wants to disconnect $auth = new Authorization(); if ($auth->deauthorize($token['access_token'])) { unset($_SESSION['token']); } header("Location: {$redirect_url}");