Open parvinshi opened 4 years ago
public function guard($name = null)
{
$name = $name ?: $this->getDefaultDriver();
return $this->guards[$name] ?? $this->guards[$name] = $this->resolve($name);
}
我也遇到了同样的问题,尝试设置 config('auth.defaults.guard', 'api'); 或者 auth(‘api’) 都没用。
我也遇到了同样的问题,尝试设置 config('auth.defaults.guard', 'api'); 或者 auth(‘api’) 都没用。
$this->auth->parseToken()->authenticate()的$this->auth就是auth(),也可以写成auth()->parseToken()->authenticate(),默认解析的是auth.php配置下的defaults数组的guard键对应的Authentication Guards,laravel默认是'web',然后通过guards数组找到身份认证使用的provider model。你把defaults配置数组的guard值改为'api',provider对应providers配置数组的model对应好,然后再试试
我也遇到了同样的问题,尝试设置 config('auth.defaults.guard', 'api'); 或者 auth(‘api’) 都没用。
这个包里面对laravel的Auth进行了扩展,具体代码如下:
protected function extendAuthGuard()
{
$this->app['auth']->extend('jwt', function ($app, $name, array $config) {
$guard = new JWTGuard(
$app['tymon.jwt'],
$app['auth']->createUserProvider($config['provider']),
$app['request']
);
$app->refresh('request', $guard, 'setRequest');
return $guard;
});
}
这里$this->app['auth']就是上面说的$this->auth、auth()或者Auth::guard(),它进行的拓展是在laravel的auth.php中defaults配置数组guard值基础上,如果默认为web,自己定义的jwt如果和默认web定义的provider model不一样就会找不到认证的用户
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
When config('auth.defaults.guard') is 'web', the authenticate() method in middleware returns false, But when changing 'auth.defaults.guard ' to 'api', $this->auth->parseToken()->authenticate() in middleware returns user model
Your environment