anandpilania/f3-token-middleware

Token Auth Middleware for FatFreeFramework.

v0.0.4 2019-08-14 11:47 UTC

This package is auto-updated.

Last update: 2020-10-14 14:34:40 UTC


README

Just pass your token secure routes [/ OR '/secure/*'] & handler to f3-token-middleware & relax... it will check requests pattern + token & execute your handler if token not found.

NOTE: This package built/ported from ikkez/f3-middleware.

CHECK example.file for sample

Install

  `composer require anandpilania/f3-token-middleware`

## Usage

  • 1: Configure f3:

    `$f3->mset(array(
    
        'TOKEN' => array(
      	  'TYPE' => 'HEADER', // HEADER|QUERY
      	  
            'KEY' => 'Authorization', // TOKEN KEY
            
            'STARTS_WITH' => 'X-Auth-Token', // TOKEN KEY STARTS WITH (supports only HEADER type) -> "Authorization: X-Auth-Token xxxxxxxx"
            
            'TABLE' => 'Models\Token', // FQCN
            
            'TABLE_KEY' => 'token' // KEY, which you used to store the token value in table
            
        )
        
    ));`
    
  • 2: Initialize in your main bootstrap file:

    `$tokenMiddleware = new TokenMiddleware();`
    
  • 3: Protect routes/pattern:

    `$tokenMiddleware->protect(array('GET|POST|PUT|DELETE /home/*', 'POST /profile'), function($f3, $params, $alias) {
    
        // YOUR FUNCTION, IF 'TOKEN' NOT SUPPLIED
        
    });`
    
  • 4: RUN:

    `$tokenMiddleware->run();`