static function authenticate($headers) { $jwt = ""; foreach ($headers as $header => $value) { if ($header == "Authorization") { $head = explode(" ", $value); if (count($head) == 2) { if ($head[0] == "Bearer") { $jwt = $head[1]; } } } } if ($jwt == "") { return false; } try { $secretKey = base64_decode(Flight::get("jwtkey")); $token = Firebase\JWT\JWT::decode($jwt, $secretKey, array("HS512")); return $token; } catch (Exception $e) { return false; } }
* * Nothing really special here. A simple snippet to check the license code. * It's simple to hack. But please consider supporting this project by * buying a license instead. Be awesome. * * Anyway, have fun using Copilot! * * Greets * Artur * */ $license = ['type' => 'trial']; $code = (string) $this->app['copilot.license']; $data = []; try { $data = (array) Firebase\JWT\JWT::decode($code, 'copilot', ['HS256']); } catch (Exception $e) { } if (isset($data['name'], $data['company'], $data['created'], $data['email'], $data['type'])) { $license = $data; $license['code'] = $code; } return (object) $license; }]); // REST if (COCKPIT_REST) { $app->on('cockpit.rest.init', function ($routes) { $routes['copilot'] = 'Copilot\\Controller\\RestApi'; }); } // ADMIN
/** * Decode the received Consent Receipt JWT */ private function decode_jwt($jwt, $key) { $decoded = Firebase\JWT\JWT::decode($jwt, $key, array('RS256')); $decodedArray = (array) $decoded; return $decodedArray; }
/** * Find a user record. * * @param string $username The token identifier. * @param string $password Unused password. * @return Mixed Either false on failure, or an array of user data. */ public function _findUser($username, $password = null) { try { $decoded = Firebase\JWT\JWT::decode($username, Configure::read('Security.salt'), array('HS256')); return json_decode(json_encode($decoded), true); } catch (UnexpectedValueException $e) { return false; } }