4

I am using lumen-passport for authentication and authorization. When I decode the JWT token I get payload as below:

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

sub is the user uuid. I want to pass custom data along with the sub as below.

{
  "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": []
}

How I can achieve this in dusterio/lumen-passport or laravel/passport?

I am generating token as below:

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);
    }

I tried different approaches:

aagjalpankaj
  • 1,160
  • 1
  • 15
  • 25

0 Answers0