mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-11 07:24:30 +08:00
Add callback function to logout user
This commit is contained in:
parent
c9603f4167
commit
344a37c5e8
7 changed files with 42 additions and 2 deletions
|
@ -45,6 +45,11 @@ defmodule Livebook.ZTA do
|
|||
"""
|
||||
@callback authenticate(name(), Plug.Conn.t(), keyword()) :: {Plug.Conn.t(), metadata() | nil}
|
||||
|
||||
@doc """
|
||||
Logouts against the given name.
|
||||
"""
|
||||
@callback logout(name(), Phoenix.LiveView.Socket.t()) :: :ok | :error
|
||||
|
||||
@doc false
|
||||
def init do
|
||||
:ets.new(__MODULE__, [:named_table, :public, :set, read_concurrency: true])
|
||||
|
|
|
@ -16,7 +16,7 @@ defmodule Livebook.ZTA.BasicAuth do
|
|||
end
|
||||
|
||||
@impl true
|
||||
def authenticate(name, conn, _options) do
|
||||
def authenticate(name, conn, _opts) do
|
||||
{username, password} = Livebook.ZTA.get(name)
|
||||
conn = Plug.BasicAuth.basic_auth(conn, username: username, password: password)
|
||||
|
||||
|
@ -26,4 +26,9 @@ defmodule Livebook.ZTA.BasicAuth do
|
|||
{conn, %{}}
|
||||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
def logout(_name, _socket) do
|
||||
:error
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,6 +25,11 @@ defmodule Livebook.ZTA.Cloudflare do
|
|||
{conn, authenticate_user(token, identity, keys)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def logout(_name, _socket) do
|
||||
:error
|
||||
end
|
||||
|
||||
@impl true
|
||||
def init(options) do
|
||||
state = struct!(__MODULE__, options)
|
||||
|
|
|
@ -25,6 +25,11 @@ defmodule Livebook.ZTA.GoogleIAP do
|
|||
{conn, authenticate_user(token, identity, keys)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def logout(_name, _socket) do
|
||||
:error
|
||||
end
|
||||
|
||||
@impl true
|
||||
def init(options) do
|
||||
state = struct!(__MODULE__, options)
|
||||
|
|
|
@ -35,6 +35,16 @@ defmodule Livebook.ZTA.LivebookTeams do
|
|||
end
|
||||
end
|
||||
|
||||
@impl true
|
||||
def logout(name, %{assigns: %{current_user: %{payload: %{"access_token" => token}}}}) do
|
||||
team = Livebook.ZTA.get(name)
|
||||
|
||||
case Teams.Requests.logout_identity_provider(team, token) do
|
||||
{:ok, _no_content} -> :ok
|
||||
_ -> :error
|
||||
end
|
||||
end
|
||||
|
||||
defp handle_request(conn, team, %{"teams_identity" => _, "code" => code}) do
|
||||
with {:ok, access_token} <- retrieve_access_token(team, code),
|
||||
{:ok, metadata} <- get_user_info(team, access_token) do
|
||||
|
|
|
@ -7,7 +7,12 @@ defmodule Livebook.ZTA.PassThrough do
|
|||
end
|
||||
|
||||
@impl true
|
||||
def authenticate(_, conn, _) do
|
||||
def authenticate(_name, conn, _opts) do
|
||||
{conn, %{}}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def logout(_name, _socket) do
|
||||
:error
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,6 +29,11 @@ defmodule Livebook.ZTA.Tailscale do
|
|||
{conn, user}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def logout(_name, _socket) do
|
||||
:error
|
||||
end
|
||||
|
||||
defp authenticate_ip(remote_ip, address) do
|
||||
{url, options} =
|
||||
if String.starts_with?(address, "http") do
|
||||
|
|
Loading…
Add table
Reference in a new issue