From f5e0678596ebedc290e448673e55cabce1da7d07 Mon Sep 17 00:00:00 2001 From: "Michael B. Klein" Date: Tue, 23 Jul 2024 16:03:56 +0000 Subject: [PATCH] Try to fix Livebook auth --- livebook/Dockerfile | 4 ++-- livebook/meadow_livebook_auth.exs | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/livebook/Dockerfile b/livebook/Dockerfile index 3f3388a0d..48bb04840 100644 --- a/livebook/Dockerfile +++ b/livebook/Dockerfile @@ -1,7 +1,7 @@ -FROM ghcr.io/livebook-dev/livebook +FROM ghcr.io/livebook-dev/livebook:latest ENV LIVEBOOK_AWS_CREDENTIALS=true ENV LIVEBOOK_IDENTITY_PROVIDER=custom:MeadowLivebookAuth -ENV LIVEBOOK_DISTRIBUTION=sname +ENV LIVEBOOK_DISTRIBUTION=name ENV LIVEBOOK_IP=0.0.0.0 ENV LIVEBOOK_DATA_PATH=/data ENV LIVEBOOK_HOME=${LIVEBOOK_DATA_PATH}/books diff --git a/livebook/meadow_livebook_auth.exs b/livebook/meadow_livebook_auth.exs index 1a4aa84c6..f44cdda5b 100644 --- a/livebook/meadow_livebook_auth.exs +++ b/livebook/meadow_livebook_auth.exs @@ -23,9 +23,22 @@ defmodule MeadowLivebookAuth do @spec authenticate(GenServer.server(), Plug.Conn.t(), keyword()) :: {Plug.Conn.t(), map() | nil} def authenticate(server, conn, _) do - with url <- get_meadow_url() do - set_state(server, :auth_url, url) - {conn, meadow_auth(url, conn)} + with url <- find_meadow_url(server), + user <- meadow_auth(url, conn) do + {conn, user} + end + end + + defp find_meadow_url(server) do + case get_state(server) do + %{auth_url: auth_url} -> + auth_url + + _ -> + with url <- get_meadow_url() do + set_state(server, :auth_url, url) + url + end end end