1. Go to this page and download the library: Download veasin/ff-web library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use function ff\web\user\jwt;
container('#user.default', user\jwt('my-secret-key'));
container('#user.default', user\jwt('my-secret-key', ttl: 3600, algo: 'HS256'));
use function ff\web\middleware\{cors, serve, json};
use function ff\web\middleware\auth\{basic, token, jwt, apikey};
use function ff\web\middleware\{csrf, error, gzip, log as mw_log, rate};
middleware(cors(), basic(), log(), $handler);
use function ff\web\middleware\auth\basic;
container('#web/auth/validators', [fn($user, $pass) => $user]);//设置验证器
middleware(basic(), $handler);//使用中间件
container('#web/auth/user');//获取认证用户
use function ff\web\middleware\auth\token;
container('#web/auth/validators', [fn($token) => $user]);//设置验证器
middleware(token(), $handler);//使用中间件,从 Authorization 头提取
middleware(token('#web/auth', 'X-Auth-Token'), $handler);//自定义请求头
use function ff\web\middleware\auth\jwt;
container('#web/auth/secret', 'your-secret-key');//设置 HMAC 签名密钥
container('#web/auth/validators', [fn($payload) => $user]);//设置验证器
middleware(jwt(), $handler);//使用中间件
container('#web/auth/payload');//获取解码后的 JWT payload
container('#web/auth/user');//获取认证用户
use function ff\web\middleware\auth\apikey;
container('#web/auth/validators', [fn($apiKey) => $user]);//设置验证器
middleware(apikey(), $handler);//使用中间件