ruby - Private channels with Pusherapp (using Rails) -


i got through hello world pusherapp. want create private channels users read messages supposed read.

the pusher docs give details on how this, , i'm kind of lost.

from docs:

... pusher js library returned socket_id when connects pusher.

when attempts subscribe private channel, sends ajax request server channel_name , socket_id parameters.

the default url http://yourserver.com/pusher/auth. ...

class pushercontroller < applicationcontroller   def auth     if current_user       response = pusher[params[:channel_name]].authenticate(params[:socket_id])       render :json => response     else       render :text => "not authorized", :status => '403'     end   end end 

given unique user id (current_user.id), how can authenticate user have him/her subscribe corresponding channel?

thanks

this blog post on implementation seems explain things bit more: https://pusher.com/docs/client_api_guide/client_private_channels

the authorization scheme based on idea that, rather implementing custom user authentication, , adding complexity , state pusher, should trust existing level of authentication offered application. wanted ensure reading data sent application browser not able connect channel user, , therefore couldn't include secrets in page html.

sounds application's business logic should authenticate user , decide should access private channel.

their diagram shows:

enter image description here

once authenticated, app requests subscribe user. pusher replies socket_id. connected using that.

here's how describe it:

as shown in diagram, unique socket id generated , sent browser pusher. sent application (1) via ajax request authorizes user access channel against existing authentication system. if successful application returns authorization string browser signed pusher secret. sent pusher on websocket, completes authorization (2) if authorization string matches.

the example @ bottom of blog post further clarifies:

suppose have channel called project-3, users , b have access, not c. you'd make channel private user c cannot listen in on private events. send events private-project-3 , subscribe in browser. long you're using latest javascript (version 1.3 or above), you'll see post request made application /pusher/auth. fail, , therefore subscribe request not made socket.

so, me sounds like: 1) request subscribe sent pusher 2) pusher posts /auth method determine if user can access channel 3) if business logic allows user access channel, auth method returns "ok" response:

auth = pusher[params[:channel_name]].socket_auth(params[:socket_id])      content_type 'application/json'     return json.generate({       :auth => auth     }) 

i haven't used pusher itself, model seems mirror structure of other push-based models. hope helps!


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -