Skip to content

Commit

Permalink
feat: Do not need app_name for external clients (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
taorepoara authored Sep 29, 2023
1 parent 077b258 commit 5dc7126
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions server/lib/dev_tool/app_adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ defmodule DevTool.AppAdapter do
end

@impl ApplicationRunner.Adapter
def resource_from_params(%{"userId" => userId, "token" => token}) do
userId
def resource_from_params(%{"userId" => user_id, "token" => token} = params) do
user_id
|> Integer.parse()
|> elem(0)
|> do_resource_from_params(token)
|> do_resource_from_params(token, params)
end

def resource_from_params(%{"token" => token}) do
do_resource_from_params(1, token)
def resource_from_params(%{"token" => token} = params) do
do_resource_from_params(1, token, params)
end

def resource_from_params(_params) do
raise "No token found. Please add a token to your websocket request."
end

defp do_resource_from_params(user_id, token) do
defp do_resource_from_params(user_id, token, params) do
with {:ok, _scope} <- OAuth2Helper.verify_scope(token, "app:websocket"),
{:ok, %User{id: id}} <- UserServices.upsert_fake_user(user_id) do
{:ok, id}
{:ok, id, "devtool-app", ApplicationRunner.AppSocket.extract_context(params)}
end
end
end
2 changes: 1 addition & 1 deletion server/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ defmodule DevTool.MixProject do
{:cors_plug, "~> 3.0"},
{:application_runner,
git: "https://github.com/lenra-io/server.git",
ref: "v1.0.0-beta.164",
ref: "v1.0.0-beta.172",
subdir: "libs/application_runner",
submodules: true},
{:distillery, "~> 2.1"}
Expand Down
2 changes: 1 addition & 1 deletion server/mix.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%{
"application_runner": {:git, "https://github.com/lenra-io/server.git", "05f3c061dfa8754a1dc40287927434c2292fb211", [ref: "v1.0.0-beta.164", subdir: "libs/application_runner", submodules: true]},
"application_runner": {:git, "https://github.com/lenra-io/server.git", "779fea0cb860be8e5459c00ea89803d023b05ea3", [ref: "v1.0.0-beta.172", subdir: "libs/application_runner", submodules: true]},
"artificery": {:hex, :artificery, "0.4.3", "0bc4260f988dcb9dda4b23f9fc3c6c8b99a6220a331534fdf5bf2fd0d4333b02", [:mix], [], "hexpm", "12e95333a30e20884e937abdbefa3e7f5e05609c2ba8cf37b33f000b9ffc0504"},
"bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"},
"bypass": {:hex, :bypass, "2.1.0", "909782781bf8e20ee86a9cabde36b259d44af8b9f38756173e8f5e2e1fabb9b1", [:mix], [{:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "d9b5df8fa5b7a6efa08384e9bbecfe4ce61c77d28a4282f79e02f1ef78d96b80"},
Expand Down

0 comments on commit 5dc7126

Please sign in to comment.