簡単に行うことができます。 \ ベンダーにあるファイルBearerTokenResponse.php を開きリーグの\のOAuth2-サーバー\ SRC \ ResponseTypesこのような
方法generateHttpResponse(ResponseInterfaceの$応答)を変更し:
public function generateHttpResponse(ResponseInterface $response)
{
$expireDateTime = $this->accessToken->getExpiryDateTime()->getTimestamp();
$jwtAccessToken = $this->accessToken->convertToJWT($this->privateKey);
$responseParams = [
'token_type' => 'Bearer',
'expires_in' => $expireDateTime - (new \DateTime())->getTimestamp(),
'access_token' => (string) $jwtAccessToken,
'user' => User::find($this->accessToken->getUserIdentifier()),
];
if ($this->refreshToken instanceof RefreshTokenEntityInterface) {
$refreshToken = $this->encrypt(
json_encode(
[
'client_id' => $this->accessToken->getClient()->getIdentifier(),
'refresh_token_id' => $this->refreshToken->getIdentifier(),
'access_token_id' => $this->accessToken->getIdentifier(),
'scopes' => $this->accessToken->getScopes(),
'user_id' => $this->accessToken->getUserIdentifier(),
'expire_time' => $this->refreshToken->getExpiryDateTime()->getTimestamp(),
]
)
);
$responseParams['refresh_token'] = $refreshToken;
}
$responseParams = array_merge($this->getExtraParams($this->accessToken), $responseParams);
$response = $response
->withStatus(200)
->withHeader('pragma', 'no-cache')
->withHeader('cache-control', 'no-store')
->withHeader('content-type', 'application/json; charset=UTF-8');
$response->getBody()->write(json_encode($responseParams));
return $response;
}
ドンApp \ Userモデルを使用することを忘れないでください。
私はこれがあなたに役立つことを願っています。
[Custom Laravel Passport BearerTokenResponse](https://stackoverflow.com/questions/39743020/custom-laravel-passport-bearertokenresponse)の可能な複製 – simonhamp