summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/broker/login.php4
-rw-r--r--src/Broker.php4
2 files changed, 6 insertions, 2 deletions
diff --git a/examples/broker/login.php b/examples/broker/login.php
index bfc79a5..e0e60f5 100644
--- a/examples/broker/login.php
+++ b/examples/broker/login.php
@@ -1,4 +1,5 @@
<?php
+use Jasny\SSO\NotAttachedException;
require_once __DIR__ . '/../../vendor/autoload.php';
$broker = new Jasny\SSO\Broker(getenv('SSO_SERVER'), getenv('SSO_BROKER_ID'), getenv('SSO_BROKER_SECRET'));
@@ -13,6 +14,9 @@ try {
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') $errmsg = "Login failed";
+} catch (NotAttachedException $e) {
+ header('Location: ' . $_SERVER['REQUEST_URI']);
+ exit;
} catch (Jasny\SSO\Exception $e) {
$errmsg = $e->getMessage();
}
diff --git a/src/Broker.php b/src/Broker.php
index 171b811..ebebded 100644
--- a/src/Broker.php
+++ b/src/Broker.php
@@ -202,7 +202,7 @@ class Broker
$response = curl_exec($ch);
if (curl_errno($ch) != 0) {
$message = 'Server request failed: ' . curl_error($ch);
- return $this->fail($message);
+ throw new Exception($message);
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
@@ -210,7 +210,7 @@ class Broker
if ($contentType != 'application/json') {
$message = 'Expected application/json response, got ' . $contentType;
- return $this->fail($message, $httpCode);
+ throw new Exception($message);
}
$data = json_decode($response, true);