/** * @param string $username * @param string $password * @return User * @throws \Exception */ private function userCasAuthentication($username, $password) { $client = new CasRestClient(); $client->setCasServer($this->serverLoginUrl); $client->setCasRestContext($this->serverTicket); $client->setCredentials($username, $password); $client->verifySSL($this->verifySsl()); if ($client->login()) { $response = $client->post($this->getServiceRoute()); if ($response->getStatusCode() == 200) { $user = new User($username, $this->apiRecolnatBaseUri, $this->apiRecolnatUserPath, $this->getContainer()->getParameter('user_group')); return $user; } else { $this->log($this->translator->trans($username . ' access.denied.wrongPermission', [], 'exceptions')); throw new AccessDeniedException($this->getContainer()->get('translator')->trans('access.denied.wrongPassword', [], 'exceptions')); } } else { $this->log($this->translator->trans($username . ' access.denied.wrongPermission', [], 'exceptions')); throw new AccessDeniedException($this->getContainer()->get('translator')->trans('access.denied.wrongPassword', [], 'exceptions')); } }
<?php use epierce\CasRestClient; require_once 'vendor/autoload.php'; $client = new CasRestClient(); // Configure CAS client $client->setCasServer('https://cas.exmaple.edu'); $client->setCasRestContext('/v1/tickets'); $client->setCredentials("username", "password"); // Login and save TGT to a file $client->login('/tmp/cas_tgt.json'); // Make a webservice call $response = $client->get("https://someservice"); print_r(json_decode($response->getBody(), true)); // Make another call using the same SSO session $headers = ['User-Agent' => 'testing/1.0']; $post_params = ['param1' => 'foo', param2 => 'bar']; $response = $client->post("https://someotherservice", $headers, '', $post_params); print_r(json_decode($response->getBody(), true)); $client->logout();