mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
fix(portal): Fallback to the user token if service account token is not available (#6764)
This commit is contained in:
@@ -30,6 +30,17 @@ defmodule Domain.Auth.Adapters.GoogleWorkspace.Jobs.SyncDirectory do
|
||||
{:error, :missing_service_account_key} ->
|
||||
provider.adapter_state["access_token"]
|
||||
|
||||
{:error, {401, _response} = reason} ->
|
||||
Logger.warning("Failed to fetch service account token",
|
||||
account_id: provider.account_id,
|
||||
account_slug: provider.account.slug,
|
||||
provider_id: provider.id,
|
||||
provider_adapter: provider.adapter,
|
||||
reason: inspect(reason)
|
||||
)
|
||||
|
||||
provider.adapter_state["access_token"]
|
||||
|
||||
{:error, reason} ->
|
||||
Logger.error("Failed to fetch service account token",
|
||||
reason: inspect(reason),
|
||||
|
||||
@@ -48,7 +48,37 @@ defmodule Domain.Auth.Adapters.GoogleWorkspace.Jobs.SyncDirectoryTest do
|
||||
%{req_headers: [{"authorization", "Bearer GOOGLE_0AUTH_ACCESS_TOKEN"} | _]}}
|
||||
end
|
||||
|
||||
test "uses admin user token as a fallback", %{provider: provider} do
|
||||
test "uses admin user token as a fallback when service account is not configured" do
|
||||
bypass = Bypass.open()
|
||||
GoogleWorkspaceDirectory.override_token_endpoint("http://localhost:#{bypass.port}/")
|
||||
|
||||
Bypass.stub(bypass, "POST", "/token", fn conn ->
|
||||
Plug.Conn.send_resp(
|
||||
conn,
|
||||
401,
|
||||
Jason.encode!(%{
|
||||
"error" => "unauthorized_client",
|
||||
"error_description" =>
|
||||
"Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested."
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
GoogleWorkspaceDirectory.override_endpoint_url("http://localhost:#{bypass.port}/")
|
||||
GoogleWorkspaceDirectory.mock_groups_list_endpoint(bypass, [])
|
||||
GoogleWorkspaceDirectory.mock_organization_units_list_endpoint(bypass, [])
|
||||
GoogleWorkspaceDirectory.mock_users_list_endpoint(bypass, [])
|
||||
|
||||
{:ok, pid} = Task.Supervisor.start_link()
|
||||
assert execute(%{task_supervisor: pid}) == :ok
|
||||
|
||||
assert_receive {:bypass_request,
|
||||
%{req_headers: [{"authorization", "Bearer OIDC_ACCESS_TOKEN"} | _]}}
|
||||
end
|
||||
|
||||
test "uses admin user token as a fallback when service account token is not set", %{
|
||||
provider: provider
|
||||
} do
|
||||
bypass = Bypass.open()
|
||||
|
||||
GoogleWorkspaceDirectory.override_endpoint_url("http://localhost:#{bypass.port}/")
|
||||
|
||||
Reference in New Issue
Block a user