Page MenuHomePhabricator

D571.diff
No OneTemporary

D571.diff

diff --git a/bin/classes/BaseController.php b/bin/classes/BaseController.php
--- a/bin/classes/BaseController.php
+++ b/bin/classes/BaseController.php
@@ -1,7 +1,6 @@
<?php
-use auth\SSO;
-use auth\SSOCache;
+use magic3w\phpauth\sdk\SSO;
use auth\Token;
use chad\Chad;
use permission\Permission;
@@ -9,7 +8,7 @@
use spitfire\cache\MemcachedAdapter;
use spitfire\core\Environment;
use spitfire\io\session\Session;
-use figure\SDK as Figure;
+use figure\sdk\Client as Figure;
class BaseController extends Controller
{
@@ -47,7 +46,7 @@
protected $figure;
public function _onload() {
- $this->sso = new SSOCache(Environment::get('SSO'));
+ $this->sso = new SSO(Environment::get('SSO'));
$this->figure = new Figure($this->sso, Environment::get('figure'));
#$this->ping = new Ping(Environment::get('ping'), $this->sso);
#$this->chad = new Chad(Environment::get('chad'), $this->sso);
diff --git a/bin/classes/auth/App.php b/bin/classes/auth/App.php
deleted file mode 100644
--- a/bin/classes/auth/App.php
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php namespace auth;
-
-/*
- * The MIT License
- *
- * Copyright 2017 César de la Cal Bretschneider <cesar@magic3w.com>.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-class App
-{
-
- private $id;
-
- private $secret;
-
- private $name;
-
- public function __construct($id, $secret, $name) {
- $this->id = $id;
- $this->secret = $secret;
- $this->name = $name;
- }
-
- public function getId() {
- return $this->id;
- }
-
- public function getSecret() {
- return $this->secret;
- }
-
- public function getName() {
- return $this->name;
- }
-
- public function setId($id) {
- $this->id = $id;
- return $this;
- }
-
- public function setSecret($secret) {
- $this->secret = $secret;
- return $this;
- }
-
- public function setName($name) {
- $this->name = $name;
- return $this;
- }
-
-}
diff --git a/bin/classes/auth/AppAuthentication.php b/bin/classes/auth/AppAuthentication.php
deleted file mode 100644
--- a/bin/classes/auth/AppAuthentication.php
+++ /dev/null
@@ -1,117 +0,0 @@
-<?php namespace auth;
-
-/*
- * The MIT License
- *
- * Copyright 2017 César de la Cal Bretschneider <cesar@magic3w.com>.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-class AppAuthentication
-{
-
- /**
- *
- * @var SSO
- */
- private $sso;
- private $local;
- private $remote;
-
- /**
- *
- * @var Context[]
- */
- private $contexts;
- private $token;
-
- public function __construct($sso, $src, $remote, $context, $token) {
- $this->sso = $sso;
- $this->local = $src;
- $this->remote = $remote;
- $this->contexts = $context;
- $this->token = $token;
- }
-
- /**
- *
- * @deprecated since version 20180704
- * @return boolean
- */
- public function getAuthenticated() {
- return true;
- }
-
- public function getRemote() {
- return $this->remote;
- }
-
- /**
- *
- * @return Context
- */
- public function getContext($name) {
- return $this->contexts[$name];
- }
-
- public function getRedirect($tgt, $contexts = null, $returnto = null) {
- if ($contexts === null) {
- $contexts = [];
- }
-
- foreach ($contexts as $ctx) {
- $signatures[] = (string)$this->sso->makeSignature($tgt, [$ctx instanceof Context? $ctx->getId() : $ctx]);
- }
-
- return $this->sso->getEndpoint() . '/auth/connect?' . http_build_query(['signatures' => $signatures, 'returnto' => $returnto]);
- }
-
- public function setRemote($remote) {
- $this->remote = $remote;
- return $this;
- }
-
- public function setContext($context) {
- $this->contexts = $context;
- return $this;
- }
-
- public function setToken($token) {
- $this->token = $token;
- return $this;
- }
-
- /**
- *
- * @return App
- */
- public function getSrc() {
- return $this->local;
- }
-
- public function getToken() {
- return $this->token;
- }
-
- public function setSrc($src) {
- $this->local = $src;
- return $this;
- }
-}
diff --git a/bin/classes/auth/Context.php b/bin/classes/auth/Context.php
deleted file mode 100644
--- a/bin/classes/auth/Context.php
+++ /dev/null
@@ -1,99 +0,0 @@
-<?php namespace auth;
-
-/*
- * The MIT License
- *
- * Copyright 2017 César de la Cal Bretschneider <cesar@magic3w.com>.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-class Context
-{
-
- private $sso;
- private $app;
- private $id;
- private $exists = null;
- private $granted = null;
-
- /**
- *
- * @param SSO $sso
- * @param App $app
- * @param string $id
- */
- public function __construct($sso, $app, $id) {
- $this->sso = $sso;
- $this->app = $app;
- $this->id = $id;
- }
-
- public function getApp() {
- return $this->app;
- }
-
- public function getId() {
- return $this->id;
- }
-
- public function exists() {
- return $this->exists;
- }
-
- public function setApp($app) {
- $this->app = $app;
- return $this;
- }
-
- public function setId($name) {
- $this->id = $name;
- return $this;
- }
-
- public function setExists($exists) {
- $this->exists = $exists;
- return $this;
- }
-
- public function setGranted($granted) {
- $this->granted = $granted;
- }
-
- public function isGranted() {
- return ((int)$this->granted) === 2;
- }
-
- public function isDenied() {
- return ((int)$this->granted) === 1;
- }
-
- public function create($name, $description) {
- $request = new Request(
- $this->sso->getEndpoint() . '/context/create.json',
- ['context' => $this->id, 'signature' => (string)$this->sso->makeSignature()]
- );
-
- $request->send(['name' => $name, 'description' => $description]);
-
- $this->exists = true;
- return true;
- }
-
-}
\ No newline at end of file
diff --git a/bin/classes/auth/File.php b/bin/classes/auth/File.php
deleted file mode 100644
--- a/bin/classes/auth/File.php
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php namespace auth;
-
-class File
-{
-
- private $previewURL;
- private $downloadURL;
-
- public function __construct($previewURL, $downloadURL) {
- $this->previewURL = $previewURL;
- $this->downloadURL = $downloadURL;
- }
-
- public function getPreviewURL($w = null, $h = null) {
- list($url, $qstring) = explode('?', $this->previewURL, 2);
- return implode('/', Array(trim($url, '/'), $w, $h)) . '/?' . $qstring;
- }
-
-
-}
\ No newline at end of file
diff --git a/bin/classes/auth/JSON.php b/bin/classes/auth/JSON.php
deleted file mode 100644
--- a/bin/classes/auth/JSON.php
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php namespace auth;
-
-use spitfire\exceptions\PrivateException;
-
-/*
- * The MIT License
- *
- * Copyright 2018 César de la Cal Bretschneider <cesar@magic3w.com>.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-class JSON
-{
-
- public static function decode($string) {
-
- $data = json_decode($string);
-
- if (json_last_error() !== JSON_ERROR_NONE) {
- throw new PrivateException('Invalid JSON - ' . json_last_error_msg(), 1806251459);
- }
-
- return $data;
- }
-}
\ No newline at end of file
diff --git a/bin/classes/auth/Request.php b/bin/classes/auth/Request.php
deleted file mode 100644
--- a/bin/classes/auth/Request.php
+++ /dev/null
@@ -1,96 +0,0 @@
-<?php namespace auth;
-
-use Exception;
-
-/**
- * The request class is in charge of properly establishing HTTP connections with
- * the remote server, retrieving the data and returning it or an error in the
- * event of it failing.
- *
- * @author César de la Cal Bretschneider <cesar@magic3w.com>
- */
-class Request
-{
-
- private $url;
-
- /**
- * Parameters are handled separately from the URL just because they can happen
- * to be a pain and are way more comfy to handle in array form.
- *
- * @var string[]
- */
- private $parameters;
-
- /**
- * Depending on whether this array contains data we will be sending a POST or
- * a GET request. Also, if it contains data this will be the post payload.
- *
- * @var mixed[]|null
- */
- private $postData;
-
- /**
- *
- * @param string $url
- * @param string[] $parameters
- */
- public function __construct($url, $parameters = Array()) {
- $this->url = $url;
- $this->parameters = $parameters;
- }
-
- /**
- * This contains the data that will be posted to the server when the request
- * is sent. This can be overriden by passing a parameter to the send method.
- *
- * @param string[] $data
- */
- public function setPostData($data) {
- $this->postData = $data;
- }
-
- /**
- *
- * @param string[] $data MAy contain postdata
- *
- * @return mixed
- */
- public function send($data = null) {
- #Find the appropriate data
- if (!$data) { $data = $this->postData; }
-
- #Assemble the full URI
- $url = $this->url;
- if (!empty($this->parameters)) { $url.= '?' . http_build_query($this->parameters); }
-
- #Prepare the cURL request
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-
- #If data is there to be posted we will send that
- if (!empty($data)) {
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- }
-
- #Get the cURL response
- $response = curl_exec($ch);
-
- #If the request was not okay we will return an error
- $http_response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-
- if ($http_response_code !== 200) {
- echo $url;
- var_dump($data);
- //echo __($response);
- //die();
- throw new Exception('SSO rejected the request (' . curl_error($ch) . ')', 1605141533);
- }
-
- #Return the response we received
- return $response;
- }
-
-
-}
diff --git a/bin/classes/auth/SSO.php b/bin/classes/auth/SSO.php
deleted file mode 100644
--- a/bin/classes/auth/SSO.php
+++ /dev/null
@@ -1,210 +0,0 @@
-<?php namespace auth;
-
-use Exception;
-use signature\Hash;
-use signature\Signature;
-
-class SSO
-{
-
- private $endpoint;
- private $appId;
- private $appSecret;
-
- public function __construct($credentials) {
- $reflection = URLReflection::fromURL($credentials);
-
- $this->endpoint = rtrim($reflection->getProtocol() . '://' . $reflection->getServer() . ':' . $reflection->getPort() . $reflection->getPath(), '/');
- $this->appId = $reflection->getUser();
- $this->appSecret = $reflection->getPassword();
-
- if (!$this->appSecret) {
- throw new Exception('App Secret is missing', 1807021658);
- }
- }
-
- /**
- * Creates a new SSO Token. This allows your application to request a single
- * user's token and manage it.
- */
- public function createToken($expires = null) {
- /*
- * Fetch the JSON message from the endpoint. This should tell us whether
- * the request was a success.
- */
- $get = Array('appID' => $this->appId, 'appSecret' => $this->appSecret);
- if ($expires !== null) { $get['expires'] = $expires; }
-
- $response = file_get_contents($this->endpoint . '/token/create.json?' .
- http_build_query($get));
-
- if (!strstr($http_response_header[0], '200')) { throw new Exception('SSO rejected the token with ' . $http_response_header[0], 1605201109); }
-
- $data = json_decode($response);
-
- if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception('SSO sent invalid json response - ' . json_last_error_msg(), 1608012100); }
-
- return new Token($this, $data->token, $data->expires, $data->location);
- }
-
- /**
- * Instances a token. As opposed to the createToken method, this token cannot
- * be authorized afterwards.
- *
- * @param string $token
- * @return Token
- */
- public function makeToken($token) {
- return new Token($this, $token, null, null);
- }
-
- public function getUser($username, Token$token = null) {
-
- if (!$username) { throw new Exception('Valid user id needed'); }
-
- /*
- * Assemble the request we need to retrieve the data. Please note that if
- * there is no token we pass no parameters.
- */
- $request = new Request(
- $this->endpoint . '/user/detail/' . $username . '.json',
- $token && $token->isAuthenticated()? Array('token' => $token->getTokenInfo()->token, 'signature' => (string)$this->makeSignature()) : Array('signature' => (string)$this->makeSignature())
- );
-
- /*
- * Fetch the JSON message from the endpoint. This should tell us whether
- * the request was a success.
- */
- $resp = $request->send();
- $data = json_decode($resp)->payload;
-
- return new User($data->id, $data->username, $data->aliases, $data->groups, $data->verified, $data->registered_unix, $data->attributes, $data->avatar);
- }
-
- /**
- *
- * @param string $signature
- * @param string $token
- * @param string $context
- * @return AppAuthentication
- */
- public function authApp($signature, $token = null, $context = null) {
- if ($token instanceof Token) {
- $token = $token->getId();
- }
-
- $request = new Request(
- $this->endpoint . '/auth/app.json',
- array_filter(Array('token' => $token, 'signature' => (string)$this->makeSignature(), 'remote' => $signature, 'context' => $context))
- );
-
- $response = $request->send();
-
- $json = json_decode($response);
- $src = new App($json->local->id, $this->appSecret, $json->local->name);
-
- if (isset($json->remote)) {
- $app = new App($json->remote->id, null, $json->remote->name);
- }
- else {
- $app = null;
- }
-
- if ($json->context) {
- $contexts = [];
- foreach ($json->context as $jsctx) {
- $ctx = new Context($this, $app, $jsctx->id);
- $ctx->setExists(!$jsctx->undefined);
- $ctx->setGranted($jsctx->granted);
- $contexts[$jsctx->id] = $ctx;
- }
- }
- else {
- $contexts = [];
- }
-
- $res = new AppAuthentication($this, $src, $app, $contexts, $json->token);
-
- return $res;
- }
-
- public function sendEmail($userid, $subject, $body) {
-
- $request = new Request(
- $this->endpoint . '/email/send/' . $userid . '.json',
- Array('appId' => $this->appId, 'appSecret' => $this->appSecret)
- );
-
- $response = $request->send(Array('body' => $body, 'subject' => $subject));
- $data = json_decode($response)->payload;
-
- return $data;
- }
-
- public function getEndpoint() {
- return $this->endpoint;
- }
-
- public function getAppId() {
- return $this->appId;
- }
-
- public function getSecret() {
- return $this->appSecret;
- }
-
- public function makeSignature($target = null, $contexts = []) {
- $signature = new Signature(Hash::ALGO_DEFAULT, $this->appId, $this->appSecret, $target, $contexts);
- return $signature;
- }
-
- public function getAppList() {
- $url = $this->endpoint . '/appdrawer/index.json';
- $request = new Request($url, ['signature' => (string)$this->makeSignature(), 'all' => 'yes']);
-
- $response = $request->send();
- $data = JSON::decode($response);
-
- return $data;
- }
-
- public function getAppDrawer() {
- $url = $this->endpoint . '/appdrawer/index.json';
- $request = new Request($url, []);
-
- $response = $request->send();
- $data = JSON::decode($response);
-
- return $data;
- }
-
- public function getAppDrawerJS() {
- return $this->endpoint . '/appdrawer/index.js';
- }
-
- public function getGroupList() {
- $url = $this->endpoint . '/group/index.json';
- $resp = file_get_contents($url);
-
- if (!strstr($http_response_header[0], '200')) {
- throw new Exception('SSO rejected the request with ' . $http_response_header[0], 201605201109);
- }
-
- $data = json_decode($resp);
- return $data->payload;
- }
-
- public function getGroup($id) {
- $url = $this->endpoint . '/group/detail/' . $id . '.json';
- $resp = file_get_contents($url);
-
- if (!strstr($http_response_header[0], '200')) {
- throw new Exception('SSO rejected the request with ' . $http_response_header[0], 201605201109);
- }
-
- $data = json_decode($resp);
- return $data->payload;
- }
-
-}
-
diff --git a/bin/classes/auth/SSOCache.php b/bin/classes/auth/SSOCache.php
deleted file mode 100644
--- a/bin/classes/auth/SSOCache.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php namespace auth;
-
-class SSOCache
-{
-
- private $sso;
-
- private $cache;
-
- public function __construct($credentials) {
- $this->sso = new SSO($credentials);
- $this->cache = new \spitfire\cache\MemcachedAdapter();
- $this->cache->setTimeout(3600*24);
- }
-
- public function getUser($id, $token = null) {
-
- if ($token) { return $this->sso->getUser($id, $token); }
-
- return unserialize($this->cache->get('sso_user_' . $id, function () use ($id) {
- return serialize($this->sso->getUser($id));
- }));
- }
-
- public function getSSO() {
- return $this->sso;
- }
-
- public function __call($name, $arguments) {
- return call_user_func_array(Array($this->sso, $name), $arguments);
- }
-}
diff --git a/bin/classes/auth/Token.php b/bin/classes/auth/Token.php
deleted file mode 100644
--- a/bin/classes/auth/Token.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php namespace auth;
-
-use Exception;
-
-class Token
-{
-
- private $sso;
- private $token;
- private $expires;
- private $redirect;
-
- public function __construct($sso, $token, $expires, $redirect) {
- $this->sso = $sso;
- $this->token = $token;
- $this->expires = $expires;
- $this->redirect = $redirect;
- }
-
- public function getId() {
- return $this->token;
- }
-
- public function getRedirect($successURI, $failureURI = null) {
- return $this->redirect . '?' . http_build_query(Array('returnurl' => strval($successURI), 'cancelurl' => strval($failureURI)));
- }
-
- public function getTokenInfo() {
- static $cache = null;
-
- if ($cache !== null) { return $cache; }
-
- $response = file_get_contents($this->sso->getEndpoint() . '/auth/index/' . $this->token . '.json');
-
- if (!isset($http_response_header)) { throw new Exception('SSO connection failed'); }
- if (!strstr($http_response_header[0], '200')) { throw new Exception('SSO error'); }
-
- return $cache = json_decode($response);
- }
-
- public function isAuthenticated() {
- return $this->getTokenInfo()->authenticated;
- }
-}
\ No newline at end of file
diff --git a/bin/classes/auth/URLReflection.php b/bin/classes/auth/URLReflection.php
deleted file mode 100644
--- a/bin/classes/auth/URLReflection.php
+++ /dev/null
@@ -1,165 +0,0 @@
-<?php namespace auth;
-
-/*
- * The MIT License
- *
- * Copyright 2017 César de la Cal Bretschneider <cesar@magic3w.com>.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-/**
- * This class allows to retrieve database settings in a organized manner. This
- * should make the transfer to environment based database settings much easier.
- *
- * @author César de la Cal Bretschneider <cesar@magic3w.com>
- */
-class URLReflection
-{
-
- private $protocol;
- private $server;
- private $port;
- private $user;
- private $password;
- private $path;
- private $queryString;
-
- private static $defaults = [
- 'scheme' => 'https',
- 'host' => 'localhost',
- 'port' => null,
- 'user' => '',
- 'pass' => '',
- 'path' => '/',
- 'query' => '',
- 'fragment' => ''
- ];
-
- public function __construct($protocol, $server, $port, $user, $password, $path, $querystr) {
- $this->protocol = $protocol;
- $this->server = $server;
- $this->port = $port === null? ($protocol === 'http'? 80 : 443) : $port;
- $this->user = $user;
- $this->password = $password;
- $this->path = $path;
-
- parse_str($querystr, $query);
- $this->queryString = $query;
- }
-
- public function getProtocol() {
- return $this->protocol;
- }
-
- public function getQueryString() {
- return $this->queryString;
- }
-
- public function setProtocol($protocol) {
- $this->protocol = $protocol;
- return $this;
- }
-
- public function setQueryString($queryString) {
- $this->queryString = $queryString;
- return $this;
- }
-
- public function getServer() {
- return $this->server;
- }
-
- public function getUser() {
- return $this->user;
- }
-
- public function getPassword() {
- return $this->password;
- }
-
- public function getPath() {
- return $this->path;
- }
-
- public function getPort() {
- return $this->port;
- }
-
- public function setServer($server) {
- $this->server = $server;
- return $this;
- }
-
- public function setPort($port) {
- $this->port = $port;
- return $this;
- }
-
- public function setUser($user) {
- $this->user = $user;
- return $this;
- }
-
- public function setPassword($password) {
- $this->password = $password;
- return $this;
- }
-
- public function setPath($path) {
- $this->path = $path;
- return $this;
- }
-
- /**
- * Reads the settings from a URL. Since October 2017 we're focusing on providing
- * URLs to store database credentials, which allow in turn to store the DB
- * settings outside of the application and on the server itself.
- *
- * @todo Move to external URL parser
- * @param Settings|string $url
- * @return Settings
- */
- public static function fromURL($url) {
-
- /*
- * If the parameter provided is already a settings object, it will be
- * returned as is.
- */
- if ($url instanceof self) { return $url; }
-
- return self::fromArray(parse_url($url));
- }
-
- public static function fromArray($arr) {
- $ops = $arr + self::$defaults;
-
- return new self(
- $ops['scheme'],
- $ops['host'],
- $ops['port'],
- $ops['user'],
- $ops['pass'],
- $ops['path'],
- $ops['query'],
- $ops['fragment']
- );
- }
-
-}
diff --git a/bin/classes/auth/User.php b/bin/classes/auth/User.php
deleted file mode 100644
--- a/bin/classes/auth/User.php
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php namespace auth;
-
-use Exception;
-
-class User
-{
-
- private $id;
- private $username;
- private $aliases;
- private $groups;
- private $verified;
- private $registered;
- private $attributes;
- private $avatar;
-
- public function __construct($id, $username, $aliases, $groups, $verified, $registered, $attributes, $avatar) {
- $this->id = $id;
- $this->username = $username;
- $this->aliases = $aliases;
- $this->groups = $groups;
- $this->verified = $verified;
- $this->registered = $registered;
- $this->attributes = $attributes;
- $this->avatar = $avatar;
- }
-
- public function getId() {
- return $this->id;
- }
-
- public function getUsername() {
- return $this->username;
- }
-
- public function getAvatar($size) {
- return $this->avatar->{$size};
- }
-
- public function getAttribute($name) {
- if (!isset($this->attributes->{$name})) { throw new Exception("Attribute {$name} is not set"); }
- if (!is_object($this->attributes->{$name})) { return $this->attributes->{$name}->value; }
-
- $data = $this->attributes->{$name}->value;
-
- if ($data === null) {
- throw new Exception("Attribute {$name} is not set");
- }
-
- switch($data->type) {
- case 'file': return new File($data->preview, $data->download);
- default: throw new Exception('Invalid data type');
- }
- }
-
-}
-
diff --git a/bin/classes/figure/SDK.php b/bin/classes/figure/SDK.php
deleted file mode 100644
--- a/bin/classes/figure/SDK.php
+++ /dev/null
@@ -1,66 +0,0 @@
-<?php namespace figure;
-
-/*
- * The MIT License
- *
- * Copyright 2020 César de la Cal Bretschneider <cesar@magic3w.com>.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-class SDK
-{
-
- /**
- *
- * @var \auth\SSO
- */
- private $sso;
- private $endpoint;
- private $appid;
-
-
- public function __construct($sso, $url) {
- $this->sso = $sso;
-
- $reflection = URLReflection::fromURL($url);
- $this->endpoint = rtrim($reflection->getProtocol() . '://' . $reflection->getServer() . ':' . $reflection->getPort() . $reflection->getPath(), '/');
- $this->appid = $reflection->getUser();
- }
-
- public function uploadJS() {
- return rtrim($this->endpoint, '\/') . '/upload/create.js';
- }
-
- public function URL() {
- return rtrim($this->endpoint, '\/');
- }
-
- public function claim($id, $secret) {
- $request = request(sprintf('%s/upload/claim/%s/%s.json', $this->endpoint, $id, $secret));
- $request->get('signature', (string) $this->sso->makeSignature($this->appid));
- $request->send();
- }
-
- public function delete($id) {
- $request = request(sprintf('%s/upload/delete/%s.json', $this->endpoint, $id, $secret));
- $request->get('signature', (string) $this->sso->makeSignature($this->appid));
- $request->send();
- }
-}
diff --git a/bin/classes/figure/URLReflection.php b/bin/classes/figure/URLReflection.php
deleted file mode 100644
--- a/bin/classes/figure/URLReflection.php
+++ /dev/null
@@ -1,165 +0,0 @@
-<?php namespace figure;
-
-/*
- * The MIT License
- *
- * Copyright 2017 César de la Cal Bretschneider <cesar@magic3w.com>.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-/**
- * This class allows to retrieve database settings in a organized manner. This
- * should make the transfer to environment based database settings much easier.
- *
- * @author César de la Cal Bretschneider <cesar@magic3w.com>
- */
-class URLReflection
-{
-
- private $protocol;
- private $server;
- private $port;
- private $user;
- private $password;
- private $path;
- private $queryString;
-
- private static $defaults = [
- 'scheme' => 'https',
- 'host' => 'localhost',
- 'port' => null,
- 'user' => '',
- 'pass' => '',
- 'path' => '/',
- 'query' => '',
- 'fragment' => ''
- ];
-
- public function __construct($protocol, $server, $port, $user, $password, $path, $querystr) {
- $this->protocol = $protocol;
- $this->server = $server;
- $this->port = $port === null? ($protocol === 'http'? 80 : 443) : $port;
- $this->user = $user;
- $this->password = $password;
- $this->path = $path;
-
- parse_str($querystr, $query);
- $this->queryString = $query;
- }
-
- public function getProtocol() {
- return $this->protocol;
- }
-
- public function getQueryString() {
- return $this->queryString;
- }
-
- public function setProtocol($protocol) {
- $this->protocol = $protocol;
- return $this;
- }
-
- public function setQueryString($queryString) {
- $this->queryString = $queryString;
- return $this;
- }
-
- public function getServer() {
- return $this->server;
- }
-
- public function getUser() {
- return $this->user;
- }
-
- public function getPassword() {
- return $this->password;
- }
-
- public function getPath() {
- return $this->path;
- }
-
- public function getPort() {
- return $this->port;
- }
-
- public function setServer($server) {
- $this->server = $server;
- return $this;
- }
-
- public function setPort($port) {
- $this->port = $port;
- return $this;
- }
-
- public function setUser($user) {
- $this->user = $user;
- return $this;
- }
-
- public function setPassword($password) {
- $this->password = $password;
- return $this;
- }
-
- public function setPath($path) {
- $this->path = $path;
- return $this;
- }
-
- /**
- * Reads the settings from a URL. Since October 2017 we're focusing on providing
- * URLs to store database credentials, which allow in turn to store the DB
- * settings outside of the application and on the server itself.
- *
- * @todo Move to external URL parser
- * @param Settings|string $url
- * @return Settings
- */
- public static function fromURL($url) {
-
- /*
- * If the parameter provided is already a settings object, it will be
- * returned as is.
- */
- if ($url instanceof self) { return $url; }
-
- return self::fromArray(parse_url($url));
- }
-
- public static function fromArray($arr) {
- $ops = $arr + self::$defaults;
-
- return new self(
- $ops['scheme'],
- $ops['host'],
- $ops['port'],
- $ops['user'],
- $ops['pass'],
- $ops['path'],
- $ops['query'],
- $ops['fragment']
- );
- }
-
-}
diff --git a/bin/classes/signature/Checksum.php b/bin/classes/signature/Checksum.php
deleted file mode 100644
--- a/bin/classes/signature/Checksum.php
+++ /dev/null
@@ -1,114 +0,0 @@
-<?php namespace signature;
-
-use spitfire\exceptions\PrivateException;
-
-/*
- * The MIT License
- *
- * Copyright 2017 César de la Cal Bretschneider <cesar@magic3w.com>.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-/**
- * When a hash is executed, it should return a checksum. This is a combination
- * of the computed hash and the algorithm used to compute said hash.
- *
- * The algo is usually not very important, since the low collission rate will
- * usually prevent two hashes from being equal if they were generated with
- * different mechanisms. But, it makes it even harder for sums to be spoofed in
- * any way.
- *
- * @author César de la Cal Bretschneider <cesar@magic3w.com>
- * @todo Technically this class should be named <code>Hash</code>
- */
-class Checksum
-{
-
- /**
- * The procedure used to calculate the checksum. Please note that if the
- * algorithms missmatch, the application will throw an exception.
- *
- * @var string
- */
- private $algo;
-
- /**
- * The hashed sum. This contains a string that will get compared. If the two
- * are different, the software will return false.
- *
- * @var string
- */
- private $hash;
-
- /**
- * Creates a new checksum result. You need to provide the algorithm, and the
- * resulting hash.
- *
- * @param string $algo
- * @param string $hash
- */
- public function __construct($algo, $hash) {
- $this->algo = $algo;
- $this->hash = $hash;
- }
-
- /**
- * Returns the name of the algorithm used to generate the hash.
- *
- * @return string
- */
- public function getAlgo() {
- return $this->algo;
- }
-
- /**
- * Returns the hash generated. Please note that the Checksum is no longer
- * aware of the original string and therefore cannot recalculate the hash.
- *
- * @return string
- */
- public function hash() {
- return $this->hash;
- }
-
- /**
- * This method allows to compare two Hashverifiers. This method is symmetric,
- * you can compare like $a->verify($b) and $b->verify($a) and they provide the
- * exact same result.
- *
- * @param Checksum $hash
- * @return bool
- * @throws PrivateException
- */
- public function verify(Checksum$hash) {
-
- /**
- * If the algo is not matched - the application will throw an exception.
- * It is not an acceptable behavior for the application to provide different
- * algos to compare a checksum.
- */
- if($this->algo !== $hash->getAlgo()) {
- throw new PrivateException('Algorithm missmatch', 1802072349);
- }
-
- return $this->hash === $hash->hash();
- }
-
-}
\ No newline at end of file
diff --git a/bin/classes/signature/Hash.php b/bin/classes/signature/Hash.php
deleted file mode 100644
--- a/bin/classes/signature/Hash.php
+++ /dev/null
@@ -1,134 +0,0 @@
-<?php namespace signature;
-
-use Exception;
-
-/*
- * The MIT License
- *
- * Copyright 2017 César de la Cal Bretschneider <cesar@magic3w.com>.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-/**
- * Signatures are a method to identify two servers communicating with each other.
- * A server can sign a set of data and the receiving server can (with knowledge
- * of the data being sent) verify that the origin server is the one it claims to
- * be.
- *
- * An example would be a server identifying itself with a signature that contains
- * it's app ID, app Secret and a random salt to prevent the request from being
- * recycled.
- *
- * @author César de la Cal Bretschneider <cesar@magic3w.com>
- * @todo Technically this class should be named <code>Hash</code>
- */
-class Hash
-{
-
- /**
- * This constant indicates the usage of SHA512 as hashing algorithm. As of
- * 2018 this algo is sufficient for the application.
- *
- * @link https://en.wikipedia.org/wiki/SHA-2
- */
- const ALGO_SHA512 = 'sha512';
-
- /**
- * This constant points to the default algorithm. This constant is updated
- * as the algo is changed.
- */
- const ALGO_DEFAULT = self::ALGO_SHA512;
-
- /**
- * The separator used to separate the components before running the hashing
- * function. This should make the debugging simpler and prevent collisions
- * when using short data.
- *
- * For example, when hashing (1, 11) and (11, 1) you could have a collision
- * if no separator is provided since both options would hash(111), this would
- * make it rather easy to vector an attack against the system.
- */
- const SEPARATOR = '.';
-
- /**
- * Name of the algorithm to be used to hash the signature.
- *
- * @var string
- */
- private $algo;
-
- /**
- * PHPAS usually hashes several pieces of data as part of a signature. Instead
- * of providing this object with a pre-concatenated string, we use an array -
- * which is concatenated before being hashed.
- *
- * @var string[]
- */
- private $components;
-
- /**
- * Creates a new hash. The first parameter is the algorithm to be used to
- * generate the hash and the next parameters are used to generate the hash.
- *
- * @param string $algo
- * @param string $_
- */
- public function __construct($algo, $_) {
- $this->components = func_get_args();
- $this->algo = array_shift($this->components);
- }
-
- /**
- * Returns the identifier for the algorithm used to generate the hash.
- *
- * @return string
- */
- public function getAlgo() {
- return $this->algo;
- }
-
- /**
- * Generates a checksum and returns it. Please note that this method does not
- * cache it's result. So running it several times may result in costly
- * operations.
- *
- * @return Checksum
- * @throws Exception
- */
- public function hash() {
- $components = $this->components;
-
- /*
- * Reconstruct the original signature with the data we have about the
- * source application to verify whether the apps are the same, and
- * should therefore be granted access.
- */
- switch(strtolower($this->algo)) {
- case 'sha512':
- $calculated = hash('sha512', implode(self::SEPARATOR, array_filter($components)));
- break;
- default:
- throw new Exception('Invalid algorithm', 400);
- }
-
- return new Checksum($this->algo, $calculated);
- }
-
-}
\ No newline at end of file
diff --git a/bin/classes/signature/Signature.php b/bin/classes/signature/Signature.php
deleted file mode 100644
--- a/bin/classes/signature/Signature.php
+++ /dev/null
@@ -1,298 +0,0 @@
-<?php namespace signature;
-
-use spitfire\exceptions\PrivateException;
-use spitfire\exceptions\PublicException;
-
-/*
- * The MIT License
- *
- * Copyright 2017 César de la Cal Bretschneider <cesar@magic3w.com>.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-/**
- * Signatures are a method to identify two servers communicating with each other.
- * A server can sign a set of data and the receiving server can (with knowledge
- * of the data being sent) verify that the origin server is the one it claims to
- * be.
- *
- * An example would be a server identifying itself with a signature that contains
- * it's app ID, app Secret and a random salt to prevent the request from being
- * recycled.
- *
- * @author César de la Cal Bretschneider <cesar@magic3w.com>
- */
-class Signature
-{
-
- /**
- * A signature hosts several pieces of information (depending on the request,
- * 4 to 6 elements) and therefore needs a separator that also needs to not
- * appear within the data.
- *
- * Since the information is only made up of alphanumeric characters (a-z,0-9)
- * we can ensure that the data can be separated by colons.
- */
- const SEPARATOR_SIGNATURE = ':';
-
- /**
- * A signature may contain several contexts. Since this data is an Array-type
- * kind of data, we need a separator for it to work in a string environment.
- */
- const SEPARATOR_CONTEXT = ',';
-
- /**
- * Indicates the hashing algorithm used to generate the hash for the signature,
- * this should be strong enough to prevent a user from generating random
- * collissions.
- *
- * @var string
- */
- private $algo;
-
- /**
- * The source application. This is the application signing the request, therefore,
- * the secret used to generate the signature will ALWAYS be the one for this
- * application.
- *
- * @var string
- */
- private $src;
-
- /**
- * The source's secret. This is generated during creation of the application
- * and should never be transmitted.
- *
- * @var string
- */
- private $secret;
-
- /**
- * The App ID of the application that the request is meant for. This is used
- * to query the server for public application data, like it's public URL or
- * name - therefore allowing the app to present some basic data to the user
- * about the remote application before connecting.
- *
- * When this is sent in a request without the appropriate context, it is used
- * to authenticate the source against the target application. This way, the
- * target app can add context as a _GET parameter and check whether the
- * given contexts have been granted to the source application.
- *
- * This is not sufficient for context granting though. When a context is to be
- * granted, the roles are reversed. The granting app becomes the source, and
- * the grantee becomes the target.
- *
- * @var string
- */
- private $target;
-
- /**
- * Contexts are used in cross application communication to grant certain
- * privileges. When an application wishes to exchange data, it will request
- * access to certain parts of the remote application by requesting access to
- * specific contexts.
- *
- * @var string
- */
- private $context;
-
- private $expires;
-
- /**
- * The salt is a random string attached to every signature, which makes it
- * hard for an attacker to forge a request. The salt is mandatory and mustn't
- * be empty for a request to be valid.
- *
- * @var string
- */
- private $salt;
-
- /**
- * This is the final, calculated checksum for this signature. A checksum object
- * will contain the combination of algo and result of the sum operation.
- *
- * If the value of the checksum is null, it has not yet been calculated.
- *
- * @var Checksum|null
- */
- private $checksum;
-
- /**
- *
- * @param string|null $algo
- * @param string $src
- * @param string|null $secret
- * @param string $target
- * @param string $context
- * @param string|null $salt
- * @param Checksum|null $hash
- */
- public function __construct($algo, $src, $secret, $target, $context, $expires = null, $salt = null, Checksum$hash = null) {
- $this->algo = $algo?: Hash::ALGO_DEFAULT;
- $this->src = $src;
- $this->secret = $secret;
- $this->target = $target;
- $this->context = $context;
- $this->expires = $expires;
- $this->salt = $salt;
- $this->checksum = $hash instanceof Checksum || !$hash? $hash : new Checksum($this->algo, $hash);
- }
-
- public function getAlgo() {
- return $this->algo;
- }
-
- public function getSrc() {
- return $this->src;
- }
-
- public function getTarget() {
- return $this->target;
- }
-
- public function getContext() {
- return $this->context;
- }
-
- public function getSalt() {
-
- if (!$this->salt) {
- $this->salt = substr(base64_encode(random_bytes(50)), 0, 50);
- }
-
- return $this->salt;
- }
-
- public function isExpired() {
- return $this->expires < time();
- }
-
- public function getExpiration() {
- return $this->expires === null? time() + 600 : $this->expires;
- }
-
- /**
- * Calculates the checksum needed to verify the signature while keeping the
- * secret hidden from curious eyes.
- *
- * @return Checksum
- * @throws PrivateException
- */
- public function checksum() {
-
- /**
- * In the event of the signature missing either the secret or the pre-calculated
- * checksum (this is the case for signatures that were sent from remote
- * sources) we will be unable to generate a proper sum and need to stop
- * the execution.
- */
- if (!$this->checksum && !$this->secret) {
- throw new PrivateException('Incomplete signature. Cannot be hashed', 1802082113);
- }
-
- /**
- * If the system has no pre-calculated checksum we will create a hash to
- * calculate the checksum.
- */
- if (!$this->checksum) {
- $hash = new Hash($this->algo, $this->src, $this->target, $this->secret, implode(self::SEPARATOR_CONTEXT, $this->context), $this->getExpiration(), $this->getSalt());
- $this->checksum = $hash->hash();
- }
-
- return $this->checksum;
- }
-
- public function salt($salt) {
- $this->salt = $salt;
- $this->checksum = null;
- return $this;
- }
-
- public function setHash(Checksum$hash) {
- $this->checksum = $hash;
- return $this;
- }
-
- public function setSecret($secret) {
- $this->secret = $secret;
- $this->checksum = null;
- return $this;
- }
-
- public function __toString() {
- return implode(self::SEPARATOR_SIGNATURE, array_filter([
- $this->algo,
- $this->src,
- $this->target,
- implode(self::SEPARATOR_CONTEXT, $this->context),
- $this->getExpiration(),
- $this->getSalt(),
- $this->checksum()->hash()
- ]));
- }
-
- /**
- * Splits up a signature sent from a remote server and extracts the data
- * provided by it. The system can then use the hash to compare it to a existing
- * dataset.
- *
- * @todo This should be moved to a helper. Not static.
- * @param string $from
- * @return Signature
- * @throws PublicException
- */
- public static function extract($from) {
- $signature = explode(self::SEPARATOR_SIGNATURE, $from);
- $context = [];
-
- switch(count($signature)) {
- case 4:
- list($algo, $src, $salt, $hash) = $signature;
- $target = null;
- break;
- case 5:
- list($algo, $src, $target, $salt, $hash) = $signature;
- break;
- case 6:
- list($algo, $src, $target, $contextstr, $salt, $hash) = $signature;
- $context = explode(self::SEPARATOR_CONTEXT, $contextstr);
- break;
- default:
- throw new PublicException('Invalid signature', 400);
- }
-
- return new self($algo, $src, null, $target, $context, $salt, new Checksum($algo, $hash));
- }
-
- /**
- * Creates a new signature. This method will use the default hashing mechanism
- * and generate a valid signature that the system can use.
- *
- * @todo This should be moved to a helper. Not static.
- * @param string $src
- * @param string $target
- * @param string $context
- * @return Signature
- */
- public static function make($src, $secret, $target = null, $context = null) {
- return new Signature(Hash::ALGO_DEFAULT, $src, $secret, $target, $context);
- }
-
-}
\ No newline at end of file
diff --git a/composer.json b/composer.json
--- a/composer.json
+++ b/composer.json
@@ -1,15 +1,19 @@
{
- "name": "magic3w/switches",
- "description": "Switches provides user profiles, configuration and privacy settings for m3w micro service environments",
- "type": "project",
- "license": "MIT",
- "authors": [
- {
- "name": "César de la Cal Bretschneider",
- "email": "cesar@magic3w.com"
- }
- ],
- "require": {
- "magic3w/permission-php-sdk": "dev-master"
- }
+ "name": "magic3w/switches",
+ "description": "Switches provides user profiles, configuration and privacy settings for m3w micro service environments",
+ "type": "project",
+ "license": "MIT",
+ "minimum-stability": "dev",
+ "prefer-stable": true,
+ "authors": [
+ {
+ "name": "César de la Cal Bretschneider",
+ "email": "cesar@magic3w.com"
+ }
+ ],
+ "require": {
+ "magic3w/permission-php-sdk": "dev-master",
+ "magic3w/figure-sdk-php": "dev-master",
+ "magic3w/phpauth-sdk-php": "^0.1.1"
+ }
}
diff --git a/composer.lock b/composer.lock
--- a/composer.lock
+++ b/composer.lock
@@ -4,8 +4,41 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "b058085fe630851f8f9398ff8a521c54",
+ "content-hash": "ace081fda48469595f569dcf2c4316e3",
"packages": [
+ {
+ "name": "magic3w/figure-sdk-php",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://phabricator.magic3w.com/source/figure-sdk-php.git",
+ "reference": "e85eeccdf4f892305012ac971c342ae0690cb931"
+ },
+ "require": {
+ "magic3w/phpauth-sdk-php": "^0.1.1",
+ "spitfire/collection": "^0.1.0",
+ "spitfire/request": "dev-master"
+ },
+ "default-branch": true,
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "figure\\sdk\\": "./src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "César de la Cal Bretschneider",
+ "email": "cesar@magic3w.com"
+ }
+ ],
+ "description": "SDK for interacting with figure",
+ "time": "2021-02-02T14:25:05+00:00"
+ },
{
"name": "magic3w/permission-php-sdk",
"version": "dev-master",
@@ -32,17 +65,144 @@
],
"description": "Allows your application to communicate with a permission server through a simple API",
"time": "2020-08-26T15:10:23+00:00"
+ },
+ {
+ "name": "magic3w/phpauth-sdk-php",
+ "version": "v0.1.1",
+ "source": {
+ "type": "git",
+ "url": "https://phabricator.magic3w.com/source/phpas-sdk-php.git",
+ "reference": "9841296f9cdcd91071d7e929f58ecb4ed154b696"
+ },
+ "require": {
+ "magic3w/url-reflection": "dev-master",
+ "spitfire/request": "dev-master"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "magic3w\\phpauth\\sdk\\": "./src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "César de la Cal Bretschneider",
+ "email": "cesar@magic3w.com"
+ }
+ ],
+ "description": "PHP SDK for PHPAuthServer (magic3w/phpauth)",
+ "time": "2020-12-18T16:45:12+00:00"
+ },
+ {
+ "name": "magic3w/url-reflection",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://phabricator.magic3w.com/source/url-reflection.git",
+ "reference": "341d1ede12d28159101b77c8ae12b544dba15a8c"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^9.3"
+ },
+ "default-branch": true,
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "magic3w\\http\\url\\reflection\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "César de la Cal Bretschneider",
+ "email": "cesar@magic3w.com"
+ }
+ ],
+ "description": "Allows applications to have a URL parsed and retrieve information about it's components",
+ "time": "2021-02-11T13:17:34+00:00"
+ },
+ {
+ "name": "spitfire/collection",
+ "version": "0.1.0",
+ "source": {
+ "type": "git",
+ "url": "https://phabricator.magic3w.com/source/spitfire-collection.git",
+ "reference": "91331bd1f15d9c15d363734bd477c7bd363291a5"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^9.4"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "spitfire\\collection\\": "./src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "César de la Cal Bretschneider",
+ "email": "cesar@magic3w.com"
+ }
+ ],
+ "description": "Provides collections for spitfire/engine",
+ "time": "2020-10-19T09:26:22+00:00"
+ },
+ {
+ "name": "spitfire/request",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://phabricator.magic3w.com/source/spitfire-request.git",
+ "reference": "0e8166d802e0e71dd12365bca0215043c9df37d2"
+ },
+ "require": {
+ "magic3w/url-reflection": "dev-master"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^9.4"
+ },
+ "default-branch": true,
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "spitfire\\io\\request\\": "./src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "César de la Cal Bretschneider",
+ "email": "cesar@magic3w.com"
+ }
+ ],
+ "description": "Spitfire request mechanism",
+ "time": "2021-01-21T07:59:55+00:00"
}
],
"packages-dev": [],
"aliases": [],
- "minimum-stability": "stable",
+ "minimum-stability": "dev",
"stability-flags": {
- "magic3w/permission-php-sdk": 20
+ "magic3w/permission-php-sdk": 20,
+ "magic3w/figure-sdk-php": 20
},
- "prefer-stable": false,
+ "prefer-stable": true,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
- "plugin-api-version": "1.1.0"
+ "plugin-api-version": "2.0.0"
}

File Metadata

Mime Type
text/plain
Expires
Wed, Apr 14, 7:23 AM (3 w, 6 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6075
Default Alt Text
D571.diff (59 KB)

Event Timeline