Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can authenticate a message to a Stomplet by using the session and a stored token. For this to work, you have to setup Rails to use the Torquebox session store. This can be done with an initializer, such as <code>config/initializers/torquebox_init.rb</code>:</p> <pre><code>AppName::Application.config.session_store :torquebox_store </code></pre> <p>Now the Stomplet will have access to the session. Here is an example Stomplet that uses the session param <code>:authentication_token</code> to match the User's authentication_token in the database. The auth token is checked for subscribing, sending a message, and unsubscribing:</p> <pre><code>require 'torquebox-stomp' class StompletDemo def initialize() super @subscribers = [] end def configure(stomplet_config) end def on_message(stomp_message, session) token = session[:authentication_token] if is_authenticated?( token ) @subscribers.each do |subscriber| subscriber.send( stomp_message ) end end end def on_subscribe(subscriber) session = subscriber.session if is_authenticated?(session[:authentication_token]) @subscribers &lt;&lt; subscriber end end def on_unsubscribe(subscriber) session = subscriber.session if is_authenticated?(session[:authentication_token]) @subscribers.delete( subscriber ) end end def is_authenticated?(token) User.where( authentication_token: token ).exists? end end </code></pre> <p>Now all you have to do is make sure that when the user authenticates, the <code>session[:authentication_token]</code> is set. Mostly like this will be set in a controller:</p> <pre><code> # user has successfully authenticates session[:authentication_token] = @user.authentication_token </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload