summaryrefslogtreecommitdiffstats
path: root/examples/server
diff options
context:
space:
mode:
Diffstat (limited to 'examples/server')
-rw-r--r--examples/server/MySSOServer.php86
-rw-r--r--examples/server/SSOTestServer.php53
-rw-r--r--examples/server/empty.pngbin125 -> 0 bytes
-rw-r--r--examples/server/index.php19
4 files changed, 95 insertions, 63 deletions
diff --git a/examples/server/MySSOServer.php b/examples/server/MySSOServer.php
new file mode 100644
index 0000000..b97eeb0
--- /dev/null
+++ b/examples/server/MySSOServer.php
@@ -0,0 +1,86 @@
+<?php
+
+use Jasny\ValidationResult;
+use Jasny\SSO;
+
+class MySSOServer extends SSO\Server
+{
+ /**
+ * Registered brokers
+ * @var array
+ */
+ private static $brokers = [
+ 'Alice' => ['secret'=>'8iwzik1bwd'],
+ 'Greg' => ['secret'=>'7pypoox2pc'],
+ 'Julias' => ['secret'=>'ceda63kmhp']
+ ];
+
+ /**
+ * System users
+ * @var array
+ */
+ private static $users = array (
+ 'jackie' => [
+ 'fullname' => 'Jackie Black',
+ 'email' => 'jackie.black@example.com',
+ 'password' => '$2y$10$lVUeiphXLAm4pz6l7lF9i.6IelAqRxV4gCBu8GBGhCpaRb6o0qzUO' // jackie123
+ ],
+ 'john' => [
+ 'fullname' => 'John Doe',
+ 'email' => 'john.doe@example.com',
+ 'password' => '$2y$10$RU85KDMhbh8pDhpvzL6C5.kD3qWpzXARZBzJ5oJ2mFoW7Ren.apC2' // john123
+ ],
+ );
+
+ /**
+ * Get the API secret of a broker and other info
+ *
+ * @param string $brokerId
+ * @return array
+ */
+ protected function getBrokerInfo($brokerId)
+ {
+ return isset(self::$brokers[$brokerId]) ? self::$brokers[$brokerId] : null;
+ }
+
+ /**
+ * Authenticate using user credentials
+ *
+ * @param string $username
+ * @param string $password
+ * @return ValidationResult
+ */
+ protected function authenticate($username, $password)
+ {
+ if (!isset($username)) {
+ return ValidationResult::error("username isn't set");
+ }
+
+ if (!isset($password)) {
+ return ValidationResult::error("password isn't set");
+ }
+
+ if (!isset(self::$users[$username]) || !password_verify($password, self::$users[$username]['password'])) {
+ return ValidationResult::error("Invalid credentials");
+ }
+
+ return ValidationResult::success();
+ }
+
+
+ /**
+ * Get the user information
+ *
+ * @return array
+ */
+ protected function getUserInfo($username)
+ {
+ if (!isset(self::$users[$username])) return null;
+
+ $user = compact('username') + self::$users[$username];
+ unset($user['password']);
+
+ return $user;
+ }
+}
+
diff --git a/examples/server/SSOTestServer.php b/examples/server/SSOTestServer.php
deleted file mode 100644
index 3bf697b..0000000
--- a/examples/server/SSOTestServer.php
+++ /dev/null
@@ -1,53 +0,0 @@
-<?php
-
-use Jasny\ValidationResult;
-use Desarrolla2\Cache\Cache;
-use Desarrolla2\Cache\Adapter\Memory;
-use Jasny\SSO\Server;
-
-class SSOTestServer extends Server
-{
- private static $brokers = array (
- 'Alice' => array('secret'=>"Bob"),
- 'Greg' => array('secret'=>'Geraldo'),
- 'BrokerApi' => array('secret'=>'BrokerApi'),
- 'ServerApi' => array('secret' => 'ServerApi')
- );
-
- private static $users = array (
- 'admin' => array(
- 'fullname' => 'jackie',
- 'email' => 'jackie@admin.com'
- )
- );
-
- public function __construct()
- {
- parent::__construct();
- }
-
- protected function getBrokerInfo($broker)
- {
- return self::$brokers[$broker];
- }
-
- protected function authenticate($username, $password)
- {
- $result = new ValidationResult();
-
- if (!isset($username)) {
- return ValidationResult::error("username isn't set");
- } elseif (!isset($password)) {
- return ValidationResult::error("password isn't set");
- } elseif ($username != 'admin' || $password != 'admin') {
- return ValidationResult::error("Invalid credentials");
- }
-
- return $result;
- }
-
- protected function getUserInfo($user)
- {
- return self::$users[$user];
- }
-}
diff --git a/examples/server/empty.png b/examples/server/empty.png
deleted file mode 100644
index 61dc432..0000000
--- a/examples/server/empty.png
+++ /dev/null
Binary files differ
diff --git a/examples/server/index.php b/examples/server/index.php
index d68c55e..5416eb9 100644
--- a/examples/server/index.php
+++ b/examples/server/index.php
@@ -1,19 +1,18 @@
<?php
require_once __DIR__ . '/../../vendor/autoload.php';
-require_once __DIR__ . '/SSOTestServer.php';
+require_once 'MySSOServer.php';
-$sso = new SSOTestServer();
-$request = isset($_REQUEST['command']) ? $_REQUEST['command'] : null;
+$ssoServer = new MySSOServer();
+$command = isset($_REQUEST['command']) ? $_REQUEST['command'] : null;
-if (!$request || !method_exists($sso, $request)) {
- error_log('Unkown command');
- header("HTTP/1.1 406 Not Acceptable");
+if (!$command || !method_exists($ssoServer, $command)) {
+ header("HTTP/1.1 404 Not Found");
header('Content-type: application/json; charset=UTF-8');
-
- echo "{error: 'Uknown command'}";
- die;
+
+ echo json_encode(['error' => 'Unknown command']);
+ exit();
}
-$sso->$request();
+$result = $ssoServer->$command();