Current section
Files
Jump to
Current section
Files
lib/soulless/auth.ex
defmodule Soulless.Auth do
def get_passport(passport_url, uid, access_token) do
headers = [{"Accept", "application/json, text/plain, */*"}]
content_type = "application/json;charset=UTF-8"
body = JSON.encode!(%{uid: uid, token: access_token, deviceId: "web|#{uid}"})
case Soulless.HTTP.post(passport_url, body, content_type, headers) do
{:ok, response} ->
case JSON.decode(response.body) do
{:ok, body} -> {:ok, body}
{:error, _} -> {:error, :ip_banned}
end
error ->
error
end
end
def test_server_url(opts, is_websocket) do
address = Keyword.fetch!(opts, :address)
port = Keyword.fetch!(opts, :port)
ssl = Keyword.get(opts, :ssl, false)
scheme =
case {ssl, is_websocket} do
{true, true} -> "wss"
{false, true} -> "ws"
{true, false} -> "https"
{false, false} -> "http"
end
"#{scheme}://#{address}:#{port}"
end
end