我暂时有了一个解决方案。。。。
auth.php配置文件
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
'app' => [
'driver' => 'passport',
'provider' => 'members',
]
]
...
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\Member::class,
],
'members' => [
'driver' => 'eloquent',
'model' => App\Models\Member::class
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
Models\User中
public function findForPassport($username) {
try {
return $this->where('phone', $username)->first();
}catch(\Exception $e) {
return Member::where('phone', $username)->first();
}
}
对应·\Laravel\Passport\Bridge\UserRepository·
···
public function getUserEntityByUserCredentials($username, $password, $grantType, ClientEntityInterface $clientEntity)
{
if (is_null($model = config('auth.providers.users.model'))) {
throw new RuntimeException('Unable to determine user model from configuration.');
}
if (method_exists($model, 'findForPassport')) {
$user = (new $model)->findForPassport($username);
} else {
$user = (new $model)->where('email', $username)->first();
}
if (! $user ) {
return;
} elseif (method_exists($user, 'validateForPassportPasswordGrant')) {
if (! $user->validateForPassportPasswordGrant($password)) {
return;
}
} elseif (! $this->hasher->check($password, $user->password)) {
return;
}
return new User($user->getAuthIdentifier());
}
···
你看我这样解决有什么隐患吗