Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticate a socket ? #17

Open
note89 opened this issue Jul 18, 2016 · 1 comment
Open

Authenticate a socket ? #17

note89 opened this issue Jul 18, 2016 · 1 comment
Assignees

Comments

@note89
Copy link

note89 commented Jul 18, 2016

It seems that there is a possibility to authenticate when connecting to a channel but not when connecting to a socket ?

let socket = new Socket("/socket", {
params: {token: window.userToken},
logger: (kind, msg, data) => { console.log(`${kind}: ${msg}`, data) }
})

want something like this on the backend

@max_age 2 * 7 * 24 * 60 * 60
def connect(%{"token" => token}, socket) do
  case Phoenix.Token.verify(socket, "user socket", token, max_age: @max_age) do
      {:ok, user_id} ->
         {:ok, assign(socket, :user_id, user_id)}
      {:error, _reason} ->
         :error
  end
end

def connect(_params, _socket), do: :error
def id(socket), do: "users_socket:#{socket.assigns.user_id}"
@maxstr maxstr self-assigned this Mar 21, 2017
@mbaileys
Copy link

This is an old issue but I ran into this recently. To authenticate at socket connection time, you have to add the token as a query param of the URL. /websocket/socket?token=ygaz7KAanxhfbpR8kJGfc8ic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants