目前我使用Laravel Passport进行Laravel安装(league/oauth2-server用于服务器实现).我想在授予oauth2令牌时返回用户ID,因此我可以使用它来识别我的EmberJS应用程序中经过身份验证的用户.
建议的方法是:
创建我自己的类:
use League\OAuth2\Server\ResponseTypes\BearerTokenResponse;
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
class UserIdBearerTokenResponse extends BearerTokenResponse
{
protected function getExtraParams(AccessTokenEntityInterface $accessToken)
{
return [
'user_id' => $this->accessToken->getUserIdentifier()
];
}
}
Run Code Online (Sandbox Code Playgroud)
修改AuthorizationServer.getResponseType()中vendor/league/oauth2-server/src
protected function getResponseType()
{
if ($this->responseType instanceof ResponseTypeInterface === false) {
// Return my own class instead of provided one
$this->responseType = new UserIdBearerTokenResponse();
}
$this->responseType->setPrivateKey($this->privateKey);
return $this->responseType;
}
Run Code Online (Sandbox Code Playgroud)
但是这种方法要求我将vendor/league/oauth2-server/src/AuthorizationServer.php文件添加到我的git repo中.
这对我来说似乎非常混乱和不可靠.是否有更好/更清洁的方法来实现这一目标?