Exemplo n.º 1
0
 public function testServiceGet()
 {
     $client = new CasRestClient();
     $client->setCasServer('https://example.org');
     $client->setCredentials('user', 'secret');
     // Create a mock subscriber and response.
     $mock = new MockHandler([new Response(201, ['Location' => 'https://example.org/cas/v1/tickets/TGT-1-1qaz2wsx3edc']), new Response(201, [], 'ST-1-abc123'), new Response(200, [], 'test..1..2..3')]);
     $handler = HandlerStack::create($mock);
     // Add the mock subscriber to the client.
     $client->setGuzzleClient(new Client(['base_uri' => 'https://example.org', 'handler' => $handler]));
     $client->login();
     $this->assertEquals((string) $client->get('https://www.example.com?param1=true')->getBody(), 'test..1..2..3');
 }
Exemplo n.º 2
0
<?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();