I just started learning PhalconPHP and decided to create a simple API, using jwt auth.
I can generate the token without any problem, but when I try to access a protected route I always have a "Signature verification failed". I went on https://jwt.io/#debugger and pasted my token and my secret and it verified properly.
Any help appreciated!
Here is my index:
<?php
require __DIR__ . '/../vendor/autoload.php';
use Dmkit\Phalcon\Auth\Middleware\Micro as AuthMicro;
use Phalcon\Config\Adapter\Ini as ConfigIni;
use Phalcon\Db\Adapter\Pdo\Mysql as PdoMysql;
use Phalcon\Di\FactoryDefault;
use Phalcon\Http\Response;
use Phalcon\Loader;
use Phalcon\Mvc\Micro;
use Phalcon\Mvc\Micro\Collection as MicroCollection;
// Use Loader() to autoload our model
$loader = new Loader();
$loader->registerNamespaces([
"App\Controller" => __DIR__ . "/../controllers/",
"App\Model" => __DIR__ . "/../models/",
]);
$loader->register();
$di = new FactoryDefault();
$config = new ConfigIni(__DIR__ . "/../config.ini");
// Set config
$di->set("config", function () use ($config) {
return $config;
});
// Set up the database service
$di->set("db", function () {
return new PdoMysql([
"host" => "localhost",
"username" => "...",
"password" => "...",
"dbname" => "...",
]);
});
$app = new Micro($di);
$auth = new AuthMicro($app);
/* Registering routes for each controller */
$test = new MicroCollection();
$test->setHandler('App\Controller\TestController', true);
$test->setPrefix('/tests');
$test->get('/', 'list');
$test->get('/{id:[0-9]+}', 'get');
$user = new MicroCollection();
$user->setHandler('App\Controller\UserController', true);
$user->setPrefix('/users');
$user->post('/token', 'token');
$app->mount($test);
$app->mount($user);
$app->handle();
The config.ini is the one in the README with just this line added:
ignoreUri[] = /users/token:POST
Hi @dmkit ,
I just started learning PhalconPHP and decided to create a simple API, using jwt auth. I can generate the token without any problem, but when I try to access a protected route I always have a "Signature verification failed". I went on https://jwt.io/#debugger and pasted my token and my secret and it verified properly.
Any help appreciated!
Here is my index:
The config.ini is the one in the README with just this line added:
ignoreUri[] = /users/token:POST
And the method used to generate the token:
I'm working with PHP 7.0 and PhalconPHP 3.2.0.
Did I miss something?