V
V
vadimstroganov2016-07-03 23:41:52
Ruby on Rails
vadimstroganov, 2016-07-03 23:41:52

How to identify mobile application client in ActionCable?

Hello!
This code recognizes the user through a cookie:

# app/channels/application_cable/connection.rb
module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user
 
    def connect
      self.current_user = find_verified_user
    end
 
    protected
      def find_verified_user
        if current_user = User.find_by(id: cookies.signed[:user_id])
          current_user
        else
          reject_unauthorized_connection
        end
      end
  end
end

The application has authorization with the subsequent issuance of a token.
There are no cookies in mobile applications, what to do in this case? How to recognize a user?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Biggless, 2016-07-07
@vadimstroganov

pass the token with the url ws://server.com/?token=abc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question