OAUTH2_CLIENT_ID, 'redirect_uri' => 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'], 'scope' => 'user', 'state' => $_SESSION['state'] ); // Redirect the user to Github's authorization page header('Location: ' . $authorizeURL . '?' . http_build_query($params)); die(); } // When Github redirects the user back here, there will be a "code" and "state" parameter in the query string if(get('code')) { // Verify the state matches our stored state if(!get('state') || $_SESSION['state'] != get('state')) { header('Location: ' . $_SERVER['PHP_SELF']); die(); } // Exchange the auth code for a token $token = apiRequest($tokenURL, array( 'client_id' => OAUTH2_CLIENT_ID, 'client_secret' => OAUTH2_CLIENT_SECRET, 'redirect_uri' => 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'], 'state' => $_SESSION['state'], 'code' => get('code') )); $_SESSION['access_token'] = $token->access_token; header('Location: ' . $_SERVER['PHP_SELF']); } if(session('access_token')) { $user = apiRequest($apiURLBase . 'user'); echo '
'; print_r($user); echo ''; } else { echo '