dusterio / lumen-passport

Making Laravel Passport work with Lumen
MIT License
654 stars 139 forks source link

Lumen passport custom data in payload #165

Closed aagjalpankaj closed 2 years ago

aagjalpankaj commented 2 years ago

How to pass custom data (like user_id, roles, etc) in payload along with sub?

dusterio commented 2 years ago

Do you mean to include extra data in the JWT token itself, in its JSON payload?

aagjalpankaj commented 2 years ago

@dusterio - Yes.

aagjalpankaj commented 2 years ago

@dusterio - e.g.

{
  "aud": "9420abb1-1470-4895-8666-a702b415cb59",
  "jti": "1dd56723fa5ac4421ebb7cb9a0222686f368de22760d9ac7038b8a3a696ac12069b84e2434ea9d75",
  "iat": 1635772661.715073,
  "nbf": 1635772661.71508,
  "exp": 1635774461.676158,
  "sub": "8707e4a1-a920-40dc-a472-b71b62343dca",
  "user_id": 123,
  "sites": { "78": 1, "60": 3 }
  "scopes": []
}

In the above payload "user_id" & "sites" is the custom data. How to pass such custom data using this package? We can do this in "tymon/jwt-auth" - https://medium.com/geekculture/restrict-jwt-token-with-ip-address-using-laravel-77ce5ae3671a

fcirone commented 2 years ago

@dusterio +1. Any way to achieve it?

dusterio commented 2 years ago

I think there are some examples at the end of this thread: https://github.com/laravel/passport/issues/94