Skip to content

Commit

Permalink
feat: change socket param from token to apikey
Browse files Browse the repository at this point in the history
  • Loading branch information
w3b6x9 committed Feb 16, 2021
1 parent af6344c commit bcda09b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions server/lib/realtime_web/channels/user_socket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ defmodule RealtimeWeb.UserSocket do
def id(_socket), do: nil

defp authorize_conn(true, %{"token" => token}) do
# WARNING: "token" param key will be deprecated.
# Please use "apikey" param key to pass in auth token.
case ChannelsAuthorization.authorize(token) do
{:ok, _} -> :ok
_ -> :error
end
end

defp authorize_conn(true, %{"apikey" => token}) do
case ChannelsAuthorization.authorize(token) do
{:ok, _} -> :ok
_ -> :error
Expand Down
4 changes: 4 additions & 0 deletions server/test/realtime_web/channels/user_socket_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ defmodule RealtimeWeb.UserSocketTest do
with_mock ChannelsAuthorization, authorize: fn _token -> {:ok, %{}} end do
Application.put_env(:realtime, :secure_channels, true)

# WARNING: "token" param key will be deprecated.
assert {:ok, %Socket{}} =
UserSocket.connect(%{"token" => "auth_token123"}, socket(UserSocket))

assert {:ok, %Socket{}} =
UserSocket.connect(%{"apikey" => "auth_token123"}, socket(UserSocket))
end
end

Expand Down

0 comments on commit bcda09b

Please sign in to comment.