I'm Dan. I also push code snippets to Github gists.
dmkit / phalcon-jwt-auth Goto Github PK
View Code? Open in Web Editor NEWBasic jwt authentication class for Phalcon framework
License: MIT License
Basic jwt authentication class for Phalcon framework
License: MIT License
I'm Dan. I also push code snippets to Github gists.
hey @dmkit any plans on adding on doing this?
[InvalidArgumentException]
Could not find package dmkit/phalcon-jwt-auth at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability
had to install the package by adding the git link to my composer.json
Thanks and I'll be submitting PR to update the package to jwt 5 ;)
Add nbf standard field to check method.
Not before (nbf): Identifies the time on which the JWT will start to be accepted for processing.
I'd like to use this, but I'd need to be able to tick the licensing box. Is it possible to add a license? MIT/BSD or similar would be good (Phalcon itself uses New BSD)
Dmkit\Phalcon\Auth\Middleware\Micro.php Line :166
Should be
preg_match('#'.$pattern.'#', $requestUri)
my config
'ignoreUri' => [
'regex:/user/[0-9]+/profile:POST',
]
resuestUri : /user/1/profile
Hi, first of all thanks for this project.
Can you update the composer requirements to allow for this version to be used on phalcon version 4.x?
I've tested this version with the current version of the project and it still works as suppose to.
Thanks once again
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:
<?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
And the method used to generate the token:
public function token()
{
$response = new Response();
$data = [
'success' => false,
];
$content = $this->request->getJsonRawBody();
if (property_exists($content, "username") && property_exists($content, "password")) {
$phql = "SELECT * FROM " . User::class . " WHERE username = :username:";
$user = $this->modelsManager->executeQuery($phql, [
"username" => $content->username,
])->getFirst();
if ($user && $user instanceof User) {
if (password_verify($content->password, $user->getPassword())) {
$payload = [
'sub' => $user->getId(),
'email' => $user->getEmail(),
'username' => $user->getUsername(),
'role' => 'admin',
'iat' => time(),
];
$token = $this->auth->make($payload);
$data = [
'success' => true,
'token' => $token,
];
}
}
}
$response->setJsonContent($data);
return $response;
}
I'm working with PHP 7.0 and PhalconPHP 3.2.0.
Did I miss something?
Hello I am having problems implementing jwt in phalcon, I am importing as described: "use Dmkit \ Phalcon \ Auth \ Middleware \ Micro as AuthMicro;" but I have the return: "Uncaught Error: Class 'Dmkit \ Phalcon \ Auth \ Middleware \ Micro' not found in /var/www/html/b9Back/public/index.php:63" Here is line 63: "$ auth = new AuthMicro ($ app, $ authConfig); "
Why we have to check if the JWT is valid if the URI is ignored already?
I was about to do a PR with the changes but I realized that you have done this on purpose.
Remove all HTML, js, and dirs that aren't part of the package.
Do you plan to make a php5.6 compatibility ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.