Search code examples
phpopentok

How to check expire token in opentok php?


I would like to confirm if there is other way to check the token of opentok expire? Only idea that I have is to send it an use the frontend api of opentok that will check the token, but I don't know it possible in php or the backend part.


Solution

  • You could decode the token and have a look at the expire time. You just need to remove the T1 part from the beginning of the token and then do a base64 decode. You'll end up with a string like:

    partner_id=<apiKey>&sig=<signature>:session_id=<sessionId>&create_time=<unix timestamp>&nonce=<random number>&role=moderator&expire_time=<unix timestamp>&initial_layout_class_list=
    

    Then you just need to pull out the expire_time from that string.

    Also, if in doubt why not just generate a new token? It's not actually a REST call to generate a new token, it's just a simple base64 encode and hashing function that happens locally so it's cheap to do.