dusterio/lumen-passport:在 JWT 负载中传递自定义数据

aag*_*kaj 5 payload jwt laravel-passport passport-jwt

我正在使用lumen-passport进行身份验证和授权。当我解码 JWT 令牌时,我得到的有效负载如下:

{
  "aud": "9420abb1-1470-4895-8666-a702b415cb59",
  "jti": "03b55ab9d73953207a7e568657a1f83a9c5dcc0162b43fe4816c6086d30d4002b9bd74604ba99ea6",
  "iat": 1635781614.447866,
  "nbf": 1635781614.447872,
  "exp": 1635783414.409659,
  "sub": "1b910fc7-54bc-44ef-885b-869b2a095c11",
  "scopes": []
}
Run Code Online (Sandbox Code Playgroud)

sub是用户uuid。我想传递自定义数据以及sub如下所示。

{
  "aud": "9420abb1-1470-4895-8666-a702b415cb59",
  "jti": "03b55ab9d73953207a7e568657a1f83a9c5dcc0162b43fe4816c6086d30d4002b9bd74604ba99ea6",
  "iat": 1635781614.447866,
  "nbf": 1635781614.447872,
  "exp": 1635783414.409659,
  "sub": "1b910fc7-54bc-44ef-885b-869b2a095c11",
  "custom_data": "this is a custom data.",
  "scopes": []
}
Run Code Online (Sandbox Code Playgroud)

我如何在dusterio/lumen-passportlaravel/passport中实现这一点?

我生成令牌如下:

public function authenticateWithPassword(
        ServerRequestInterface $request,
        string $email,
        string $password,
        string $scope = ''
    ): Response {
        $newBody = [
            'grant_type' => 'password',
            'client_id' => $this->clientId,
            'client_secret' => $this->clientSecret,
            'username' => $email,
            'password' => $password,
            'scopes' => $scope,
        ];

        $newRequest = $request->withParsedBody($newBody);

        // We forward the request to Lumen's AccessTokenController since that does everything we want.
        return (App::make(AccessTokenController::class))->issueToken($newRequest);
    }
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的方法: