【发布时间】:2020-01-23 06:17:24
【问题描述】:
我正在使用护照登录(在 API 中)我正在尝试获取身份验证服务器生成的令牌。但是,我无法向作为 FormRequest 实例的请求添加额外参数。
另一方面,如果我将请求更改为Request 的实例,它会起作用。
所以,我的问题是如何将参数添加到我的查询 $loginRequest(这是 FormRequest 的实例)
$loginRequest->request->add($params);
这是我的代码:
class AuthController extends Controller
{
use ThrottlesLogins;
public function store(LoginRequest $loginRequest)
{
$loginRequest->validated();
if ($this->hasTooManyLoginAttempts($loginRequest)) {
$this->fireLockoutEvent($loginRequest);
return $this->sendLockoutResponse($loginRequest);
}
if (Auth::attempt($this->credentials($loginRequest))){
$client = $this->getClient($loginRequest->name);
$params = [
'grant_type' => 'password',
'client_id' => $client->id,
'client_secret' => $client->secret,
'username' => $loginRequest->email,
'password' => $loginRequest->password,
'scopes' => 'fd',
];
$loginRequest->request->add($params);
$req = Request::create('oauth/token', 'POST');
$response = Route::dispatch($req)->getContent();
return $response;
}
$this->incrementLoginAttempts($loginRequest);
$this->sendFailedLoginResponse($loginRequest);
}
}
【问题讨论】:
-
刚刚检查,在自定义表单请求中使用
add()没有问题。 -
额外的参数没有加起来,我知道这是因为我有一个服务器错误 oauth @Harven
-
服务器 oauth 错误不能证明
add()不起作用。尝试在调用add()方法后立即转储$login->request并手动检查。 -
参数加好了,为什么我的oauth服务器收不到这些参数?
标签: php laravel oauth request laravel-6