在passport v10以上已经移除了相关设置接口,我们可以重写createToken方法实现指定客户端ID
public function createToken($name, array $scopes = [])
{
$clients = new ClientRepository('9466f475-de2d-47fc-9f14-ec8c1fed7f8d');
$pr = Container::getInstance()->make(PersonalAccessTokenFactory::class);
$refObject = new \ReflectionObject($pr);
$refProperty = $refObject->getProperty( 'clients' );
$refProperty->setAccessible( true );
$refProperty->setValue($pr, $clients);
return $pr->make(
$this->getKey(), $name, $scopes
);
}
因为客户端在初始化已经被注入容器,只能通过反射去修改它.