validateState($state); } catch (\Exception $ex) { die('Invalid state returned'); } // If that passes, then we can exchange the authentication code for a token $code = $_GET['code']; $token = $flow->exchangeCodeForToken($code, OPENID_CALLBACK_URL); // Set the token in the session $_SESSION['access_token'] = $token->getAccessToken(); $_SESSION['refresh_token'] = $token->getRefreshToken(); // Now redirect them back to the home page! header('Location: index.php');