sizeg / yii2-jwt

A simple Yii2 component to work with JSON Web Token and JSON Web Signature
https://jwt.io/
196 stars 85 forks source link

Token is empty #8

Closed pptyasar closed 6 years ago

pptyasar commented 7 years ago

$token->getClaims()and other functions are returning value but $token is empty

jpayne-cxp commented 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

HiepNinh commented 6 years ago

Can you tell me how to get full token. getPayload() just return header and payload but I want to return signature too. Thanks.

sizeg commented 6 years ago

@HiepNinh full token echo $token; or $var = (string) $token;

HiepNinh commented 6 years ago

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."

HiepNinh commented 6 years ago

Oop!!, my fault, I forgot sign(). It work properly. Thank @sizeg