From e93ed92c82d853354c09e1e82908fc4977286412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Bara=C3=BAna?= Date: Mon, 3 Jun 2024 09:51:09 -0300 Subject: [PATCH] Uses in the doc example --- lib/kino/proxy.ex | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/kino/proxy.ex b/lib/kino/proxy.ex index 8971f3ac..f9a84128 100644 --- a/lib/kino/proxy.ex +++ b/lib/kino/proxy.ex @@ -57,18 +57,19 @@ defmodule Kino.Proxy do > > ```elixir > Kino.Proxy.listen(fn conn -> - > api_token = "my-secret-api-token" - > - > case Plug.Conn.get_req_header(conn, "authorization") do - > ["Bearer " <> ^api_token] -> - > Plug.Conn.send_resp(conn, 200, "hello") + > expected_token = "my-secret-api-token" > + > with ["Bearer " <> user_token] <- Plug.Conn.get_req_header(conn, "authorization"), + > true <- Plug.Crypto.secure_compare(user_token, expected_token) do + > Plug.Conn.send_resp(conn, 200, "hello") + > else > _ -> > conn > |> Plug.Conn.put_resp_header("www-authenticate", "Bearer") > |> Plug.Conn.send_resp(401, "Unauthorized") > end > end) + > ``` """ @doc """