JWTAuth error on setting user.
Whenever I set a user, I get an error code 5 with the message JWTAuth error: json: cannot unmarshal object into Go struct field StreamJWTClaims.exp of type int64. I have no idea what could be the cause or how I can resolve it. I believe I'm using a valid token because I'm making the request to get the token and use the tokenSuccessListener.onSuccess to get my token while setting the user. Any idea how I can resolve this?
@tbarbugli
@Chikrix can you share the token here? you can redact a token by stripping out the last section of the token.
somevery.weirdbase64.token -> somevery.weirdbase64.
also, it would be great if you could share the code you used to generate the token. Looking at the error I'd say something is off with the exp field
@tbarbugli
Here's my auth token eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMjg0LTExNjk5MTcxIiwiZXhwIjp7ImRhdGUiOiIyMDE5LTEwLTIyIDEzOjM2OjI4LjkxNzI0NCIsInRpbWV6b25lX3R5cGUiOjMsInRpbWV6b25lIjoiQW1lcmljYVwvRGVudmVyIn19.
here's my code snippet
/**
* This uses Get Stream Client Library to hit their services
* @param array $user
* @return string
* @throws StreamChatServiceException
* @throws \GetStream\StreamChat\StreamException
*/
public function addUser(array $user): string
{
if (empty($user)) {
throw new StreamChatServiceException("A valid user is required");
}
$this->getStreamChat->updateUser($user);
// with an expiration time
$expiration = (Carbon::now()->addMinutes(1440));
$userToken = $this->getStreamChat->createToken($user['id'], $expiration);
return $userToken;
}
The above calls the following method from https://github.com/GetStream/stream-chat-php
/**
* @param string $userId
* @param array $extraData
* @return string
*/
public function createToken($userId, $expiration=null)
{
$payload = [
'user_id' => $userId,
];
if($expiration !== null){
$payload['exp'] = $expiration;
}
return JWT::encode($payload, $this->apiSecret, 'HS256');
}
@Chikrix exp must be a timestamp (ie. something like this Carbon::now()->addMinutes(1440)->timestamp) ; @pterk can you add docs and a test to the PHP client?
Thanks @tbarbugli . Would try that.
FTR, a note, a check and a test were added to the PHP client so it should be easier to debug this in future.