Closed pptyasar closed 6 years ago
You need to either echo $token
, or use $token->getPayload()
to get the actual token. I struggled wit that for a bit too. @pptyasar
Can you tell me how to get full token. getPayload() just return header and payload but I want to return signature too. Thanks.
@HiepNinh full token echo $token;
or $var = (string) $token;
It didn't work for me. Here is my code $signer = new Sha256(); //Generate token $token = Yii::$app->jwt->getBuilder()->setIssuer(Yii::$app->params['issuer']) ->setId(Yii::$app->params['token_id'], true) ->setIssuedAt(time()) ->setExpiration(time() + Yii::$app->params['expired_time']) ->set('username', $params['username']) ->set('password', $params['password']) ->getToken(); // Retrieves the generated token
return (string)$token;
I'm using postman to post API and I just receive "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIiwianRpIjoiaXF1YWhDYWg3YXUifQ.eyJpc3MiOiJhcGkuY2h1eWVudGllbm5oYW5oMjRoLmxvY2FsIiwianRpIjoiaXF1YWhDYWg3YXUiLCJpYXQiOjE1MjIxNDgxOTMsImV4cCI6MTUyMjE1MTc5MywidXNlcm5hbWUiOiJhZG1pbiAiLCJwYXNzd29yZCI6IjEyMzQ1NiJ9."
Oop!!, my fault, I forgot sign(). It work properly. Thank @sizeg
$token->getClaims()
and other functions are returning value but$token
is empty