用于dingo / api的Config oauth2 Laravel 4.2传递了参数1的错误

时间:2015-03-27 04:04:05

标签: laravel oauth-2.0 dingo-api

我是BeanNguyen。

我是Laravel框架的初学者。所以我想构建一个Web服务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 () {

    });
});

应用\设置\包\野狗\ 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;
        }
    ],

应用\设置\包\ lucadegasperi \的oauth2 - 服务器 - 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

请帮帮我:),非常感谢你:)

1 个答案:

答案 0 :(得分:0)

我的配置(app \ config \ packages \ dingo \ api \ config.php)看起来像这个,与你的完全不同。在Laravel 4.2上。

'auth' => [
        'oauth' => function ($app) {
            $provider = new Dingo\Api\Auth\LeagueOAuth2Provider($app['oauth2-server.authorizer']->getChecker());

            $provider->setUserResolver(function ($id) {
                return User::find($id);
            });

            $provider->setClientResolver(function ($id) {
                return Client::find($id);
            });

            return $provider;
        }
    ]