Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/anandpilania/f3-token-middleware

Token authentication middleware for FatFreeFramework
https://github.com/anandpilania/f3-token-middleware

f3 f3-auth f3-middleware fatfree-framework secure-api token-authetication

Last synced: about 1 month ago
JSON representation

Token authentication middleware for FatFreeFramework

Awesome Lists containing this project

README

        

# f3-token-middleware

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](https://github.com/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();`