Last active
December 9, 2016 20:44
-
-
Save tokafish/8dbefd858b1649d0804e to your computer and use it in GitHub Desktop.
Pusher Authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PusherController < ApplicationController | |
protect_from_forgery except: :auth | |
def auth | |
response = Pusher[params[:channel_name]].authenticate params[:socket_id], | |
user_id: params[:id], | |
user_info: { name: params[:name] } | |
render json: response | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pusher.app_id = 'YOUR_APP_ID' | |
Pusher.key = 'YOUR_APP_KEY' | |
Pusher.secret = 'YOUR_APP_SECRET' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
match '/pusher/auth' => 'pusher#auth', via: :post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var currentUser = { | |
name: 'Tommy', | |
id: 42 | |
}; | |
var pusher = new Pusher('YOUR_PUSHER_KEY', { | |
authEndpoint: '/pusher/auth', | |
auth: { | |
params: currentUser | |
} | |
}); | |
var channel = pusher.subscribe('presence-chat'); | |
channel.bind('pusher:subscription_succeeded', function() { | |
console.log('Channel members:', channel.members); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have the same problem as @Ami2810, please help!