Php 使用FormRequest在调度时获取令牌访问权
我使用Php 使用FormRequest在调度时获取令牌访问权,php,laravel,authentication,laravel-passport,Php,Laravel,Authentication,Laravel Passport,我使用formRequest的实例作为参数创建登录,一旦验证了用户的访问,我就向请求中添加需要oauth服务器的参数 但是,我从服务器oauth收到一个错误: { "error": "unsupported_grant_type", "error_description": "The authorization grant type is not supported by the authorization server.", "hint": "Check that al
formRequest
的实例作为参数创建登录,一旦验证了用户的访问,我就向请求中添加需要oauth服务器的参数
但是,我从服务器oauth收到一个错误:
{
"error": "unsupported_grant_type",
"error_description": "The authorization grant type is not supported by the authorization server.",
"hint": "Check that all required parameters have been provided",
"message": "The authorization grant type is not supported by the authorization server."
}
但是,当我将参数的实例更改为Request时,我不再得到这个错误
复制步骤:
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);
}
}
尝试将内容类型application/x-www-form-urlencoded作为头添加到对“oauth/token”的请求中
$req = Request::create('oauth/token', 'POST');
$req->headers->set('Content-Type', 'application/x-www-form-urlencoded');
$response = Route::dispatch($req)->getContent();
很抱歉,我无法回答您的问题,但您知道您可以像这样为用户创建令牌:
$token=$user->createToken('My token',['scope-1'])->accessToken代码>?是的,我知道,但是我们可以做一个刷新令牌吗?(使用此方法)@DelenaMalanIt不起作用。我通过使用HasApiTokens特性的createToken
方法生成一个访问令牌并能够继续,从而劫持了这个问题。