ryanb / private_pub

Handle pub/sub messaging through private channels in Rails using Faye.
MIT License
864 stars 226 forks source link

Pure JS Client-side Option? #82

Open maedi opened 11 years ago

maedi commented 11 years ago

According to the Readme:

The Ruby subscribe_to helper call is still necessary with this approach to grant the user access to the channel. The JavaScript is just a callback for any custom behavior.

I'd like to use Private Pub in PhoneGap which can only run JavaScript. Can Private Pub do its authentication via an AJAX request instead? Or will I have to use Faye directly.

gregmolnar commented 11 years ago

That helper outputs some javascript code: https://github.com/ryanb/private_pub/blob/master/lib/private_pub/view_helpers.rb#L12 So you can use simple javascript instead. Something like this would do it I guess:

<script type="text/javascript">
PrivatePub.sign({"server":"http://localhost:9292/faye","timestamp":1377071937590,"channel":"/your/channel","signature":"signature hash"});
</script>
miukki commented 8 years ago

@gregmolnar it possible but is important think subscription = PrivatePub.subscription(:channel => channel) prepare subscription on backend as secure solution.. right/ ?