尝试获取经过身份验证的用户时出错

时间:2015-11-26 17:44:34

标签: php laravel oauth-2.0 dingo-api

使用dingo/apilucadegasperi/oauth2-server-laravel。验证用户是好的,我得到一个访问令牌,但每当我发出另一个请求时,我都会收到以下错误:

call_user_func() expects parameter 1 to be a valid callback, no array or string given

我使用了dingo / api文档中列出的Service Provider option,并且它肯定会设置用户解析器(我在setUserResolver方法中设置了var_dump' d解析器)。

我的OauthServiceProvider在下面。

<?php namespace App\Providers;
use Dingo\Api\Auth\Auth;
use Dingo\Api\Auth\Provider\OAuth2;
use App\User\User;
use Illuminate\Support\ServiceProvider;

class OAuthServiceProvider extends ServiceProvider
{
    public function boot()
    {
        $this->app[Auth::class]->extend('oauth', function ($app) {
            $provider = new OAuth2($app['oauth2-server.authorizer']->getChecker());

            $provider->setUserResolver(function ($id) {
                return User::first();
                // Logic to return a user by their ID.
            });

            $provider->setClientResolver(function ($id) {
                // Logic to return a client by their ID.
            });

            return $provider;
        });
    }

    public function register()
    {
        //
    }
}

1 个答案:

答案 0 :(得分:2)

事实证明我完全离开了我正在寻找的地方。在config / api.php中,在我的身份验证设置中,我有

        'oauth2' => Dingo\Api\Auth\Provider\OAuth2::class,

应该刚刚

        'oauth' => Dingo\Api\Auth\Provider\OAuth2::class,