GithubHelp home page GithubHelp logo

dmkit / phalcon-jwt-auth Goto Github PK

View Code? Open in Web Editor NEW
36.0 3.0 22.0 54 KB

Basic jwt authentication class for Phalcon framework

License: MIT License

PHP 100.00%
middleware phalcon-jwt phalcon jwt-authentication

phalcon-jwt-auth's Introduction

Hi there ๐Ÿ‘‹


I'm Dan. I also push code snippets to :octocat: Github gists.

Elixir Typescript Javascript Node.JS PHP

MySQL PostgreSQL MongoDB Elastic Search Redis

RabbitMQ

I'm on:

LINKEDIN PACKAGIST GMAIL

phalcon-jwt-auth's People

Contributors

dannyfeliz avatar dmkit avatar gabbanaesteban avatar jimjam88 avatar kaioken avatar quickshiftin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

phalcon-jwt-auth's Issues

Add the package to packagist.org

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 support for nbf field

Add nbf standard field to check method.
Not before (nbf): Identifies the time on which the JWT will start to be accepted for processing.

Missing License

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)

IgnoreUri regex match bug

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

Phalcon 4.x

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

Signature verification failed

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?

Error

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); "

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.