/** * setUp Class constructor */ public function setUp() { Config::loadenv(); $this->client = new Client(); $this->api_url = 'https://api-9jamoji.herokuapp.com'; $this->token = getenv('test_token'); }
/** * Generates Token which expires in One hour * @param Slim $app */ public static function Tokenize(Slim $app) { $username = $app->request->params(self::format('username')); Config::loadenv(); $key = getenv('jwt_key'); $token = ["issued" => getenv('jwt_issued_at'), "issuer" => getenv('jwt_issuer'), "user" => $username, "exp" => time() + 3600]; $jwt = JWT::encode($token, $key); $success = ["status" => 200, "token" => $jwt, "issued at" => gmdate("Y-m-d H:i:s", time()), "expires at" => gmdate("Y-m-d H:i:s", time() + 3600), "token for" => $username]; return json_encode($success); }
/** * Returns a JSON error output * * @param Instance of Slim * @return string */ public static function authentication(Slim $app) { $app->response->headers->set('Content-Type', 'application/json'); $token = $app->request->headers->get('Authorization'); Config::loadenv(); $key = getenv('jwt_key'); $algorithm = array('HS256'); if (!$token) { $app->halt(401, json_encode(['status' => 401, 'message' => 'You need a token to perform this action!'])); } try { $decode_jwt = JWT::decode($token, $key, $algorithm); } catch (Exception $e) { $app->halt(400, json_encode(['status' => 400, 'message' => 'The token supplied is invalid!.'])); } return $decode_jwt->user; }
<?php /* * Connection to database using Illuminate\Database */ use Sirolad\app\base\Config; use Illuminate\Database\Capsule\Manager as Capsule; $capsule = new Capsule(); Config::loadenv(); $driver = getenv('driver'); $capsule->addConnection(array('driver' => $driver, 'host' => getenv('host'), 'database' => getenv('database'), 'username' => getenv('username'), 'password' => getenv('password'), 'charset' => $driver == 'mysql' ? 'utf8mb4' : 'utf8', 'collation' => $driver == 'mysql' ? 'utf8mb4_unicode_ci' : 'utf8_unicode_ci', 'prefix' => '')); $capsule->setAsGlobal(); $capsule->bootEloquent();