I am using JWT Token Authentication with lexik/jwt-authentication-bundle version 2.18.1. I have an API and my complete user information is stored in the JWT token I get from an external system. The information is an multidimensional array with the user identifier "uid" being stored in the user.
Example:
{
"application": {
"appcode": "my_app"
},
"user": {
"uid": "p320666",
"firstname": "John",
"mail": "John.Doe.com",
"lastname": "Doe"
},
"grants": [
"create"
],
"resources": [
{
"code": "foo",
"values": [
"5"
]
}
],
"updateDate": {}
}
My user identifier is uid and it is in the 2nd level of my information array.
If I set in my configuration user_id_claim: user I get understandably the warning:
Array to string conversion because in JWTAuthenticator.php
$passport = new SelfValidatingPassport(
new UserBadge(
(string)$payload[$idClaim],
function ($userIdentifier) use ($payload) {
return $this->loadUser($payload, $userIdentifier);
}
)
);
it tries to read my user array as a string.
If I set uid in my configuration it isn't found. user.uid also doesn't work.
Is there an option to access my uid information without changing the structure of the payload?
I solved it now by writing a custom authenticator:
security.yaml
services.yaml
lexik_jwt_authentication.yaml
and finally my custom authenticator where I changed the line
(string) $payload[$idClaim]['uid'],and also call an extra class TokenDataProcessor to extract my complete user info from the payload: