尝试获取经过身份验证的用户时出错
Getting error trying to get authenticated user
使用dingo/api along with lucadegasperi/oauth2-server-laravel。对用户进行身份验证没问题,我得到了一个访问令牌,但每当我发出另一个请求时,我都会收到以下错误:
call_user_func() expects parameter 1 to be a valid callback, no array or string given
我正在使用 dingo/api 文档中列出的 Service Provider option,它肯定会设置用户解析器(我 var_dump 在 setUserResolver 方法中设置了解析器)。
下面是我的 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()
{
//
}
}
事实证明我完全不在我正在看的地方。在 config/api.php 中,在我的身份验证设置中我有
'oauth2' => Dingo\Api\Auth\Provider\OAuth2::class,
应该是
'oauth' => Dingo\Api\Auth\Provider\OAuth2::class,
使用dingo/api along with lucadegasperi/oauth2-server-laravel。对用户进行身份验证没问题,我得到了一个访问令牌,但每当我发出另一个请求时,我都会收到以下错误:
call_user_func() expects parameter 1 to be a valid callback, no array or string given
我正在使用 dingo/api 文档中列出的 Service Provider option,它肯定会设置用户解析器(我 var_dump 在 setUserResolver 方法中设置了解析器)。
下面是我的 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()
{
//
}
}
事实证明我完全不在我正在看的地方。在 config/api.php 中,在我的身份验证设置中我有
'oauth2' => Dingo\Api\Auth\Provider\OAuth2::class,
应该是
'oauth' => Dingo\Api\Auth\Provider\OAuth2::class,