-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve authentication handling
Using the admin UI was previously plagued by auth errors that would occur after just a few minutes of idle time and required refreshing the page, losing any work in progress. These changes should improve how we handle authentication, allowing an admin to be idle for up to 30 minutes and signed in for up to 12 hours before needing to reauthenticate, following the TID Session Management guidelines and the prior art of mbta/screenplay#520. Also, when an admin's session has expired and they try to load new data in the admin UI, they will get a message indicating they need to refresh the page, instead of the generic "an error occurred".
- Loading branch information
1 parent
8659089
commit ae5255a
Showing
12 changed files
with
119 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
defmodule ScreensWeb.Controllers.AuthControllerTest do | ||
use ScreensWeb.ConnCase | ||
|
||
import ExUnit.CaptureLog | ||
|
||
describe "callback" do | ||
test "redirects on success and saves refresh token", %{conn: conn} do | ||
current_time = System.system_time(:second) | ||
|
||
auth = %Ueberauth.Auth{ | ||
provider: :keycloak, | ||
uid: "[email protected]", | ||
credentials: %Ueberauth.Auth.Credentials{ | ||
expires_at: current_time + 1_000 | ||
}, | ||
extra: %{ | ||
raw_info: %{ | ||
extra: %Ueberauth.Auth.Extra{ | ||
raw_info: %UeberauthOidcc.RawInfo{ | ||
claims: %{ | ||
"iat" => System.system_time(:second) | ||
}, | ||
userinfo: %{ | ||
"resource_access" => %{ | ||
"test-client" => %{"roles" => ["screens-admin"]} | ||
|
@@ -33,14 +39,17 @@ defmodule ScreensWeb.Controllers.AuthControllerTest do | |
end | ||
|
||
test "handles generic failure", %{conn: conn} do | ||
conn = | ||
conn | ||
|> assign(:ueberauth_failure, %Ueberauth.Failure{}) | ||
|> get(ScreensWeb.Router.Helpers.auth_path(conn, :callback, "keycloak")) | ||
logs = | ||
capture_log([level: :warning], fn -> | ||
conn = | ||
conn | ||
|> assign(:ueberauth_failure, %Ueberauth.Failure{}) | ||
|> get(ScreensWeb.Router.Helpers.auth_path(conn, :callback, "keycloak")) | ||
|
||
response = response(conn, 401) | ||
assert response(conn, 401) =~ "unauthenticated" | ||
end) | ||
|
||
assert response =~ "unauthenticated" | ||
assert logs =~ "ueberauth_failure" | ||
end | ||
end | ||
|
||
|