Skip to content

1056ng/Aeacus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phalcon JWT Authentication Plugin

A simple plugin to authenticate JWT from Request in PHP with firebase/php-jwt.

Installation

Use composer to manage your dependencies and download:

{
    "repositories": [
      {
        "type": "vcs",
        "url": "https://github.com/1056ng/Aeacus"
      }
    ],
    "require": {
      "1056ng/Aeacus": "~1.0"
    }
}

Example

setup

$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach('authorization', new \Aeacus\Middleware($di));
$app->setEventsManager($eventsManager);

check

function beforeExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\Di\Injectable $injectable) {
  $publicKeys = [
    'kid1' => 'jwt.token.aaaa',
    'kid2' => 'jwt.token.bbbb'
  ];

  $di = $this->getDi();

  // check JWT from request
  $di->getEventsManager()->fire(\Aeacus\EventKeys::check, $injectable, $publicKeys);

  // get decoded jwt token
  $decodedToken = $di->get(\Aeacus\ServiceKeys::decodedToken);
}