Php Laravel Passport-通过客户id获取客户机密
我有oauth_客户端的客户端id,需要获取机密。Php Laravel Passport-通过客户id获取客户机密,php,laravel,laravel-passport,Php,Laravel,Laravel Passport,我有oauth_客户端的客户端id,需要获取机密。 由于secret属性受保护,因此无法进行普通模型查询或DB查询。如果您知道oauth\u客户机的id,则可以访问客户机id和客户机机密: /** * DefaultController constructor. */ public function __construct() { $this->client = DB::table('oauth_clients')->where('
由于secret属性受保护,因此无法进行普通模型查询或DB查询。如果您知道
oauth\u客户机的id,则可以访问客户机id
和客户机机密
:
/**
* DefaultController constructor.
*/
public function __construct()
{
$this->client = DB::table('oauth_clients')->where('id', 2)->first();
}
/**
* @param Request $request
* @return mixed
*/
protected function authenticate(Request $request)
{
$request->request->add([
'username' => $request->username,
'password' => $request->password,
'grant_type' => 'password',
'client_id' => $this->client->id,
'client_secret' => $this->client->secret,
'scope' => '*'
]);
$proxy = Request::create(
'oauth/token',
'POST'
);
return Route::dispatch($proxy);
}
如果您知道oauth\u客户端
id,则可以访问client\u id
和client\u secret
:
/**
* DefaultController constructor.
*/
public function __construct()
{
$this->client = DB::table('oauth_clients')->where('id', 2)->first();
}
/**
* @param Request $request
* @return mixed
*/
protected function authenticate(Request $request)
{
$request->request->add([
'username' => $request->username,
'password' => $request->password,
'grant_type' => 'password',
'client_id' => $this->client->id,
'client_secret' => $this->client->secret,
'scope' => '*'
]);
$proxy = Request::create(
'oauth/token',
'POST'
);
return Route::dispatch($proxy);
}
$this->client->secret
不可能,因为这个秘密是受保护的属性。我已经粘贴了一个在我的Laravel 5.5项目中工作的实际代码,试试看,它应该可以工作。id在构造函数中是硬编码的,此时我还没有id,因为我在某处使用了某种方法…@Ardit,正如您在构造函数中看到的那样,我从数据库中查询,所以您可以在任何地方执行此操作来强制转换客户机对象,然后访问属性。你的宠物是什么?请添加更多信息以理解问题,并尝试提供更好的答案。我使用的代码如下$client=DB::table('oauth_clients')->where('id',$apiUser)->first()$clientSecret=$client->secret代码>和工程伟大!非常感谢,$this->client->secret
是不可能的,因为这个秘密是一个受保护的属性。我已经粘贴了一个在我的Laravel 5.5项目中工作的实际代码,试试看,它应该可以工作。id在构造函数中是硬编码的,此时我还没有id,因为我在某处使用了某种方法…@Ardit,正如您在构造函数中看到的那样,我从数据库中查询,所以您可以在任何地方执行此操作来强制转换客户机对象,然后访问属性。你的宠物是什么?请添加更多信息以理解问题,并尝试提供更好的答案。我使用的代码如下$client=DB::table('oauth_clients')->where('id',$apiUser)->first()$clientSecret=$client->secret代码>和工程伟大!非常感谢