我使用超薄框架,試圖實現slim token authentication中間件,現在每當我去Error類應用程序驗證未發現 - 超薄框架V3中間件
本地主機/項目/限制
我得到消息「令牌未找到」似乎工作正常,但是當我嘗試通過授權參數中的令牌按照中間件documentation
的locahost /項目/限制?授權= usertokensecret
我總是得到錯誤級 '應用程序\驗證' 未找到和我的錯誤追查之下,
0 /應用/ AMPPS/WWW /project/vendor/dyorg/slim-token-authentication/src/TokenAuthentication.php(66): {閉合}(對象(超薄\ HTTP \請求), 對象(超薄\中間件\ TokenAuthentication))
1 [內部函數]:Slim \ Middleware \ TokenAuthentication - > __ invoke(Object(Slim \ Http \ Request), 對象(超薄\ HTTP \響應),對象(超薄\ APP))
2 /Applications/AMPPS/www/project/vendor/slim/slim/Slim/DeferredCallable.php(43): call_user_func_array(對象(超薄\中間件\ TokenAuthentication) 陣列)
3內部功能]:超薄\ DeferredCallable - > __調用(對象(超薄\ HTTP \請求), 對象(超薄\ HTTP \響應),對象(超薄\ APP))
4 /Applications/AMPPS/www/project/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(73): call_user_func(對象(超薄\ DeferredCallable) 的OBJ ECT(超薄\ HTTP \請求),對象(超薄\ HTTP \響應), 對象(超薄\ APP))
5 /應用/ AMPPS/WWW /項目/供應商/超薄/超薄/超薄/ MiddlewareAwareTrait。 PHP(122): 超薄\ APP->超薄{閉合}(對象(超薄\ HTTP \請求), 對象(超薄\ HTTP \響應))
6 /應用/ AMPPS /網絡/項目/供應商/slim/slim/Slim/App.php(370):Slim \ App-> callMiddlewareStack(Object(Slim \ Http \ Request), Object(Slim \ Http \ Response))
7/Applications/AMPPS/www/project/vendor/slim/slim/Slim/App.php(295):Slim \ App-> process(Object(Slim \ Http \ Request), 對象(超薄\ HTTP \響應))
8 /Applications/AMPPS/www/project/index.php(81):苗條\ APP->的run()
9 {主}
這裏的代碼我使用
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require_once './vendor/autoload.php';
$app = new \Slim\App;
use Slim\App;
use Slim\Middleware\TokenAuthentication;
$config = [
'settings' => [
'displayErrorDetails' => true
]
];
$app = new App($config);
$authenticator = function($request, TokenAuthentication $tokenAuth){
$token = $tokenAuth->findToken($request);
$auth = new \app\Auth();
$auth->getUserByToken($token);
};
/**
* Add token authentication middleware
*/
$app->add(new TokenAuthentication([
'path' => '/restrict',
'authenticator' => $authenticator
]));
/**
* Public route example
*/
$app->get('/', function($request, $response){
$output = ['msg' => 'It is a public area'];
$response->withJson($output, 200, JSON_PRETTY_PRINT);
});
/**
* Restrict route example
* Our token is "usertokensecret"
*/
$app->get('/restrict', function($request, $response){
$output = ['msg' => 'It\'s a restrict area. Token authentication works!'];
$response->withJson($output, 200, JSON_PRETTY_PRINT);
});
$app->run();
?>
類'\ app \ Auth'是否存在?我們可以看到那個類和'composer.json'。 – meun5
@ meun5我通過作曲家安裝了庫,我想將它移動到苗條的文件夾? – jdoe1991
您是否創建了'\ app \ Auth'或者它是與作曲家一起安裝的庫? – meun5