Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/workos/client/tesla_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ defmodule WorkOS.Client.TeslaClient do
{Tesla.Middleware.BaseUrl, client.base_url},
Tesla.Middleware.PathParams,
Tesla.Middleware.JSON,
{Tesla.Middleware.Headers, [{"Authorization", "Bearer #{access_token}"}]}
{Tesla.Middleware.Headers,
[
{"Authorization", "Bearer #{access_token}"},
{"User-Agent", user_agent()}
]}
])
end

defp user_agent do
"workos-elixir/#{Application.spec(:workos, :vsn)}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Guard against nil version

Application.spec(:workos, :vsn) returns nil when the application is not loaded (e.g. in certain test setups or as a library dependency that hasn't started). Interpolating nil yields "workos-elixir/", which is a malformed User-Agent. A compile-time attribute or a runtime fallback would be safer.

Suggested change
"workos-elixir/#{Application.spec(:workos, :vsn)}"
version = Application.spec(:workos, :vsn) || "unknown"
"workos-elixir/#{version}"

end
end
Loading