createCustomToken method response empty {}
phuongphally opened this issue · comments
Phuong Phally (ភួង ផល្លី) commented
I try to create custom token with https://firebase-php.readthedocs.io/en/5.x/authentication.html#id2 in Laravel project by write code below.
$auth = Firebase::auth();
$token = $auth->verifyIdToken($token);
$uid = $token->claims()->get('sub');
$user = $auth->getUser($uid);
$additionalClaims = [
'nationality' => 'kh',
];
if($user) {
$customToken = $auth->createCustomToken($user->uid, $additionalClaims);
}
- If I return response json
$user
it is display object user likes
{
"uid": "oR58AIcn3TS69CL..........",
"email": "...........@gmail.com",
"emailVerified": false,
"displayName": null,
"photoUrl": null,
"phoneNumber": null,
"disabled": false,
"metadata": {
"createdAt": "2021-03-25T06:05:56+00:00",
"lastLoginAt": "2021-03-25T10:04:09+00:00",
"passwordUpdatedAt": {
"date": "2021-03-25 06:05:56.899000",
"timezone_type": 3,
"timezone": "UTC"
},
"lastRefreshAt": {
"date": "2021-03-25 10:04:11.653000",
"timezone_type": 3,
"timezone": "UTC"
}
},
"providerData": [
{
"uid": "...@gmail.com",
"displayName": null,
"email": "..@gmail.com",
"photoUrl": null,
"providerId": "password",
"phoneNumber": null
}
],
"passwordHash": "....",
"passwordSalt": null,
"customClaims": [],
"tokensValidAfterTime": "2021-03-25T06:05:56+00:00",
"tenantId": null
}
But when use $customToken
it response empty json body
{}
If I try to cast to string $customTokenString = (string) $customToken
it error like below
Error
Object of class Lcobucci\JWT\Token\Plain could not be converted to string
Please help me
Jérôme Gamez commented
$customTokenString = $customToken->toString();
should work. Thank you for bringing this up, the documentation needs an update to reflect the different usages depending on the installed version of lcobucci/jwt
, will do this right after writing this comment ^^.
Jérôme Gamez commented
Here it is kreait/firebase-php@8b45c07