pusher / chatkit-server-ruby

Ruby server SDK for Chatkit
https://pusher.com/chatkit
MIT License
12 stars 11 forks source link

Error "Could not parse the token" when should be improper arguments #17

Closed shrugs closed 6 years ago

shrugs commented 6 years ago

What?

Running:

chatkit.get_user_rooms({ id: 2640 })

gives you:

PusherPlatform::ErrorResponse: PusherPlatform::ErrorResponse - status: 401 description: Could not parse the token. Find out more at https://docs.pusher.com/errors/authentication/jwt/invalid

but since user ids are supposed to be strings, I'd expect an error closer to not being able to understand the query params.

hamchapman commented 6 years ago

The 401 here suggests that your instance locator or key are invalid / improperly formatted. Have you checked that you've copied them from the dashboard exactly as they appear?

The instance locator should be something like: v1:us1:abc-def-ghi-jkl and the key should be something like: asjdkiubg91bg81n:jknav=10-2fn1uin1

Note the two :s in the locator and single : in the key

shrugs commented 6 years ago

Yup! the same line, but with a string key chatkit.get_user_rooms({ id: '2640' }) works within the same rails console instance

shrugs commented 6 years ago

It feels like the backed is throwing on type conversion but somehow attributing the parsing incorrectly

hamchapman commented 6 years ago

Ah yep, okay I've spotted it. So the user ID you pass in via id to the get_user_rooms call was being used as the subject of the token without any stringifying going on, hence the token error (as we expect the subject to be a string).

I've fixed this as part of #16

Thanks!

vivek1395068 commented 5 years ago

const chatManager= new Chatkit.ChatManager({ instanceLocator:"v1:us1:xyz", userId:"HK", tokenProvider:new Chatkit.TokenProvider({ url:"http://localhost:8081/authenticate" }) }); chatManager.connect().then((currentUser)=>{ console.log("current User",currentUser)}) .catch((error)=>{ console.error(error)})

while running the above code from the client

to the node/express server:- app.post("/authenticate",(req,res)=>{ const {grant_type}=req.body; res.json(chatkit.authenticate({grant_type,userId:req.query.user_id})); });

throws an error:-

Logger.ERROR: error establishing presence subscription: Could not parse the token. More information can be found at https://docs.pusher.com/errors/authentication/jwt/invalid. Error object: {…} headers: Object { "Request-Method": "SUBSCRIBE" } info: {…} error: "authentication/jwt/invalid" error_description: "Could not parse the token" error_uri: "https://docs.pusher.com/errors/authentication/jwt/invalid" proto: Object { … } statusCode: 401 proto: Object { … }

Can someone help me out fixing the error. Note:- I provided the correct "instanceLocator" in my application (not the one mentioned above)

hamchapman commented 5 years ago

That looks like it's related to the https://github.com/pusher/chatkit-server-node repo. Please open a new issue there

vivek1395068 commented 5 years ago

Sure thanks, I raised the issue.