centrifugal / centrifuge-dart

Dart (Flutter) client SDK for bidirectional communication with Centrifugo and Centrifuge-based server over WebSocket
https://pub.dartlang.org/packages/centrifuge
MIT License
102 stars 29 forks source link

token not accepted for dart client but works for other clients #36

Closed andthereitgoes closed 4 years ago

andthereitgoes commented 4 years ago

I am using connecting using a secret token to connect to the sever, but on the server, I am getting the following error

{"level":"info","client":"be291d0f-fafd-4d0e-a201-e518d428b5e3","data":"\ufffd\u0001\b\u0001\u0010\u0000\u001a\ufffd\u0001\n\ufffd\u0001eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJUZXN0IE9yZ2FuaXNhdGlvbiAxIiwic3ViIjoiNWRhYTAyMzgtN2YwYy0xMWVhLWIxMTItZWFlNTU2OWY4NjAxIiwiZXhwIjoxNTg5OTg3NjYxfQ.fwwM8-L4mqdpK2kFteoYmb6TDfoQ3J0oxiyfCmbIDlY","error":"invalid character 'Õ' looking for beginning of value","user":"","time":"2020-05-19T15:15:30Z","message":"error decoding command"}

The following \ufffd\u0001\b\u0001\u0010\u0000\u001a\ufffd\u0001\n\ufffd\u0001 is being added to the token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJUZXN0IE9yZ2FuaXNhdGlvbiAxIiwic3ViIjoiNWRhYTAyMzgtN2YwYy0xMWVhLWIxMTItZWFlNTU2OWY4NjAxIiwiZXhwIjoxNTg5OTg3NjYxfQ.fwwM8-L4mqdpK2kFteoYmb6TDfoQ3J0oxiyfCmbIDlY

This same token works fine for other centrifuge (js, golang, java) clients for the same server.

I have used the example code https://github.com/centrifugal/centrifuge-dart/blob/master/example/console/simple.dart

FZambia commented 4 years ago

@andthereitgoes I think you are not using this recommendation from this library readme:

Note that ?format=protobuf is required because this library only works with Protobuf protocol.

So Centrifugo thinks client is using JSON protocol while dart client actually uses binary data. Try to add ?format=protobuf to connection url.

andthereitgoes commented 4 years ago

Aah thanks. Let me try it and get back to you.

FZambia commented 4 years ago

Please reopen in case it does not help, but I am pretty sure that's the case since I reproduced error message locally.

andthereitgoes commented 4 years ago

Hello @FZambia

yes, tried it and connect/disconnect works. But I have another problem for which I couldn't find anything in the code.

After connecting I am trying to subscribe to a private channel such as $5daa0238-7f0c-11ea-b112-eae5569f8601#5daa0238-7f0c-11ea-b112-eae5569f8601

When I send the subscribe, on the server I am seeing the following in the log

{"level":"info","client":"436bb802-c9a3-471c-99d1-36b94cdf32c3","command":"id:2 method:SUBSCRIBE params:\"\\nJ$5daa0238-7f0c-11ea-b112-eae5569f8601#5daa0238-7f0c-11ea-b112-eae5569f8601\\022\\000\" ","error":"103: permission denied","reply":"id:2 error:<code:103 message:\"permission denied\" > ","user":"5daa0238-7f0c-11ea-b112-eae5569f8601","time":"2020-05-21T15:41:11Z","message":"client command error"}

\\nJ$5daa0238-7f0c-11ea-b112-eae5569f8601#5daa0238-7f0c-11ea-b112-eae5569f8601\\022\\000\

I am sure this is related to protobuf format, but not sure what to do.

I read in the readme that subscribe to private channels with JWT is supported. So not sure what I am missing.