hey guys, I'm having a problem with token generati...
# server-api
o
hey guys, I'm having a problem with token generation. I wrote the system myself in Swift to connect via live kit's server api. I've double and triple checked our api key and secret but I'm still getting a bad primitive message when I try and start a room instance. This is going from a client side web socket connection through a backend in vapor that connects directly to livekit.
r
Can I see a token you generated
o
sure, let me have the console log one. In the meantime this is the journalctl log snippet showing the error:
r
Also, is the clock on your device correct?
o
going to take just a few minutes, this is just a test backend instance so it takes like 10 minutes to rebuild but I just set it up to log the token output fro the generation method.
That's from last night, but, no. I believe 6 maps to 10pm central time
sorry, 5.
r
One common cause of that 401 error is a system clock that is not correct
o
oh it's using the time in the seed?
r
the token has a validity time frame. If you issue a token and the clock is not correct the validity range can fails when checked on the sever
o
oh, ok. when this rebuild finishes, I'll attempt to connect just to get you a token output but then I'll change the system clock on the vm and see if that changes anything.
r
You can decode the token here once you have it: http://yepher.com/livekit/validate_token.html
o
I hadn't done it because this is just the prototype backend so it's been quick and dirty in a lot of respects.
r
I am on a flight that will be landing soon so may have to drop soon.
o
ok, no worries. I'll keep working on it and if you disappear I'll know why.
So it comes back invalid via the yepher tool. using jwt.io I get valid token but invalid signature. Here's the token in question: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJBUElqajJhY0VBNU1QNnEiLCJleHAiOjE3NTkzNDA5OTUsImlhdCI6MTc1OTM0MDM5NSwic3ViIjoiQVBJamoyYWNFQTVNUDZxIiwidmlkZW8iOnsicm9vbUNyZWF0ZSI6dHJ1ZSwicm9vbVJlY29yZCI6dHJ1ZSwicm9vbUxpc3QiOnRydWUsInJvb21BZG1pbiI6dHJ1ZX19.ZXrqflq2HtPELpntx8_vPTML-6eEUp5VEEZcFSSGHl0
in the claims validator on jwt.io I get the correct API key in the iss and sub fields.
I found the issue. was missing one character from the secret in my environment file so the length was under 256b making it an invalid signature. Literally one character.