Skip to content

Commit

Permalink
Add docs related to auth when using Kino.Proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
hugobarauna committed May 28, 2024
1 parent 0bd3bd0 commit 6c5e315
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions lib/kino/proxy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Kino.Proxy do
Plug.Conn.send_resp(conn, 200, "hello")
end
> #### Plug {: .info}
> #### Plug dependency {: .info}
>
> In order to use this feature, you need to add `:plug` as a dependency.
Expand All @@ -29,12 +29,10 @@ defmodule Kino.Proxy do
Using the proxy feature, we can use Livebook apps to build APIs.
For example, we could provide a data export endpoint:
data = <<...>>
token = "auth-token"
Kino.Proxy.listen(fn
%{path_info: ["export", "data"]} = conn ->
["Bearer " <> ^token] = Plug.Conn.get_req_header(conn, "authorization")
data = "some data"
conn
|> Plug.Conn.put_resp_header("content-type", "application/csv")
Expand All @@ -46,8 +44,28 @@ defmodule Kino.Proxy do
|> Plug.Conn.send_resp(200, "use /export/data to get extract the report data")
end)
Once deployed as an app, the user would be able to export the data
Once deployed as an app, the API client would be able to export the data
by sending a request to `/apps/:slug/proxy/export/data`.
> #### Authentication {: .warning}
>
> The paths exposed by `Kino.Proxy` don't use the authentication mechanisms
> defined in your Livebook instance.
>
> If you need to authenticate requests, you should
> implement your own authentication mechanism. Here's a simple example.
>
> ```elixir
> Kino.Proxy.listen(fn conn ->
> import Plug.BasicAuth
>
> case Plug.BasicAuth.basic_auth(conn, username: "username", password: "password") do
> %{status: 401} = conn -> Plug.Conn.send_resp(conn)
>
> conn -> Plug.Conn.send_resp(conn, 200, "hello")
> end
> end)
> ```
"""

@doc """
Expand Down

0 comments on commit 6c5e315

Please sign in to comment.