src/CasRestClient.php
public function login($tgtStorageLocation = '', $forceAuth = false)
    {

        if ((!$this->casServer) || (!$this->casPassword) || (!$this->casUsername)) {
            throw new \Exception('CAS server and credentials must be set before calling login()', 1);
        }

        $this->tgtStorageLocation = $tgtStorageLocation;

        // Try to load the TGT from the storage file
        if (!$forceAuth && $tgtStorageLocation) {
            if (file_exists($tgtStorageLocation)) {
                if (! is_readable($tgtStorageLocation)) {
                    throw new \Exception('TGT storage file [' . $tgtStorageLocation . '] is not readable!', 500);
                }
                $this->loadTGTfromFile($tgtStorageLocation);
                return true;
            }
        }

        try {
            $response = $this->guzzleClient->request(
                'POST',
                $this->casRESTcontext,
                [
                    'verify' => $this->verifySSL,
                    'form_params' => [
                        'username' => $this->casUsername,
                        'password' => $this->casPassword
                    ]
                ]
            );

            $responseHeaders = $response->getHeaders();

        } catch (ClientException $e) {
            // Bad username or password.
            if ($e->getCode() == 400) {
                return false;
                // Unsupported Media Type
            } elseif ($e->getCode() == 415) {
                return false;
            } else {
                throw new \Exception($e->getMessage(), $e->getCode());
            }
        } catch (\Exception $e) {
            throw new \Exception($e->getMessage(), $e->getCode());
        }

        if (isset($responseHeaders['Location'][0])) {
            $this->tgtLocation = $responseHeaders['Location'][0];
            $this->tgt = substr(strrchr($this->tgtLocation, '/'), 1);
        }

        // Save the TGT to a storage file.
        if ($tgtStorageLocation) {
            $this->writeTGTtoFile($tgtStorageLocation, $this->tgt);
        }

        return true;
    }
public function login($tgtStorageLocation = '', $forceAuth = false)
    {

        if ((!$this->casServer) || (!$this->casPassword) || (!$this->casUsername)) {
            throw new \Exception('CAS server and credentials must be set before calling login()', 1);
        }

        $this->tgtStorageLocation = $tgtStorageLocation;

        // Try to load the TGT from the storage file
        if (!$forceAuth && $tgtStorageLocation) {
            if (file_exists($tgtStorageLocation)) {
                if (! is_readable($tgtStorageLocation)) {
                    throw new \Exception('TGT storage file [' . $tgtStorageLocation . '] is not readable!', 500);
                }
                $this->loadTGTfromFile($tgtStorageLocation);
                return true;
            }
        }

        try {
            $response = $this->guzzleClient->request(
                'POST',
                $this->casRESTcontext,
                [
                    'verify' => $this->verifySSL,
                    'form_params' => [
                        'username' => $this->casUsername,
                        'password' => $this->casPassword
                    ]
                ]
            );

            $responseHeaders = $response->getHeaders();

        } catch (ClientException $e) {
            // Bad username or password.
            if ($e->getCode() == 400) {
                return false;
                // Unsupported Media Type
            } elseif ($e->getCode() == 415) {
                return false;
            } else {
                throw new \Exception($e->getMessage(), $e->getCode());
            }
        } catch (\Exception $e) {
            throw new \Exception($e->getMessage(), $e->getCode());
        }

        if (isset($responseHeaders['Location'][0])) {
            $this->tgtLocation = $responseHeaders['Location'][0];
            $this->tgt = substr(strrchr($this->tgtLocation, '/'), 1);
        }

        // Save the TGT to a storage file.
        if ($tgtStorageLocation) {
            $this->writeTGTtoFile($tgtStorageLocation, $this->tgt);
        }

        return true;
    }
public function login ( $ tgtStorageLocation = '' , $ forceAuth = false ) { if ( ( ! $ this -> casServer ) || ( ! $ this -> casPassword ) || ( ! $ this -> casUsername ) ) { throw new \ Exception ( 'CAS server and credentials must be set before calling login()' , 1 ) ; } $ this -> tgtStorageLocation = $ tgtStorageLocation ; // Try to load the TGT from the storage file if ( ! $ forceAuth && $ tgtStorageLocation ) { if ( file_exists ( $ tgtStorageLocation ) ) { if ( ! is_readable ( $ tgtStorageLocation ) ) { throw new \ Exception ( 'TGT storage file [' . $ tgtStorageLocation . '] is not readable!' , 500 ) ; } $ this -> loadTGTfromFile ( $ tgtStorageLocation ) ; return true ; } } try { $ response = $ this -> guzzleClient -> request ( 'POST' , $ this -> casRESTcontext , [ 'verify' => $ this -> verifySSL , 'form_params' => [ 'username' => $ this -> casUsername , 'password' => $ this -> casPassword ] ] ) ; $ responseHeaders = $ response -> getHeaders ( ) ; } catch ( ClientException $ e ) { // Bad username or password. if ( $ e -> getCode ( ) == 400 ) { return false ; // Unsupported Media Type } elseif ( $ e -> getCode ( ) == 415 ) { return false ; } else { throw new \ Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } } catch ( \ Exception $ e ) { throw new \ Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } if ( isset ( $ responseHeaders [ 'Location' ] [ 0 ] ) ) { $ this -> tgtLocation = $ responseHeaders [ 'Location' ] [ 0 ] ; $ this -> tgt = substr ( strrchr ( $ this -> tgtLocation , '/' ) , 1 ) ; } // Save the TGT to a storage file. if ( $ tgtStorageLocation ) { $ this -> writeTGTtoFile ( $ tgtStorageLocation , $ this -> tgt ) ; } return true ; }
Validate credentials against the CAS server and retrieve a Ticket-Granting Ticket.  If a tgtStorageLocation is
specified, the fle is read and the saved TGT is used instead of validating credentials.  If force_auth is TRUE,
always validate credentials.

@param string $tgtStorageLocation
@param bool $forceAuth
@return bool
@throws \Exception
Validate credentials against the CAS server and retrieve a Ticket - Granting Ticket . If a tgtStorageLocation is specified the fle is read and the saved TGT is used instead of validating credentials . If force_auth is TRUE always validate credentials .