我是豆阮。
我是 Laravel 框架的初学者。所以我想建立一个网络服务 RestAPI(laravel 4.2)。我使用https://github.com/dingo/api和 oauth2 lucadegasperi/oauth2-server-laravel 来保护我的 api。但是当我完成所有配置文件并使用 Postman ( https://www.getpostman.com/ ) 发送请求时。
我有一个错误:
*ErrorException (E_UNKNOWN)
Argument 1 passed to Dingo\Api\Auth\LeagueOAuth2Provider::__construct() must be an instance of League\OAuth2\Server\ResourceServer, instance of LucaDegasperi\OAuth2Server\Authorizer given, called in /home/vagrant/Code/webservice/app/config/packages/dingo/api/config.php on line 110 and defined*
所以请帮我解决这个问题:)。这是我的配置文件:
应用程序\routes.php
Route::api('v1', function () {
Route::group(['prefix' => 'protected', 'protected' => true, 'providers' => 'oauth'], function () {
Route::post('user', function () {
$user = API::user();
return $user;
});
});
Route::group(['prefix' => 'unprotected', 'protected' => false], function () {
});
});
app\config\packages\dingo\api\config.php
'auth' => [
'basic' => function ($app) {
return new Dingo\Api\Auth\BasicProvider($app['auth']);
},
'oauth' => function ($app) {
$provider = new Dingo\Api\Auth\LeagueOAuth2Provider($app['oauth2-server.authorizer'], false);
$provider->setUserCallback(function($id) {
return User::find($id);
});
$provider->setClientCallback(function($id) {
return Client::find($id);
});
return $provider;
}
],
app\config\packages\lucadegasperi\oauth2-server-laravel\oauth2.php
'grant_types' => [
'password' => [
'class' => 'League\OAuth2\Server\Grant\PasswordGrant',
'access_token_ttl' => 604800,
// the code to run in order to verify the user's identity
'callback' => function($username, $password){
$credentials = [
'email' => $username,
'password' => $password,
];
if (Auth::once($credentials)) {
return Auth::user()->id;
} else {
return false;
}
}
],
],
这是我的问题:
ErrorException (E_UNKNOWN)
Argument 1 passed to Dingo\Api\Auth\LeagueOAuth2Provider::__construct() must be an instance of League\OAuth2\Server\ResourceServer, instance of LucaDegasperi\OAuth2Server\Authorizer given, called in /home/vagrant/Code/webservice/app/config/packages/dingo/api/config.php on line 110 and defined
请帮助我:),非常感谢:)