summaryrefslogtreecommitdiffstats
path: root/examples/ajax-broker/ajax.php
diff options
context:
space:
mode:
Diffstat (limited to 'examples/ajax-broker/ajax.php')
-rw-r--r--examples/ajax-broker/ajax.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/ajax-broker/ajax.php b/examples/ajax-broker/ajax.php
new file mode 100644
index 0000000..68d252f
--- /dev/null
+++ b/examples/ajax-broker/ajax.php
@@ -0,0 +1,41 @@
+<?php
+require_once $_SERVER['DOCUMENT_ROOT'] . '/src/Broker.php';
+
+function send_error($message) {
+ header("Content-Type: application/json");
+ header("HTTP/1.1 406 Not Acceptable");
+ echo '{error: "$message"}';
+}
+
+if (empty($_REQUEST['command'])) {
+ send_error('command not specified');
+ exit();
+}
+else if ($_REQUEST['command'] == 'on') {
+ send_error('unsupported command');
+ exit();
+}
+
+$command = $_REQUEST['command'];
+$broker = new Jasny\SSO\Broker('http://localhost:9000/examples/server/', 'Alice', 'Bob');
+
+if (!empty($_REQUEST['token'])) {
+ $broker->token = $_REQUEST['token'];
+}
+
+if (realpath($_SERVER["SCRIPT_FILENAME"]) == realpath(__FILE__) && isset($_REQUEST['command'])) {
+ error_log('executing: '. $_REQUEST['command']);
+ try {
+ $result = $broker->$_GET['command']();
+ }
+ catch (\Exception $ex) {
+ $result = $ex->getMessage();
+ }
+}
+else {
+ error_log('nothing to execute');
+}
+
+header("Content-Type: application/json");
+echo json_encode($result);
+?> \ No newline at end of file