Php 如何使JWTAuth服务于不同的用户类型?
我使用以下工作方法登录用户:Php 如何使JWTAuth服务于不同的用户类型?,php,authentication,laravel-5,jwt,token,Php,Authentication,Laravel 5,Jwt,Token,我使用以下工作方法登录用户: // Authenticate Business User public function authBU() { $this->validate( request(), [ 'provider' => 'required', 'token' => 'required', ] ); $user = JWTAuth::authenticate(request( 'token' ))
// Authenticate Business User
public function authBU() {
$this->validate( request(), [
'provider' => 'required',
'token' => 'required',
] );
$user = JWTAuth::authenticate(request( 'token' ));
return $this->buildItemResponse( $user, new UserLoginTransformer() );
}
它从User
表返回,但是,我需要它查看BusinessUser
表
我已经在auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'business_api' => [
'driver' => 'passport',
'provider' => 'business_users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => \App\Services\Users\User::class,
],
'business_users' => [
'driver' => 'eloquent',
'model' => \App\Services\Users\BusinessUser::class,
],
],
如何获取JWTAuth::authenticate(请求('token')是否返回业务用户
,而不编辑供应商代码
这是JWTAuth.php中的方法
/**
* Authenticate a user via a token.
*
* @param mixed $token
*
* @return mixed
*/
public function authenticate($token = false)
{
$id = $this->getPayload($token)->get('sub');
if (! $this->auth->byId($id)) {
return false;
}
return $this->auth->user();
}
您需要指定
防护
@AnilJaiswal您能提供答案吗?